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

separating required properties from schema object generates Record<string, never> #2165

Open
1 of 2 tasks
xinruix opened this issue Feb 20, 2025 · 0 comments
Open
1 of 2 tasks
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@xinruix
Copy link

xinruix commented Feb 20, 2025

openapi-typescript version

7.0.0-next.8

Node.js version

20

OS + version

macOS 15.2

Description

When separating out the required properties into its own schema, an additional type of Record<string, never> is generated onto the type which does not allow me to update the fields on the generated type. It also does not make the types required as specified in the OpenApi spec.

Reproduction

Hi, I was looking to follow this blog where ideally I can separate out properties to be reused in different methods(get/patch)
https://blog.stoplight.io/reuse-openapi-descriptions

So let's say I have the following schema
paths: '/customers': post: tags: - Customer requestBody: $ref: '#/components/requestBodies/CreateCustomer' responses: 201: description: Created content: application/json: schema: $ref: '#/components/schemas/CustomerId' components: schemas: Customer: allOf: - $ref: '#/components/schemas/CustomerProperties' - $ref: '#/components/schemas/CustomerRequiredProperties'
CustomerProperties:
type: object
properties:
FirstName:
type: string
LastName:
type: string
DOB:
type: string
format: date-time
Segment:
type: string
enum:
- Young
- MiddleAged
- Old
- Moribund
CustomerRequiredProperties:
type: object
required:
- FirstName
- LastName
- DOB`

Splitting out this into CustomerRequiredProperties generates Record<string, never> onto the type

Expected result

I would expect to have a Customer object that has the required properties of FirstName,LastName and DOB

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

@xinruix xinruix added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

1 participant