astahmer / typed-openapi

Generate a headless Typescript API client from an OpenAPI spec
https://typed-openapi-web.vercel.app/
200 stars 23 forks source link

TypeError: Cannot read properties of undefined (reading 'normalized') with nested definitions #27

Open penx opened 8 months ago

penx commented 8 months ago

The following spec throws an error "TypeError: Cannot read properties of undefined (reading 'normalized')"

openapi: 3.0.3
info:
  version: 1.0.0
paths:
  '/example':
    post:
      parameters:
        - name: example
          schema:
            $ref: '#/definitions/DefinitionA'
      responses:
        '200':
          description: OK
          schema:
            type: string
definitions:
  DefinitionA:
    type: object
    properties:
      example:
        type: array
        items:
          $ref: '#/definitions/DefinitionB'
  DefinitionB:
    type: object
    properties:
      example:
        type: string

https://typed-openapi-astahmer.vercel.app/?input=PYBwpgdghiCWBcACAzAOgAyuQKFhAZsPNoogG5gBOAzrMBEgIwYbYhQAuAFtcaQOQB6MAA8oAWxAAbMPz6lEIYNQ7yFiqJQlgOVXiXUKAtImjiwSUROlgDhhdQDGXMOKhr7CgCSUw%2BJPwAxIIAJn54sBx0ENSCACLhEJHRAIL8dgq%2B1EoxYPqeiPwATOjochn2YU6UsCBR9EgA8gDSFYZOLm4eBRwAnuBIKjUQAObYYfgR9THyCZNJ0ykefQOIwABGAFZgjhwZIJSgVFF53YhWkjJnpCsWiJpavW2kka75BYg%2BfgHBE1PRsTm-3oACF0qQgQtoiDlv07httrt9odwJQTu91BcbNdELdBhxhiMgA

Note that this works fine:

openapi: 3.0.3
info:
  version: 1.0.0
paths:
  '/example':
    post:
      parameters:
        - name: example
          schema:
            $ref: '#/definitions/DefinitionA'
      responses:
        '200':
          description: OK
          schema:
            type: string
definitions:
  DefinitionA:
    type: object
    properties:
      example:
        type: string

https://typed-openapi-astahmer.vercel.app/?input=PYBwpgdghiCWBcACAzAOgAyuQKFhAZsPNoogG5gBOAzrMBEgIwYbYhQAuAFtcaQOQB6MAA8oAWxAAbMPz6lEIYNQ7yFiqJQlgOVXiXUKAtImjiwSUROlgDhhdQDGXMOKhr7CgCSUw%2BJPwAxIIAJn54sBx0ENSCACLhEJHRAIL8dgq%2B1EoxYPqeiPwATOjochn2YU6UsCBR9EgA8gDSFYZOLm4eBRwAnuBIKjUQAObYYfgR9THyCZNJ0ykefQOIwABGAFZgjhwZIJSgVFF53YhWkjJnpCsWiEN4I0A

astahmer commented 8 months ago

hey, feel free to send a PR