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

Swagger/struct generation now uses concrete types exclusively to simplify config object setup #16

Merged
merged 2 commits into from
Feb 7, 2024

Conversation

Tanz0rz
Copy link
Collaborator

@Tanz0rz Tanz0rz commented Feb 7, 2024

oapi-codegen is the tool used to convert an OpenAPI spec file into Golang structs. By default, it sets optional parameter types to pointers, but this leads to clunky configuration for the user. This PR updates the swagger files in-place to append oapi-codegen's custom field x-go-type-skip-optional-pointer to all parameters and schemas in the swagger spec.

If possible, this should be done in a more native way (potentially using oapi-codegen's template framework). The current approach uses jq to update the swagger spec and could lead to unexpected behavior in at least two scenarios:

  1. Response objects no longer have pointers. This means lots of "zero" values will come back on these structs when parsing API responses. This will lead to clunky response objects at best and confusing responses at worst.
  2. The jq command is a blanket update to the swagger files and likely does not cover all edge cases. We will need to monitor this as more services are added/updated

An issue was opened here on the oapi-codegen repo to ask the developers directly for a potential alternative to the jQuery approach.

@Tanz0rz Tanz0rz merged commit a81d115 into main Feb 7, 2024
@Tanz0rz Tanz0rz deleted the feature/generation-concrete-only branch March 12, 2024 20:35
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

Successfully merging this pull request may close these issues.

1 participant