-
Notifications
You must be signed in to change notification settings - Fork 0
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(protoc-gen-openapi): remove path parameters from body #1
base: master
Are you sure you want to change the base?
Conversation
96e6109
to
d7cdf97
Compare
@@ -470,6 +482,7 @@ func (g *OpenAPIv3Generator) buildOperationV3( | |||
file *protogen.File, | |||
operationID string, | |||
tagName string, | |||
methodName string, | |||
description string, | |||
defaultHost string, | |||
path string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fieldNames := make([]string, len(message.Fields))
@@ -127,6 +135,10 @@ func (g *OpenAPIv3Generator) buildDocumentV3() *v3.Document { | |||
g.requiredSchemas = g.requiredSchemas[count:len(g.requiredSchemas)] | |||
} | |||
|
|||
for _, schema := range g.modifiedSchemas { | |||
g.addSchemaToDocumentV3(d, schema.Message, schema.Name, schema.FieldNames) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
name
both inparameters
andrequestBody
in 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}RequestBody
which doesn't contain the fields bound by the path template in these cases.The resulting openapi spec looks like: