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

openapiv2_tag.name does not work #3829

Open
omrikiei opened this issue Dec 17, 2023 · 6 comments · Fixed by #3830 or #3843
Open

openapiv2_tag.name does not work #3829

omrikiei opened this issue Dec 17, 2023 · 6 comments · Fixed by #3830 or #3843

Comments

@omrikiei
Copy link
Contributor

omrikiei commented Dec 17, 2023

🐛 Bug Report

openapiv2_tag name attribute is not being considered during generation

To Reproduce

  1. Annotate with openapiv2_tag.name to a name different than the service's name
  2. buf generate

Expected behavior

name should override the service name in swagger.json artifact.

Please assign this to me if possible - I'm working on a fix

Actual Behavior

Name doesn't change

Your Environment

omrikiei added a commit to omrikiei/grpc-gateway that referenced this issue Dec 17, 2023
omrikiei added a commit to omrikiei/grpc-gateway that referenced this issue Dec 17, 2023
[Bug grpc-ecosystem#3829] consider openapiv2_tag.name attribute when generating ope…
johanbrandhorst pushed a commit that referenced this issue Dec 20, 2023
…ute when generating ope… (#3830)

* [Bug #3829] consider openapiv2_tag.name attribute when generating openapi docs

* fix artifacts

* fix test

---------

Co-authored-by: Omri Eival <oeival@grubhub.com>
johanbrandhorst pushed a commit that referenced this issue Dec 29, 2023
* [Bug #3829] consider openapiv2_tag.name attribute when generating openapi docs

* fix tags in methods

* fixup

* generated

* fixup

* fu

* fixup of code

* ran bazel build command

* weird test is flakey
@seanlaff
Copy link
Contributor

seanlaff commented Mar 2, 2024

Is there any additional config needed to make this work? I've been trying it with the latest release (2.19.1) and the tags in the methods don't seem to have the overridden name

syntax = "proto3";

package test;

import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

option go_package = "testing/test";

// ABitOfEverything service is used to validate that APIs with complicated
// proto messages and URL templates are still processed correctly.
service ABitOfEverythingService {
  option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_tag) = {
    name: "ABitOfEverything"
    description: "ABitOfEverythingService description -- which should not be used in place of the documentation comment!"
    external_docs: {
      url: "https://github.com/grpc-ecosystem/grpc-gateway";
      description: "Find out more about EchoService";
    }
  };

  rpc CreateBody(CreateBodyRequest) returns (CreateBodyResponse) {
    option (google.api.http) = {
      post: "/v1/example/a_bit_of_everything"
      body: "*"
    };
  }
}
message CreateBodyRequest {}
message CreateBodyResponse {}
"tags": [
    {
      "name": "ABitOfEverything",
      "description": "ABitOfEverythingService description -- which should not be used in place of the documentation comment!",
      "externalDocs": {
        "description": "Find out more about EchoService",
        "url": "https://github.com/grpc-ecosystem/grpc-gateway"
      }
    }
  ],
  ....
        "tags": [
          "ABitOfEverythingService"
        ]

buf yaml:

version: v1
managed:
  enabled: true
plugins:
  - plugin: buf.build/grpc-ecosystem/openapiv2:v2.19.1
    out: openapi-spec

@johanbrandhorst
Copy link
Collaborator

Hm, perhaps there needs to be an additional fix to update the tags of the methods in the service? CC @omrikiei

@seanlaff
Copy link
Contributor

seanlaff commented Mar 13, 2024

Oh I understand the problem, it looks like #3843 didn't address the behavior in all scenarios (unsure if that was intentional due to limitations- or an oversight).

It looks like the tag is only being overridden if an RPC happens to have a non-nil openapiv2_operation annotation.

Here's an rpc that did properly get the tag overridden/inherited from its Service

/v1/example/a_bit_of_everything/query/{uuidName}:
get:
tags:
- "ABitOfEverything"
operationId: "ABitOfEverythingService_GetQuery"

and its corresponding proto definition
rpc GetQuery(ABitOfEverything) returns (google.protobuf.Empty) {
option (google.api.http) = {get: "/v1/example/a_bit_of_everything/query/{uuid}"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
deprecated: true // For testing purposes.
external_docs: {
url: "https://github.com/grpc-ecosystem/grpc-gateway";
description: "Find out more about GetQuery";
}
security: {}
};
}

and here's an rpc within the same service that didn't get the tag applied
/v1/{book.name}:
patch:
tags:
- "ABitOfEverythingService"
operationId: "ABitOfEverythingService_UpdateBook"

with its corresponding proto defintion
rpc UpdateBook(UpdateBookRequest) returns (Book) {
option (google.api.http) = {
patch: "/v1/{book.name=publishers/*/books/*}"
body: "book"
};
}

Do we think thats the desired behavior? If not, should we re-open this issue, or would it be better to create a new one @johanbrandhorst?

@johanbrandhorst
Copy link
Collaborator

This sounds like a bug, so I've reopened the issue. Thanks for digging into this!

@seanlaff
Copy link
Contributor

seanlaff commented Jun 6, 2024

I am looking into fixing this but Im having a lot of trouble figuring out how to run/test the openapi generator. If I want to regenerate a_bit_of_everything with my changes to the generator- what is the best way to do that?

@johanbrandhorst
Copy link
Collaborator

Please see the instructions in CONTRIBUTING.md, or if you have the tools installed locally you can just run make generate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants