openapi-typescript-codegen icon indicating copy to clipboard operation
openapi-typescript-codegen copied to clipboard

Lack of default and exmaple properties in SDK schema

Open pboguslawski opened this issue 2 years ago • 3 comments

Describe the bug For OpenAPI type schema

 "MyNumber": {
    "minimum": 1,
    "type": "integer",
    "description": "My number.",
    "default": 1,
    "example": 2
   },

openapi-typescript-codegen --exportSchemas true does not generate default nor example properties in SDK schema (schemas/$MyNumber.ts):

export const $MyNumber = {
    type: 'number',
    description: `My number.`,
    minimum: 1,
} as const;

Schema should include both (expecially default that may be useful for clients).

pboguslawski avatar Mar 23 '23 09:03 pboguslawski

Thanks for a great tool overall! I'm seconding this issue. I've been using the --exportSchemas to try and get values to populate forms and client-side validation and I'm missing a few of them:

components:
  schemas:
     MyObject:
      type: object
      properties:
        clientId:
          type: string
          format: string
          description: client identifier 
          example: my-example-client-id
          nullable: true
          pattern: "^[a-zA-Z0-9 -_]*"
        keepAlive:
          type: integer
          format: int32
          default: 240
          description: keepAlive
          maximum: 65535
          minimum: 0

and I'm getting this:

export const $MyObject = {
    properties: {
        clientId: {
            type: 'string',
            description: `client identifier.`,
            isRequired: true,
            isNullable: true,
            format: 'string',
            pattern: '^[a-zA-Z0-9 -_]*',
        },
        keepAlive: {
            type: 'number',
            description: `keepAlive`,
            isRequired: true,
            format: 'int32',
            maximum: 65535,
        },
  • default is missing
  • example is missing
  • minimum is missing if equal to 0 (I guess that can be checked)

vanch3d avatar Jun 01 '23 13:06 vanch3d

also missing patternProperties

nhayfield avatar Dec 05 '23 14:12 nhayfield

I have fixed the issue with minimum missing when equal to 0 (also other min/max schema values will no longer have this bug). Please check out v0.32.1 of our fork @hey-api/openapi-ts. I plan to add default in the near future. If there are any other issues you have please open an issue and we will address as soon as we can!

jordanshatford avatar Mar 30 '24 23:03 jordanshatford