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

feat(gen): Generate single type for a parameter definition #1177

Closed
urandom opened this issue Feb 9, 2024 · 2 comments · Fixed by #1197
Closed

feat(gen): Generate single type for a parameter definition #1177

urandom opened this issue Feb 9, 2024 · 2 comments · Fixed by #1197
Assignees
Labels
enhancement New feature or request openapi-features OpenAPI features support issues

Comments

@urandom
Copy link

urandom commented Feb 9, 2024

Description

Given the following definition:

components:
  securitySchemes:
  parameters:
    PathParam:
      in: path
      name: path-param
      required: true
      schema:
        type: string
        enum: ["val1", "val2"]

The generator creates a separate type for this definition whenever this parameter is used. If two operations (oper1, oper2) use this parameter, there will be two generated types (Oper1PathParam, Oper2PathParam). This makes it very difficult to handle such parameters in a common middleware, since they cannot be converted to a string, as that is just an underlying type.

@urandom urandom added enhancement New feature or request openapi-features OpenAPI features support issues labels Feb 9, 2024
@urandom
Copy link
Author

urandom commented Feb 9, 2024

Having a dedicated schema definition that is referenced there is a workaround for this problem. I'm just sure why a separate definition is required in this case.

@ayuhito
Copy link

ayuhito commented Apr 27, 2024

This would significantly reduce the size of my generated source files and improve debuggability since I reuse a lot of my parameters over many endpoints.

Although I'm not 100% sure how much inlining the Go compiler does, it may even noticeably reduce the binary size which is something I wanted to explore contributing to ogen when I have time. Parameter reuse was my first idea when looking into the generated code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-features OpenAPI features support issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants