Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscompilation issue for returning a list of items #10

Open
domesticmouse opened this issue Dec 8, 2022 · 0 comments
Open

Miscompilation issue for returning a list of items #10

domesticmouse opened this issue Dec 8, 2022 · 0 comments

Comments

@domesticmouse
Copy link

domesticmouse commented Dec 8, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant