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

Fix #201: Exclude path params from body schemas. #1145

Closed

Conversation

jgiles
Copy link
Contributor

@jgiles jgiles commented Mar 1, 2020

When body is "*" and some request fields are captured by path
parameters, exclude those fields from the request body Swagger schema.

Define an inline request body schema with all the request fields NOT
captured by path parameters. Also filter path parameters out of the
required fields list for the body schema.

When body is "*" and some request fields are captured by path
parameters, exclude those fields from the request body Swagger schema.

Define an inline request body schema with all the request fields NOT
captured by path parameters. Also filter path parameters out of the
required fields list for the body schema.
examples/clients/abe/api/swagger.yaml Show resolved Hide resolved
"$ref": "#/definitions/examplepbABitOfEverything"
"type": "object",
"example": {
"uuid": "0cf361e1-4b44-483d-a159-54dabdf7e814"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit unfortunate - the example here is from the proto message definition, and that example has uuid in it. Arguably, the example should be updated since it's not really applicable to everywhere the message is used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds right - could you update the example to include both the required values int64_value and double_value?

@@ -2201,7 +2380,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/examplepbBody"
"type": "object"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only field in the request object is captured by a path parameter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some way we could remove this "in": "body" entry altogether?

protoc-gen-swagger/genswagger/template.go Show resolved Hide resolved
protoc-gen-swagger/genswagger/template.go Show resolved Hide resolved
@jgiles
Copy link
Contributor Author

jgiles commented Mar 1, 2020

@johanbrandhorst this is a first pass at fixing #201 , with the fix confirmed in the existing a_bit_of_everything example and in our application's generated documentation.

Comment on lines +800 to +801
// If we are excluding some fields, define a schema inline.
schema = renderMessageAsSchema(meth.RequestType, reg, customRefs, bodyExcludedFields)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have no fields left here, we could skip this part?

@stale
Copy link

stale bot commented May 1, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 1, 2020
@johanbrandhorst
Copy link
Collaborator

Hey Josh, sorry there hasn't been any activity on here, are you waiting on me?

@stale stale bot removed the wontfix label May 1, 2020
@stale
Copy link

stale bot commented Jun 30, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 30, 2020
@stale stale bot closed this Jul 7, 2020
@Darevski
Copy link

Darevski commented Sep 3, 2020

Hey, @johanbrandhorst what is currently blocking the accept of this pull request?

@johanbrandhorst
Copy link
Collaborator

We were happy to merge this but it seems the author disappeared. Would you be willing to contribute a fix for this? If so, could I ask that it be against the v2 branch only?

@stijndehaes
Copy link
Contributor

@jgiles are you still planning on working on this or are you fine with me using your work as a starting point and finish it?

@jgiles jgiles deleted the fix-201-path-params-in-body branch April 21, 2021 00:16
@bmperrea bmperrea restored the fix-201-path-params-in-body branch June 21, 2021 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants