Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default values from schema not passed through codegen #34

Open
0237h opened this issue May 16, 2024 · 0 comments
Open

Default values from schema not passed through codegen #34

0237h opened this issue May 16, 2024 · 0 comments

Comments

@0237h
Copy link
Contributor

0237h commented May 16, 2024

Hi,

Seems like when applying default values to some parameters in the OpenAPI spec, those defaults are not carried over in the codegen. This could be useful especially for Zod, etc. when parsing the resulting objects to provide the default value.

Example

"parameters": [
  {
    "name": "test_no_default",
    "in": "query",
    "schema": {
      "type": "string"
    }
  },
  {
    "name": "test_with_default",
    "in": "query",
    "schema": {
      "type": "string",
      "default": "hello world"
    }
  }
]

will generate

parameters: z.object({
  query: z.object({
    test_no_default: z.string().optional(),
    test_with_default: z.string().optional(),
  }),
})

instead of

parameters: z.object({
  query: z.object({
    test_no_default: z.string().optional(),
    test_with_default: z.string().optional().default("hello world"),
  }),
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant