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

[WIP] feat: adds Headers to Operation for specifying request headers #2970

Closed
wants to merge 4 commits into from

Conversation

amitavaghosh1
Copy link

@amitavaghosh1 amitavaghosh1 commented Oct 20, 2022

References to other Issues or PRs

Fixes#2932

Brief description of what is fixed or changed

Adding header definition to Operation. To be used to render request headers as in openapi v2.

@google-cla
Copy link

google-cla bot commented Oct 20, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@amitavaghosh1 amitavaghosh1 changed the title feat: adds Headers to Operation for spcifying request headers [WIP] feat: adds Headers to Operation for spcifying request headers Oct 20, 2022
@johanbrandhorst johanbrandhorst changed the title [WIP] feat: adds Headers to Operation for spcifying request headers [WIP] feat: adds Headers to Operation for specifying request headers Oct 25, 2022
Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

I'm not sure what's going here but we cannot make this many changes here, it will break all existing users. Please constrain yourself to additions only.

@amitavaghosh1
Copy link
Author

amitavaghosh1 commented Oct 30, 2022

Hi @johanbrandhorst , sorry, I got caught up in some work. Could you please elaborate a bit more. Do you mean, inside Operations we cannot add any more fields?
I have removed the other stuff and kept only headers for now.

@@ -175,6 +175,8 @@ message Operation {
// extra functionality that is not covered by the standard OpenAPI Specification.
// See: https://swagger.io/docs/specification/2-0/swagger-extensions/
map<string, google.protobuf.Value> extensions = 13;

map<string, Header> headers = 14;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The fields in this msaage map to the fields in https://swagger.io/specification/v2/#operation-object. As far as I can tell, headers does not belong here, but in the parameter object: https://swagger.io/specification/v2/#parameter-object. Naturally, we don't actually allow the user to specify the parameter object, since it's entirely inferred from the request parameters in the protobuf file. Maybe you could define a very shallow parameter type and we can allow the user to only specify headers? Still not sure it's a good idea though.

Copy link
Author

Choose a reason for hiding this comment

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

Okay, I will try that. It makes sense. Sure, I will have maybe only the bare minimum and not everything in the spec. for the Parameter object

Copy link
Contributor

@krak3n krak3n Nov 10, 2022

Choose a reason for hiding this comment

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

I'm completely new to this proto to openapiv2 thing, but if we want to avoid users explicitly setting the parameter object and only allow them to define header parameters would it not be safer to add a headers field in the operation message which can be used to add the needed parameters?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it would end u[ be something like this:

message Operation {
  // existing fields
  Parameters parameters = 14;
}

message Parameters {
  repeated HeaderParameter headers = 1;
}

message HeaderParameter {
  string name = 1;
  // etc etc
}

This ends up looking like this in the operation:

service FooService {
  rpc CreateFoo(CreateFooRequest) returns (CreateFooResponse) {
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
      parameters: {
        headers: {
          name: "Authorization";
          description: "Basic Auth";
          required: true;
        };
        headers: {name: "X-Thing"};
        headers: {name: "X-Other"};
      };
    };
  }
}

@krak3n
Copy link
Contributor

krak3n commented Nov 10, 2022

Any news on this one, I am also in need of it 😄

@krak3n
Copy link
Contributor

krak3n commented Nov 10, 2022

Do you mind if I take this over @amitavaghosh1 and open a new PR? I have a working PoC since I'm also in need of this feature.

@johanbrandhorst
Copy link
Collaborator

Please feel free Chris :). I can close this one if we merge the other one.

@krak3n
Copy link
Contributor

krak3n commented Nov 11, 2022

Opened #3010 which I think works 😅

@johanbrandhorst
Copy link
Collaborator

Superceded by #3010

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

Successfully merging this pull request may close these issues.

None yet

3 participants