Dorthu / openapi3

A Python3 OpenAPI 3 Spec Parser
BSD 3-Clause "New" or "Revised" License
118 stars 47 forks source link

[Model error] array of schema items raise : 'NoneType' object has no attribute 'keys' #49

Closed CalmingBreeze closed 2 years ago

CalmingBreeze commented 3 years ago

As described here : https://swagger.io/specification/#response-object

I have a endpoint that return an array of Service item :

/api/services:
    get:
      operationId: api_services_list
      description: List all available services
      tags:
        - api
      security:
        - tokenAuth: []
      responses:
        '200':
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Service'
          description: ''

I don't understand well enough how models are built to fix it myself, but what I've understood so far is it will work with wrapped object array line in linodeAPI example :

responses:
        '200':
          description: Returns an array of all Linodes on your Account.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Linode'
                  page:
                    $ref: '#/components/schemas/PaginationEnvelope/properties/page'
                  pages:
                    $ref: '#/components/schemas/PaginationEnvelope/properties/pages'
                  results:
                    $ref: '#/components/schemas/PaginationEnvelope/properties/results'

Investigating further into model builder :

https://github.com/Dorthu/openapi3/blob/425341938167c7c0bb373ea6cee29770748e0057/openapi3/schemas.py#L83-L119

get_type await 'properties' property, but in my case, there's none.

It would be greatly appreciated it if you had some time for a quickfix or some hint to make it work !