openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
568 stars 68 forks source link

Issue with negative numbers in API spec #182

Open dnlgrgly opened 7 months ago

dnlgrgly commented 7 months ago

Hello! 👋 When trying to run npx openapicmd typegen, I receive the following error:

npx openapicmd typegen <path>
Error: Debug Failure. False expression: Negative numbers should be created in combination with createPrefixUnaryExpression
    at Object.createNumericLiteral (~/.npm/_npx/fb2ea8e0e5441457/node_modules/typescript/lib/typescript.js:21094:13)
    at Object.buildNumericLiteralTypeNode (~/.npm/_npx/fb2ea8e0e5441457/node_modules/@anttiviljami/dtsgenerator/dist/core/astBuilder.js:56:56)
    at DtsGenerator.generateLiteralTypeNode (~/.npm/_npx/fb2ea8e0e5441457/node_modules/@anttiviljami/dtsgenerator/dist/core/dtsGenerator.js:312:28)
    at ~/.npm/_npx/fb2ea8e0e5441457/node_modules/@anttiviljami/dtsgenerator/dist/core/dtsGenerator.js:279:29
    at Array.map (<anonymous>)
    at Object.buildUnionTypeNode (~/.npm/_npx/fb2ea8e0e5441457/node_modules/@anttiviljami/dtsgenerator/dist/core/astBuilder.js:124:55)
    at DtsGenerator.generateLiteralTypeProperty (~/.npm/_npx/fb2ea8e0e5441457/node_modules/@anttiviljami/dtsgenerator/dist/core/dtsGenerator.js:278:24)
    at DtsGenerator.generateTypeProperty (~/.npm/_npx/fb2ea8e0e5441457/node_modules/@anttiviljami/dtsgenerator/dist/core/dtsGenerator.js:273:21)
    at DtsGenerator.generateProperties (~/.npm/_npx/fb2ea8e0e5441457/node_modules/@anttiviljami/dtsgenerator/dist/core/dtsGenerator.js:244:84)
    at DtsGenerator.generateTypeName (~/.npm/_npx/fb2ea8e0e5441457/node_modules/@anttiviljami/dtsgenerator/dist/core/dtsGenerator.js:449:35)

This seems to happen because the schema I'm trying to generate the types for contains some negative numbers, eg:

Coordinates:
  title: Coordinates
  type: object
  properties:
    latitude:
      type: number
      format: double
      example: 37.751
      minimum: -90
      maximum: 90
    longitude:
      type: number
      format: double
      example: -97.822
      minimum: -180
      maximum: 180
  required:
    - latitude
    - longitude

I checked the docs of the OpenAPI specs and this doesn't seem to be a real constraint of the specs themselves.