hpoul / openapi_dart

Dart implementation to generate (dart) server stubs and client libraries from OpenAPI 3.0 yaml files.
38 stars 21 forks source link

Miscompilation issue for returning a list of items #10

Open domesticmouse opened 1 year ago

domesticmouse commented 1 year ago

The following schema compiles correctly:

openapi: 3.0.0
info:
  title: AnAPI
  version: 0.0.2-alpha
paths:
  /inventory:
    get:
      operationId: Inventory Listing
      parameters: []
      responses:
        '200':
          description: Inventory
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/item_list'
components:
  schemas:
    item_list:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items: 
            $ref: '#/components/schemas/item'
    item:
      type: object
      required: [name, id]
      properties:
        name:
          type: string
        id:
          type: string

The following, more compact version, does not:

openapi: 3.0.0
info:
  title: AnAPI
  version: 0.0.2-alpha
paths:
  /inventory:
    get:
      operationId: Inventory Listing
      parameters: []
      responses:
        '200':
          description: Inventory
          content:
            application/json:
              schema:
                type: array
                items: 
                  $ref: '#/components/schemas/item'
components:
  schemas:
    item:
      type: object
      required: [name, id]
      properties:
        name:
          type: string
        id:
          type: string

The trick being FastAPI generates the second kind of schema, and implements it as if it were the first.