-
Notifications
You must be signed in to change notification settings - Fork 254
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
protoc-gen-openapi - incorrect output for multiple proto files #268
Comments
For us we love this feature. We define our whole api in multiple proto files, but want one openapi spec for mapping from REST. I understand the buf incompatibility isn't great. |
On the feature side, I think it would be great to be able to provide an option such as |
I don't share the opinion that the output is incorrect - like @clintberry, I wanted multiple proto files to be converted into 1 Open API file, which is one of the reasons I chose gnostic over Buf and protoc-gen-openapiv2 . I do agree with @casimcdaniels, that it would be nice to have output to multiple files as an option. It shouldn't be too hard to add this functionality, though there is some logic that might need some extra thinking.
@jan-sykora if you (or anybody else) has some example proto files + example OpenAPI output files, that would be greatly appreciated. /cc @timburks |
I also think that the current behavior "works as intended". At Google, APIs are frequently described with multiple @jan-sykora if you run |
First, thank you all for your replies! Below are some answers to your comments.
@timburks that's a good point. However, as I mentioned, this approach is not easily applicable when using Buf. We had to create a script for copying each proto file into tmp folder, running buf for each of these files, renaming each openapi output, cleaning afterwards, etc. just to get openAPI for each service.
IMHO having openAPI per service is more readable than having it all mixed in one spec. It allows readers to easily display API of only one specific service that they care about. Though that may be a matter of personal preference.
@morphar
I found that the generated // foo.proto
syntax = "proto3";
package example;
option go_package="example/example";
service FooService {} // bar.proto
syntax = "proto3";
package example;
option go_package="example/example";
service BarService {} protoc foo.proto bar.proto -I=. --openapi_out=. generates # Generated with protoc-gen-openapi
# https://github.com/googleapis/gnostic/tree/master/apps/protoc-gen-openapi
openapi: 3.0.3
info:
title: BarService
version: 0.0.1
paths: {}
components:
schemas: {} --> value of When I saw the merged title I was afraid that the content of |
FWIW...the API Discovery Service descriptions of the APIs are describing the HTTP/"REST" interface to the API. For the Google APIs you mention, the HTTP interface is derived from the HTTP bindings added to the proto description of an RPC style interface. The HTTP interface is centered around "resources" (aka "collections") and methods that can be applied to them. In creating the discovery doc description of the HTTP interface, (by default) it derives the resource names from the HTTP paths that have been associated with the method (e.g. an HTTP path like |
I recently ran into this issue as well, and would really like the ability to have multiple files generated instead of just the one.
My use case is as follows:
For example, say on 2022-01-01 we have two microservices,
Now, say that on 2022-12-31 the team that manages
What I'd like to provide is two OpenAPI documents:
The way I'd like to be able to do that is by generating individual OpenAPI docs for each service, and then merging the ones I care about for each "date version" using something like yq to merge the relevant ones together into one. I could also use the new feature added in #324 to create For instance, I could do something like this:
Then in the Running
Then to generate the full documention of my
With this solution there is no moving of files around to various places just to make things work. But in order to do this I would need
|
It all makes sense :) @timburks you know the goals of @jeffsawatzky the automatic title and description stuff, was me expanding on functionality already there. I don't necessarily agree, that Google had and has a certain set of ideas and goals for So I would personally prefer, whatever Google sees as the best way, regardless of the norm and standards arising from other tools. It's of course always nice to have compatibility through e.g. options, when defaults breaks compatibility. But the aim of being able to convert between different formats, is vastly different than "just" being able to create e.g. an OpenAPI spec from .proto files, but not vice versa. This doesn't mean that it shouldn't be possible to "break" this capability, by using "unsafe" options, but the defaults should reflect the goals, in my opinion, regardless of whatever else is out there. A personal example of why I'd rather stick to Google's way of doing things: I don't know if this was a bug or a "nice feature" (default behaviour) of the other tool, but it caused a lot of problems down the line. I would personally much prefer Anyway... That became a rant, sorry. |
@timburks if someone were to put up a PR to optionally support multiple files, would you be ok with that or does it go against gnostic ideals and get rejected? @morphar many of the tools that I refer to are the built in tools created by Google themself. So if, as you say, Google has put a lot of thought into this then there is probably a good reason as to why their tools support multiple files. Also I'm not sure how supporting multiple files loses any information or breaks away from correct functionality, especially if it is optional. Plus, gnostic is already losing information. For instance with Anyway, long story short, I just want to know whether a PR to add multiple output file support would be ok or rejected. 😄 As for how it would work, I'd suggest following something similar to what grpc-gateway's protoc-gen-openapiv2 is doing. |
@jeffsawatzky short answer: ask @timburks, I'm also just a contributor ;)
I was referring to proto and API Discovery with regards to 1 file.
I am totally for supporting as much functionality and being as compatible as possible - especially as optional.
Again: I agree. As I have stated earlier, I think this project would benefit hugely from having officially stated goals. |
Hi, I agree with @morphar's suggestion that it would be good to discuss overall project goals and influences. I'll start an issue about that (edit: see #340). On this topic, I can say that an original goal of Basically this means supporting the googleapis protos and generating OpenAPI docs for each transcoded API. @jeffsawatzky, the Discovery docs are organized one-per-API-version. These are all generated from protos, either from public or internal ones, and each API version corresponds to a directory path that ends in a version name ( Could aggregation be treated as a separate operation on OpenAPI documents? If so, that moves it out of scope for |
@timburks in regards what @jeffsawatzky proposed: I'd like to propose an PR, discussing the interface (plugin options) there: #359 We have the usecase of using buf in a monorepo. My suggestion would be: add a flag
optional: add a boolean flag
|
Description
When running protoc-gen-openapi for generating OpenAPI description for multiple .proto files, the output is incorrectly mixed into one OpenAPI description file.
Expected behaviour is to generate OpenAPI description for each .proto file separately when there's more than one proto file on the input. The protoc-gen-openapiv2 from grpc-gateway also generates for each proto file a separate OpenAPI description file.
Example
Let there be two .proto files:
and the protoc-gen-openapi plugin is run for both of these files at once:
Expected output:
Actual output:
Buf incompatibility
This behaviour makes the protoc-gen-openapi plugin impossible to be used by Buf since Buf is designed to process multiple proto files when generating content (it works with modules which are basically directories containing multiple proto files) and it is not possible to configure Buf to process proto files one by one.
The text was updated successfully, but these errors were encountered: