Fix OpenAPI generation bugs; add custom responses - #92
Merged
Merged
Conversation
…ponses
Fixes:
- Schema names are unique: colliding messages (including imported ones such
as openapi.v3.Contact) no longer replace each other.
- Path params: renaming only touches the placeholder, named templates no
longer match greedily, and {x=*}/{x=**} wildcards are supported.
- Servers from multiple default hosts are all kept.
- Enum in/not_in/const rules use enum numbers.
- Numeric rules cover all numeric kinds, gt/lt, negative and zero bounds.
- Validating repeated message fields no longer panics.
- Circular-depth limits count the current path only.
- Pipes are kept in field, message and service descriptions.
- Method and file headers are emitted.
- additional_bindings and custom HEAD/OPTIONS/TRACE rules are emitted.
Features:
- custom_responses on file/service/method params (#70).
- resource_id_pattern option for resource name patterns.
Closes #69
Closes #70
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
# Conflicts: # examples/tests/customparamsbuildtag/openapi_json.yaml # examples/tests/customparamsexclude/openapi_json.yaml # examples/tests/customparamspostmanonly/openapi_json.yaml
- Circular depth counts message types on the current path, so recursive messages expand polynomially rather than exponentially. - method_params headers and responses follow build_tags like file and service params. - Schema names are only checked for collisions among messages the spec can reference, including google.rpc.Status for the default response. Schemas are only emitted for those messages. - A custom "default" response suppresses the google.rpc.Status schemas. - resource_id_pattern alternation is grouped to keep the anchors. - Wildcard path params drop allowReserved, which OpenAPI 3.0 only allows for query params. - Messages are indexed once; duplicated build-tag and Status logic removed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Fixes a set of bugs that produced invalid or wrong specs, and adds custom responses. Closes #69 and #70.
Fixes
Schema names collide. Schemas were looked up by short name, so any two messages with the same name shared one schema. For example, importing
openapiv3/annotations.proto(which defines its ownContact) could make the OpenAPI spec'sContactreplace an API's ownContact, even though nothing referenced it. Names are now assigned up front, among the messages the spec can reference (includinggoogle.rpc.Statusfor the default response), and schemas are only emitted for those. On a collision, a lone message from a generated file keeps its name and the others get package-qualified names. Unreferenced imports never cause a rename. Nested names that collide use the full chain of enclosing messages. Names that don't collide are unchanged, but schemas that did collide get new names, which may affect clients that refer to them by name.Path templates
/v1/user_ids/{user_id}became/v1/userIds/{user_id}. Only the placeholder is renamed now./v1/{project}/{name=shelves/*}became/v1/shelves/{shelf}. Every named template is now handled.{x=*}and{x=**}wildcards become a single path param;**getspattern: .+(Bug In Named Parameters Parsing and Support for Wildcards #69). The issue also asked forallowReserved, which is left out because OpenAPI 3.0 only allows it on query params.HTTP bindings.
additional_bindingsare emitted as extra operations with numbered IDs (Svc_Method_2). CustomHEAD,OPTIONSandTRACErules are mapped to those operations; other custom methods are skipped with a warning.Servers. With several
default_hosts, only the last path's host was kept, so every operation claimed that host.Validation
in,not_inandconstcompared enum numbers against descriptor indexes, andnot_inwas inverted, so these rules removed the enum list entirely.gt/lt(exclusive), negative bounds andconst. Zero bounds are emitted through an extension key, since gnostic omits zero values. "Outside the range" rules are skipped.itemsrules panicked.Other
method_paramsandfile_paramsheaders were ignored. Headers now merge file, then service, then method, and the more specific level wins on a name clash. Each level applies only when itsbuild_tags(if any) match the build tag.|in any field, message or service comment truncated the description. The "Summary | description" split now applies to method comments only.Features
custom_responsesonfile_params,service_paramsandmethod_params, keyed by status code. They replace generated responses with the same code, including thegoogle.rpc.Statusdefault. Responses followbuild_tagsthe same way headers do. A customdefaultalso stops thegoogle.rpc.Statusschemas from being emitted. An unknownmessage_reffails generation.resource_id_patternoption: controls the ID regex in resourcenamepatterns. The default[a-z2-7]{26}keeps current output; an empty value omits the pattern. Literal segments are now regex-escaped.Testing
schemacollisionmultihostsiblingqueryparamshttpbindingscustomresponsescustomdefaultresponsepathparams,validateandsummary.customparamsexamplewas never registered inplugin_test.go, and its JSON golden had gone stale; it's registered and regenerated now.FileHeaderandMethodHeader, which were declared in the protos but never emitted.go test ./...,go vetandgofmtpass.🤖 Generated with Claude Code