-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fields bound by path template also in body (Swagger) #201
Comments
@brocaar are you posting like |
@tmc sorry for my late response. I needed to find some time to test with the latest grpc-gateway version. One the What I still would expect however is that path arguments are left out of the body in the Swagger definition. As the |
Any way how to to avoid redundant fields in message, when it's already defined in path? Talking about swagger definition. |
No, this is a bug in the swagger generator. Fields in the path should be excluded from the body when |
I was looking in to it. "parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/IdRequest"
}
}
],
I can't remove id from |
I think we have to use the existing tests: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-swagger/genswagger/template_test.go As to the problem of the type, yes, indeed, that is unfortunate. Maybe the best thing to do is to define a new type for the requests that take some parameters in the path and some in the body? |
We recently identified this issue in our generated Swagger docs, and I'm interested in contributing a fix. The safest option seems to be generating an inline schema definition for the request body, with all the fields from the proto request message other than those captured by path parameters (see https://swagger.io/docs/specification/2-0/describing-request-body/ ). Defining a named schema for the body with the needed field subset and using With this approach, we might not end up needing a schema definition for the proto request message at all (if it's not used anywhere without path params). @johanbrandhorst does this approach make sense to you? |
That sounds perfect! Please take a look if you can find the time. |
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.
Code generator was failing due to a change in how the swagger put params are defined. grpc-ecosystem/grpc-gateway#201 Fix a few failing tests.
Code generator was failing due to a change in how the swagger put params are defined. grpc-ecosystem/grpc-gateway#201 Fix a few failing tests.
Code generator was failing due to a change in how the swagger put params are defined. grpc-ecosystem/grpc-gateway#201 Fix a few failing tests.
Code generator was failing due to a change in how the swagger put params are defined. grpc-ecosystem/grpc-gateway#201 Fix a few failing tests.
Code generator was failing due to a change in how the swagger put params are defined. grpc-ecosystem/grpc-gateway#201 Fix a few failing tests.
Code generator was failing due to a change in how swagger put params are defined. Swagger gen change: grpc-ecosystem/grpc-gateway#201. Fix a few failing tests.
https://github.com/googleapis/googleapis/blob/master/google/api/http.proto#L123
PUT /v1/messages/123456 { "text": "Hi!" }
UpdateMessage(message_id: "123456" message { text: "Hi!" })
The special name
*
can be used in the body mapping to define thatevery field not bound by the path template should be mapped to the
request body. This enables the following alternative definition of
the update method:
Currently, this doesn't seem to work when generating the Swagger definition, as both fields are showing up. This is a snippet from my
.proto
file.I would have expected to ony have
name
in the request body. Leaving out thedevEUI
does work however when making requests!When setting
body: "name"
in the.proto
file (see also http.proto#L109), the API returns the following error (even if theappEUI
is included in the body too):The text was updated successfully, but these errors were encountered: