feat(protoc-gen-openapi): remove path parameters from body#1
feat(protoc-gen-openapi): remove path parameters from body#1istvan-hevele wants to merge 1 commit intomasterfrom
Conversation
96e6109 to
d7cdf97
Compare
| methodName string, | ||
| description string, | ||
| defaultHost string, | ||
| path string, |
There was a problem hiding this comment.
not required of course, but you can clean up a longer list of params like this by consolidating to:
operationID, tagName, methodName, description, defaultHost, path string
|
|
||
| // getMessageFieldNames gets the names of all fields from a message | ||
| func (g *OpenAPIv3Generator) getMessageFieldNames(message *protogen.Message) []string { | ||
| fieldNames := []string{} |
There was a problem hiding this comment.
fieldNames := make([]string, len(message.Fields))
| } | ||
|
|
||
| for _, schema := range g.modifiedSchemas { | ||
| g.addSchemaToDocumentV3(d, schema.Message, schema.Name, schema.FieldNames) |
There was a problem hiding this comment.
not sure what best practice is here, but you can pass the entire schema here since you seem to need all of its attributes
| // Pass the entire request message as the request body. | ||
| typeName := fullMessageTypeName(inputMessage.Desc) | ||
| requestSchema = g.schemaOrReferenceForType(typeName) | ||
| if string(inputMessage.Desc.FullName()) != "google.api.HttpBody" && haveCommonItem(coveredParameters, g.getMessageFieldNames(inputMessage)) { |
There was a problem hiding this comment.
do we have access to the actual type? may be more safe to check that against something that isn't hard coded
|
Hi @istvan-hevele, are you (still) planning on merging this upstream to |
|
Hi @daanschipper, I'd like to get this merged, but unfortunately I don't have enough spare time currently to get this rebased and opened against the upstream repo. |
|
I can help with that! I'll use your changes to generate my openapi specs to validate the changes, address the comments above and open a pull request upstream. |
|
Hi! I came across this issue (google#323) and was wondering if you ever got the chance to make the PR. |
When a request has both path parameters and
body: "*", the path parameters are being repeated in the body in the resulting OpenAPI spec.Note how the following example has
nameboth inparametersandrequestBodyin the generated openapi spec.protobuf:
openapi spec:
According to use_wildcard_in_body, every field not bound by the path template should be mapped to the request body.
So fields that are bound by the path template shouldn't be in the request body.
This PR creates a new type named
{method_name}RequestBodywhich doesn't contain the fields bound by the path template in these cases.The resulting openapi spec looks like: