openapi: fix v2 parameter and header type mapping#3919
Merged
Conversation
Use the same primitive mapping for v2 parameters, headers, and array items that body schemas already use so generated specs stay valid for named aliases and int64/date-time formats. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes a bug in Goa's OpenAPI v2 generator for parameter and header schemas.
Today, body and component schemas already translate Goa types into valid OpenAPI base types and formats, but parameter/header generation was using a different code path. That mismatch meant the same logical type could be rendered correctly in one part of the spec and incorrectly in another.
In practice, the broken path could emit invalid schema types such as:
type: UUIDtype: Timetype: int64Those are Goa type names, not valid OpenAPI
typevalues, so downstream OpenAPI tooling can reject the generated document.This change makes OpenAPI v2 parameters, headers, and array items use the same primitive mapping rules as body schemas. After the fix, those cases are emitted as valid OpenAPI shapes such as:
type: stringwithformat: uuidtype: stringwithformat: date-timetype: integerwithformat: int64The change also preserves validations coming from both the alias definition and the use site, so named aliases keep their expected formats when they are used in query params or headers.
What changed
Test plan
go test ./http/codegen/openapi/v2make