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

swagger: Prefix used in nested-field GET params does not respect json_names_for_fields #1125

Closed
jgiles opened this issue Feb 2, 2020 · 1 comment

Comments

@jgiles
Copy link
Contributor

jgiles commented Feb 2, 2020

Steps you follow to reproduce the error:

  1. Create proto structure like this:
message TimestampRange {
    google.protobuf.Timestamp after = 1;
    google.protobuf.Timestamp before = 2;
}
message GetFoosRequest {
    TimestampRange created_at = 1;
    string other_filter = 2;
}

service Foo {
    rpc GetFoos (GetFoosRequest) returns (GetFoosResponse) {
        option (google.api.http) = {
            get: "/v1/foos"
        };
    }
}
  1. Run protoc-gen-swagger with json_names_for_fields=true
  2. Observe generated Swagger parameter list like
"parameters": [
          {
            "name": "created_at.after",
            "in": "query",
            "required": false,
            "type": "string",
            "format": "date-time"
          },
          {
            "name": "created_at.before",
            "in": "query",
            "required": false,
            "type": "string",
            "format": "date-time"
          },
          {
            "name": "otherFilter",
            "in": "query",
            "required": false,
            "type": "string"
          },
]

What did you expect to happen instead:

The GET parameter should be createdAt.after.

What's your theory on why it isn't working:

Prefix assembly uses field.GetName() without checking GetUseJSONNamesForFields here:

p, err := queryParams(msg, nestedField, prefix+field.GetName()+".", reg, pathParams)

jgiles added a commit to paxosglobal/grpc-gateway that referenced this issue Feb 2, 2020
@jgiles
Copy link
Contributor Author

jgiles commented Feb 2, 2020

@johanbrandhorst I went ahead and put up #1126 for this (with a test case).

adasari pushed a commit to adasari/grpc-gateway that referenced this issue Apr 9, 2020
pull bot pushed a commit to BuildingRobotics/grpc-gateway that referenced this issue Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant