tazatechnology / openapi_spec

Dart based OpenAPI specification generator and parser
BSD 3-Clause "New" or "Revised" License
9 stars 6 forks source link

Fix Dart classes not using pascal case #8

Closed davidmigloz closed 1 year ago

davidmigloz commented 1 year ago

Some class names where not using the proper case when generated from a yaml file.

cc @walsha2

Example:

Using the following spec to generate a server:

openapi: "3.0.3"

info:
  title: knowledge-v1 API
  version: "1.0"

servers:
  - url: https://api.example.com

components:
  schemas:
    documents:
      type: array
      description: "List of documents"
      items:
        $ref: "#/components/schemas/document"
    document:
      type: object
      properties:
        id:
          type: string
          description: "Document ID"
        pageContent:
          type: string
          description: "Document content"
        metadata:
          $ref: "#/components/schemas/document_metadata"
      required:
        - id
        - pageContent
        - metadata
    document_metadata:
      type: object
      description: "Document metadata"
      properties:
        type:
          type: string
          description: "Document type"
        title:
          type: string
          description: "Document title"
        url:
          type: string
          description: "Document URL"
        locale:
          type: string
          description: "Document locale"
        updatedAt:
          type: string
          description: "Document last update date"
          format: date-time
      required:
        - type
        - title
        - url
        - locale
        - updatedAt
  responses:
    unauthorized:
      description: "Unauthorized: missing or invalid token"
    not_found:
      description: "User not found"
    internal_error:
      description: "Unexpected internal server error"

paths:
  /health/:
    get:
      description: "Health check"
      responses:
        "200":
          description: OK
          content:
            text/plain:
              schema:
                type: string
  /knowledge/v1/find:
    parameters:
      - in: query
        name: q
        description: "Query"
        schema:
          type: string
      - in: query
        name: type
        description: "Document type"
        schema:
          type: string
          example: "faq"
      - in: query
        name: locale
        description: "Locale"
        schema:
          type: string
          example: "en_GB"
    get:
      description: "Find documents"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/documents"
        "401":
          $ref: "#/components/responses/unauthorized"
        "500":
          $ref: "#/components/responses/internal_error"

This PR fixes the following issues:

server.dart:

image

schema/documets.dart

image

schema/document.dart

image
walsha2 commented 1 year ago

@davidmigloz Looks good. I confirmed this does not have any unintended consequences on a few projects using this package.

The generation code was written with the assumption that the class names in component references , e.g. #/components/schemas/document, would be Pascal already (or at least title case), per general code conventions.

Who defines a class in lowercase 😮 ??

walsha2 commented 1 year ago

Version 0.5.2 released: https://pub.dev/packages/openapi_spec

davidmigloz commented 1 year ago

Some Python people use snake case for everything 😅

Thanks for merging it!