Skip to content

swagger-typescript-api crashes on OpenAPI not: {} in 13.12.2, while 13.0.28 succeeds #1798

Description

@Vovcharaa

Describe the bug

swagger-typescript-api crashes when the OpenAPI schema contains not: {}.

This works in 13.0.28, but fails in 13.12.2.

Minimal repro

Repro spec:

{
  "openapi": "3.0.3",
  "info": {
    "title": "swagger-typescript-api not repro",
    "version": "1.0.0"
  },
  "paths": {},
  "components": {
    "schemas": {
      "RelatedProductVariant": {
        "type": "object",
        "properties": {
          "variantId": {
            "type": "integer"
          },
          "variantReferenceKey": {
            "type": "string"
          },
          "isMainVariant": {
            "type": "boolean"
          }
        }
      },
      "ProductVariant": {
        "type": "object",
        "properties": {
          "relatedVariants": {
            "oneOf": [
              {
                "type": "array",
                "minItems": 1,
                "items": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/RelatedProductVariant"
                    },
                    {
                      "type": "object",
                      "required": [
                        "variantId",
                        "isMainVariant"
                      ],
                      "properties": {
                        "variantId": {
                          "type": "integer"
                        },
                        "variantReferenceKey": {
                          "not": {}
                        }
                      }
                    }
                  ]
                }
              },
              {
                "type": "array",
                "minItems": 1,
                "items": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/RelatedProductVariant"
                    },
                    {
                      "type": "object",
                      "required": [
                        "variantReferenceKey",
                        "isMainVariant"
                      ],
                      "properties": {
                        "variantReferenceKey": {
                          "type": "string"
                        },
                        "variantId": {
                          "not": {}
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      }
    }
  }
}

Command:

swagger-typescript-api generate \
  --axios \
  -p ./docs/swagger-typescript-api-not-repro.json \
  -o ./tmp/generated \
  -n api.ts

Current behavior

13.12.2 throws:

TypeError: (this.schema[complexType] || []).map is not a function
    at ComplexSchemaParser.parse (...)

Expected behavior

The generator should not crash on not: {}.

If this schema shape is unsupported, a clear validation error would still be much better than a runtime exception.

Version info

Fails:

  • swagger-typescript-api@13.12.2

Works:

  • swagger-typescript-api@13.0.28

Suspected cause

It looks like ComplexSchemaParser handles not as a complex schema, but later assumes the complex schema value is array-like when building the description.

13.0.28 uses Lodash:

lodash.map(this.schema[complexType], "description")

That safely returns [] for not: {}.

13.12.2 uses native .map(...):

(this.schema[complexType] || []).map((item) => item?.description)

For not: {}, that becomes {} and throws because {} does not have .map.

Additional context

In a larger real-world spec, removing only the two not: {} entries made generation succeed, which seems to confirm this is the direct trigger.

Relevant source

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions