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

Generated Schema types are not restrictive (not sealed) #4761

Open
uroslates opened this issue Jun 18, 2024 · 3 comments
Open

Generated Schema types are not restrictive (not sealed) #4761

uroslates opened this issue Jun 18, 2024 · 3 comments
Labels
feature request Requests for new functionality

Comments

@uroslates
Copy link

Is your feature request related to a problem? Please describe.
Actual: We have a problem with having & Record<string, any> added at each generated schema type definition. This does not seal (restrict additional properties) to the schema.

Describe the solution you'd like
Expected: In ideal Scenario there would be a flag (to a generate function - additional generate option) that controls this feature - either makes the generated Schema files strict (what we refer to as sealed) or if set to false (default behaviour) would add the & Record<string, any> type union, allowing the types to be flexible (non restrictive).

Impact / Priority

The problematic code is relevant to serializeObjectSchema function.

Example: Instead of having schema file outputs from openapi generate function like this:

export type AddToCartEntryInputBO = {
  quantity: number;
  ...
} & Record<string, any>;

Would be good to have them (if correct generate options flag is set) like this:

export type AddToCartEntryInputBO = {
  quantity: number;
  ...
};
@uroslates uroslates added the feature request Requests for new functionality label Jun 18, 2024
@jjtang1985
Copy link
Contributor

Hi @uroslates ,

Thanks for raising up.
Before talking about the solution, I would like to understand the root cause of & Record<string, any>, because we are woking on some improvement for this direction.

Maybe @shibeshduw can correct me, it seems this is related to the special keywords of the specification file like allOf, anyOf, oneOf.

@uroslates , please share a minimal example of the spec, so we can reproduce the issue.

Thank you!

Best regards,
Junjie

@shibeshduw
Copy link
Contributor

shibeshduw commented Jun 28, 2024

Hey @jjtang1985, this is not related to the special keywords in the spec. I believe this is the default behavior with how OpenAPI interprets schemas.
In an object schema, even if additionalProperties is not specified, it is implicitly allowed (defaults to true), which means the object can have additional properties of any type. While parsing the spec, we default to type: any so that this behavior is captured. This in turn, causes the serializer code to append & Record<string, any> to the schema type definition.

@jjtang1985
Copy link
Contributor

Thank you, @shibeshduw.

@uroslates , I'll keep this feature request open, but I'm not sure whether we will work on this feature requests or not, due to the current capacity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Requests for new functionality
Projects
None yet
Development

No branches or pull requests

3 participants