diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ee6b20d3..39a3996d 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -2,9 +2,9 @@ name: Go on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] jobs: diff --git a/COMPILE-PROTOS.sh b/COMPILE-PROTOS.sh index b7b4774e..d9269089 100755 --- a/COMPILE-PROTOS.sh +++ b/COMPILE-PROTOS.sh @@ -15,7 +15,7 @@ # limitations under the License. # -go install github.com/golang/protobuf/protoc-gen-go@latest +go install google.golang.org/protobuf/cmd/protoc-gen-go@latest protoc -I . -I ./third_party --go_out=. --go_opt=paths=source_relative openapiv2/*.proto protoc -I . -I ./third_party --go_out=. --go_opt=paths=source_relative openapiv3/*.proto diff --git a/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi.yaml b/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi.yaml index e0c52870..219a0b24 100644 --- a/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi.yaml +++ b/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi.yaml @@ -29,13 +29,19 @@ paths: parameters: - name: page_size in: query - description: Requested page size. Server may return fewer shelves than requested. If unspecified, server will pick an appropriate default. + description: |- + Requested page size. Server may return fewer shelves than requested. + If unspecified, server will pick an appropriate default. schema: type: integer format: int32 - name: page_token in: query - description: A token identifying a page of results the server should return. Typically, this is the value of [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token] returned from the previous call to `ListShelves` method. + description: |- + A token identifying a page of results the server should return. + Typically, this is the value of + [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token] + returned from the previous call to `ListShelves` method. schema: type: string responses: @@ -141,13 +147,19 @@ paths: type: string - name: page_size in: query - description: Requested page size. Server may return fewer books than requested. If unspecified, server will pick an appropriate default. + description: |- + Requested page size. Server may return fewer books than requested. + If unspecified, server will pick an appropriate default. schema: type: integer format: int32 - name: page_token in: query - description: A token identifying a page of results the server should return. Typically, this is the value of [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token]. returned from the previous call to `ListBooks` method. + description: |- + A token identifying a page of results the server should return. + Typically, this is the value of + [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token]. + returned from the previous call to `ListBooks` method. schema: type: string responses: @@ -386,7 +398,10 @@ components: properties: name: type: string - description: The resource name of the book. Book names have the form `shelves/{shelf_id}/books/{book_id}`. The name is ignored when creating a book. + description: |- + The resource name of the book. + Book names have the form `shelves/{shelf_id}/books/{book_id}`. + The name is ignored when creating a book. author: type: string description: The name of the book author. @@ -430,7 +445,12 @@ components: description: The list of books. next_page_token: type: string - description: A token to retrieve next page of results. Pass this value in the [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token] field in the subsequent call to `ListBooks` method to retrieve the next page of results. + description: |- + A token to retrieve next page of results. + Pass this value in the + [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token] + field in the subsequent call to `ListBooks` method to retrieve the next + page of results. description: Response message for LibraryService.ListBooks. ListShelvesResponse: type: object @@ -442,7 +462,12 @@ components: description: The list of shelves. next_page_token: type: string - description: A token to retrieve next page of results. Pass this value in the [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] field in the subsequent call to `ListShelves` method to retrieve the next page of results. + description: |- + A token to retrieve next page of results. + Pass this value in the + [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] + field in the subsequent call to `ListShelves` method to retrieve the next + page of results. description: Response message for LibraryService.ListShelves. MergeShelvesRequest: required: @@ -456,7 +481,9 @@ components: other_shelf_name: type: string description: The name of the shelf we're removing books from and deleting. - description: Describes the shelf being removed (other_shelf_name) and updated (name) in this merge. + description: |- + Describes the shelf being removed (other_shelf_name) and updated + (name) in this merge. MoveBookRequest: required: - name @@ -469,7 +496,9 @@ components: other_shelf_name: type: string description: The name of the destination shelf. - description: Describes what book to move (name) and what shelf we're moving it to (other_shelf_name). + description: |- + Describes what book to move (name) and what shelf we're moving it + to (other_shelf_name). Shelf: required: - name @@ -477,7 +506,10 @@ components: properties: name: type: string - description: The resource name of the shelf. Shelf names have the form `shelves/{shelf_id}`. The name is ignored when creating a shelf. + description: |- + The resource name of the shelf. + Shelf names have the form `shelves/{shelf_id}`. + The name is ignored when creating a shelf. theme: type: string description: The theme of the shelf diff --git a/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_default_response.yaml b/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_default_response.yaml index 9ffae16a..f1ecadb6 100644 --- a/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_default_response.yaml +++ b/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_default_response.yaml @@ -29,13 +29,19 @@ paths: parameters: - name: pageSize in: query - description: Requested page size. Server may return fewer shelves than requested. If unspecified, server will pick an appropriate default. + description: |- + Requested page size. Server may return fewer shelves than requested. + If unspecified, server will pick an appropriate default. schema: type: integer format: int32 - name: pageToken in: query - description: A token identifying a page of results the server should return. Typically, this is the value of [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token] returned from the previous call to `ListShelves` method. + description: |- + A token identifying a page of results the server should return. + Typically, this is the value of + [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token] + returned from the previous call to `ListShelves` method. schema: type: string responses: @@ -141,13 +147,19 @@ paths: type: string - name: pageSize in: query - description: Requested page size. Server may return fewer books than requested. If unspecified, server will pick an appropriate default. + description: |- + Requested page size. Server may return fewer books than requested. + If unspecified, server will pick an appropriate default. schema: type: integer format: int32 - name: pageToken in: query - description: A token identifying a page of results the server should return. Typically, this is the value of [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token]. returned from the previous call to `ListBooks` method. + description: |- + A token identifying a page of results the server should return. + Typically, this is the value of + [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token]. + returned from the previous call to `ListBooks` method. schema: type: string responses: @@ -386,7 +398,10 @@ components: properties: name: type: string - description: The resource name of the book. Book names have the form `shelves/{shelf_id}/books/{book_id}`. The name is ignored when creating a book. + description: |- + The resource name of the book. + Book names have the form `shelves/{shelf_id}/books/{book_id}`. + The name is ignored when creating a book. author: type: string description: The name of the book author. @@ -430,7 +445,12 @@ components: description: The list of books. nextPageToken: type: string - description: A token to retrieve next page of results. Pass this value in the [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token] field in the subsequent call to `ListBooks` method to retrieve the next page of results. + description: |- + A token to retrieve next page of results. + Pass this value in the + [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token] + field in the subsequent call to `ListBooks` method to retrieve the next + page of results. description: Response message for LibraryService.ListBooks. ListShelvesResponse: type: object @@ -442,7 +462,12 @@ components: description: The list of shelves. nextPageToken: type: string - description: A token to retrieve next page of results. Pass this value in the [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] field in the subsequent call to `ListShelves` method to retrieve the next page of results. + description: |- + A token to retrieve next page of results. + Pass this value in the + [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] + field in the subsequent call to `ListShelves` method to retrieve the next + page of results. description: Response message for LibraryService.ListShelves. MergeShelvesRequest: required: @@ -456,7 +481,9 @@ components: otherShelfName: type: string description: The name of the shelf we're removing books from and deleting. - description: Describes the shelf being removed (other_shelf_name) and updated (name) in this merge. + description: |- + Describes the shelf being removed (other_shelf_name) and updated + (name) in this merge. MoveBookRequest: required: - name @@ -469,7 +496,9 @@ components: otherShelfName: type: string description: The name of the destination shelf. - description: Describes what book to move (name) and what shelf we're moving it to (other_shelf_name). + description: |- + Describes what book to move (name) and what shelf we're moving it + to (other_shelf_name). Shelf: required: - name @@ -477,7 +506,10 @@ components: properties: name: type: string - description: The resource name of the shelf. Shelf names have the form `shelves/{shelf_id}`. The name is ignored when creating a shelf. + description: |- + The resource name of the shelf. + Shelf names have the form `shelves/{shelf_id}`. + The name is ignored when creating a shelf. theme: type: string description: The theme of the shelf diff --git a/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_fq_schema_naming.yaml b/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_fq_schema_naming.yaml index b9ee04d8..2b908fa3 100644 --- a/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_fq_schema_naming.yaml +++ b/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_fq_schema_naming.yaml @@ -29,13 +29,19 @@ paths: parameters: - name: pageSize in: query - description: Requested page size. Server may return fewer shelves than requested. If unspecified, server will pick an appropriate default. + description: |- + Requested page size. Server may return fewer shelves than requested. + If unspecified, server will pick an appropriate default. schema: type: integer format: int32 - name: pageToken in: query - description: A token identifying a page of results the server should return. Typically, this is the value of [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token] returned from the previous call to `ListShelves` method. + description: |- + A token identifying a page of results the server should return. + Typically, this is the value of + [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token] + returned from the previous call to `ListShelves` method. schema: type: string responses: @@ -141,13 +147,19 @@ paths: type: string - name: pageSize in: query - description: Requested page size. Server may return fewer books than requested. If unspecified, server will pick an appropriate default. + description: |- + Requested page size. Server may return fewer books than requested. + If unspecified, server will pick an appropriate default. schema: type: integer format: int32 - name: pageToken in: query - description: A token identifying a page of results the server should return. Typically, this is the value of [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token]. returned from the previous call to `ListBooks` method. + description: |- + A token identifying a page of results the server should return. + Typically, this is the value of + [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token]. + returned from the previous call to `ListBooks` method. schema: type: string responses: @@ -386,7 +398,10 @@ components: properties: name: type: string - description: The resource name of the book. Book names have the form `shelves/{shelf_id}/books/{book_id}`. The name is ignored when creating a book. + description: |- + The resource name of the book. + Book names have the form `shelves/{shelf_id}/books/{book_id}`. + The name is ignored when creating a book. author: type: string description: The name of the book author. @@ -422,7 +437,12 @@ components: description: The list of books. nextPageToken: type: string - description: A token to retrieve next page of results. Pass this value in the [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token] field in the subsequent call to `ListBooks` method to retrieve the next page of results. + description: |- + A token to retrieve next page of results. + Pass this value in the + [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token] + field in the subsequent call to `ListBooks` method to retrieve the next + page of results. description: Response message for LibraryService.ListBooks. google.example.library.v1.ListShelvesResponse: type: object @@ -434,7 +454,12 @@ components: description: The list of shelves. nextPageToken: type: string - description: A token to retrieve next page of results. Pass this value in the [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] field in the subsequent call to `ListShelves` method to retrieve the next page of results. + description: |- + A token to retrieve next page of results. + Pass this value in the + [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] + field in the subsequent call to `ListShelves` method to retrieve the next + page of results. description: Response message for LibraryService.ListShelves. google.example.library.v1.MergeShelvesRequest: required: @@ -448,7 +473,9 @@ components: otherShelfName: type: string description: The name of the shelf we're removing books from and deleting. - description: Describes the shelf being removed (other_shelf_name) and updated (name) in this merge. + description: |- + Describes the shelf being removed (other_shelf_name) and updated + (name) in this merge. google.example.library.v1.MoveBookRequest: required: - name @@ -461,7 +488,9 @@ components: otherShelfName: type: string description: The name of the destination shelf. - description: Describes what book to move (name) and what shelf we're moving it to (other_shelf_name). + description: |- + Describes what book to move (name) and what shelf we're moving it + to (other_shelf_name). google.example.library.v1.Shelf: required: - name @@ -469,7 +498,10 @@ components: properties: name: type: string - description: The resource name of the shelf. Shelf names have the form `shelves/{shelf_id}`. The name is ignored when creating a shelf. + description: |- + The resource name of the shelf. + Shelf names have the form `shelves/{shelf_id}`. + The name is ignored when creating a shelf. theme: type: string description: The theme of the shelf diff --git a/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_json.yaml b/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_json.yaml index 38172184..a0ea21f4 100644 --- a/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_json.yaml +++ b/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_json.yaml @@ -29,13 +29,19 @@ paths: parameters: - name: pageSize in: query - description: Requested page size. Server may return fewer shelves than requested. If unspecified, server will pick an appropriate default. + description: |- + Requested page size. Server may return fewer shelves than requested. + If unspecified, server will pick an appropriate default. schema: type: integer format: int32 - name: pageToken in: query - description: A token identifying a page of results the server should return. Typically, this is the value of [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token] returned from the previous call to `ListShelves` method. + description: |- + A token identifying a page of results the server should return. + Typically, this is the value of + [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token] + returned from the previous call to `ListShelves` method. schema: type: string responses: @@ -141,13 +147,19 @@ paths: type: string - name: pageSize in: query - description: Requested page size. Server may return fewer books than requested. If unspecified, server will pick an appropriate default. + description: |- + Requested page size. Server may return fewer books than requested. + If unspecified, server will pick an appropriate default. schema: type: integer format: int32 - name: pageToken in: query - description: A token identifying a page of results the server should return. Typically, this is the value of [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token]. returned from the previous call to `ListBooks` method. + description: |- + A token identifying a page of results the server should return. + Typically, this is the value of + [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token]. + returned from the previous call to `ListBooks` method. schema: type: string responses: @@ -386,7 +398,10 @@ components: properties: name: type: string - description: The resource name of the book. Book names have the form `shelves/{shelf_id}/books/{book_id}`. The name is ignored when creating a book. + description: |- + The resource name of the book. + Book names have the form `shelves/{shelf_id}/books/{book_id}`. + The name is ignored when creating a book. author: type: string description: The name of the book author. @@ -430,7 +445,12 @@ components: description: The list of books. nextPageToken: type: string - description: A token to retrieve next page of results. Pass this value in the [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token] field in the subsequent call to `ListBooks` method to retrieve the next page of results. + description: |- + A token to retrieve next page of results. + Pass this value in the + [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token] + field in the subsequent call to `ListBooks` method to retrieve the next + page of results. description: Response message for LibraryService.ListBooks. ListShelvesResponse: type: object @@ -442,7 +462,12 @@ components: description: The list of shelves. nextPageToken: type: string - description: A token to retrieve next page of results. Pass this value in the [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] field in the subsequent call to `ListShelves` method to retrieve the next page of results. + description: |- + A token to retrieve next page of results. + Pass this value in the + [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] + field in the subsequent call to `ListShelves` method to retrieve the next + page of results. description: Response message for LibraryService.ListShelves. MergeShelvesRequest: required: @@ -456,7 +481,9 @@ components: otherShelfName: type: string description: The name of the shelf we're removing books from and deleting. - description: Describes the shelf being removed (other_shelf_name) and updated (name) in this merge. + description: |- + Describes the shelf being removed (other_shelf_name) and updated + (name) in this merge. MoveBookRequest: required: - name @@ -469,7 +496,9 @@ components: otherShelfName: type: string description: The name of the destination shelf. - description: Describes what book to move (name) and what shelf we're moving it to (other_shelf_name). + description: |- + Describes what book to move (name) and what shelf we're moving it + to (other_shelf_name). Shelf: required: - name @@ -477,7 +506,10 @@ components: properties: name: type: string - description: The resource name of the shelf. Shelf names have the form `shelves/{shelf_id}`. The name is ignored when creating a shelf. + description: |- + The resource name of the shelf. + Shelf names have the form `shelves/{shelf_id}`. + The name is ignored when creating a shelf. theme: type: string description: The theme of the shelf diff --git a/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_string_enum.yaml b/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_string_enum.yaml index 9ffae16a..f1ecadb6 100644 --- a/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_string_enum.yaml +++ b/cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_string_enum.yaml @@ -29,13 +29,19 @@ paths: parameters: - name: pageSize in: query - description: Requested page size. Server may return fewer shelves than requested. If unspecified, server will pick an appropriate default. + description: |- + Requested page size. Server may return fewer shelves than requested. + If unspecified, server will pick an appropriate default. schema: type: integer format: int32 - name: pageToken in: query - description: A token identifying a page of results the server should return. Typically, this is the value of [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token] returned from the previous call to `ListShelves` method. + description: |- + A token identifying a page of results the server should return. + Typically, this is the value of + [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token] + returned from the previous call to `ListShelves` method. schema: type: string responses: @@ -141,13 +147,19 @@ paths: type: string - name: pageSize in: query - description: Requested page size. Server may return fewer books than requested. If unspecified, server will pick an appropriate default. + description: |- + Requested page size. Server may return fewer books than requested. + If unspecified, server will pick an appropriate default. schema: type: integer format: int32 - name: pageToken in: query - description: A token identifying a page of results the server should return. Typically, this is the value of [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token]. returned from the previous call to `ListBooks` method. + description: |- + A token identifying a page of results the server should return. + Typically, this is the value of + [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token]. + returned from the previous call to `ListBooks` method. schema: type: string responses: @@ -386,7 +398,10 @@ components: properties: name: type: string - description: The resource name of the book. Book names have the form `shelves/{shelf_id}/books/{book_id}`. The name is ignored when creating a book. + description: |- + The resource name of the book. + Book names have the form `shelves/{shelf_id}/books/{book_id}`. + The name is ignored when creating a book. author: type: string description: The name of the book author. @@ -430,7 +445,12 @@ components: description: The list of books. nextPageToken: type: string - description: A token to retrieve next page of results. Pass this value in the [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token] field in the subsequent call to `ListBooks` method to retrieve the next page of results. + description: |- + A token to retrieve next page of results. + Pass this value in the + [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token] + field in the subsequent call to `ListBooks` method to retrieve the next + page of results. description: Response message for LibraryService.ListBooks. ListShelvesResponse: type: object @@ -442,7 +462,12 @@ components: description: The list of shelves. nextPageToken: type: string - description: A token to retrieve next page of results. Pass this value in the [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] field in the subsequent call to `ListShelves` method to retrieve the next page of results. + description: |- + A token to retrieve next page of results. + Pass this value in the + [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token] + field in the subsequent call to `ListShelves` method to retrieve the next + page of results. description: Response message for LibraryService.ListShelves. MergeShelvesRequest: required: @@ -456,7 +481,9 @@ components: otherShelfName: type: string description: The name of the shelf we're removing books from and deleting. - description: Describes the shelf being removed (other_shelf_name) and updated (name) in this merge. + description: |- + Describes the shelf being removed (other_shelf_name) and updated + (name) in this merge. MoveBookRequest: required: - name @@ -469,7 +496,9 @@ components: otherShelfName: type: string description: The name of the destination shelf. - description: Describes what book to move (name) and what shelf we're moving it to (other_shelf_name). + description: |- + Describes what book to move (name) and what shelf we're moving it + to (other_shelf_name). Shelf: required: - name @@ -477,7 +506,10 @@ components: properties: name: type: string - description: The resource name of the shelf. Shelf names have the form `shelves/{shelf_id}`. The name is ignored when creating a shelf. + description: |- + The resource name of the shelf. + Shelf names have the form `shelves/{shelf_id}`. + The name is ignored when creating a shelf. theme: type: string description: The theme of the shelf diff --git a/cmd/protoc-gen-openapi/examples/tests/additional_bindings/message.proto b/cmd/protoc-gen-openapi/examples/tests/additional_bindings/message.proto new file mode 100644 index 00000000..4d19c966 --- /dev/null +++ b/cmd/protoc-gen-openapi/examples/tests/additional_bindings/message.proto @@ -0,0 +1,39 @@ +// Copyright 2020 Google LLC. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +syntax = "proto3"; + +package tests.bodymappying.message.v1; + +import "google/api/annotations.proto"; + +option go_package = "github.com/google/gnostic/apps/protoc-gen-openapi/examples/tests/additional_bindings/message/v1;message"; + +service Messaging { + rpc UpdateMessage(Message) returns(Message) { + option(google.api.http) = { + patch: "/v1/messages/{message_id}" + body: "text" + additional_bindings { + patch: "/v1/messages" + body: "*" + } + }; + } +} +message Message { + string message_id = 1; + string text = 2; +} diff --git a/cmd/protoc-gen-openapi/examples/tests/additional_bindings/openapi.yaml b/cmd/protoc-gen-openapi/examples/tests/additional_bindings/openapi.yaml new file mode 100644 index 00000000..15c32d3e --- /dev/null +++ b/cmd/protoc-gen-openapi/examples/tests/additional_bindings/openapi.yaml @@ -0,0 +1,97 @@ +# Generated with protoc-gen-openapi +# https://github.com/google/gnostic/tree/master/cmd/protoc-gen-openapi + +openapi: 3.0.3 +info: + title: Messaging API + version: 0.0.1 +paths: + /v1/messages: + patch: + tags: + - Messaging + operationId: Messaging_UpdateMessage + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Message' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Message' + default: + description: Default error response + content: + application/json: + schema: + $ref: '#/components/schemas/Status' + /v1/messages/{message_id}: + patch: + tags: + - Messaging + operationId: Messaging_UpdateMessage + parameters: + - name: message_id + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + type: string + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Message' + default: + description: Default error response + content: + application/json: + schema: + $ref: '#/components/schemas/Status' +components: + schemas: + GoogleProtobufAny: + type: object + properties: + '@type': + type: string + description: The type of the serialized message. + additionalProperties: true + description: Contains an arbitrary serialized message along with a @type that describes the type of the serialized message. + Message: + type: object + properties: + message_id: + type: string + text: + type: string + Status: + type: object + properties: + code: + type: integer + description: The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code]. + format: int32 + message: + type: string + description: A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client. + details: + type: array + items: + $ref: '#/components/schemas/GoogleProtobufAny' + description: A list of messages that carry the error details. There is a common set of message types for APIs to use. + description: 'The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).' +tags: + - name: Messaging diff --git a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/message.proto b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/message.proto index c0161a9e..6dba0b53 100644 --- a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/message.proto +++ b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/message.proto @@ -22,6 +22,8 @@ import "google/api/annotations.proto"; import "google/api/httpbody.proto"; import "google/protobuf/struct.proto"; import "google/protobuf/empty.proto"; +import "google/protobuf/wrappers.proto"; +import "google/protobuf/timestamp.proto"; option go_package = "github.com/google/gnostic/apps/protoc-gen-openapi/examples/tests/protobuftypes/message/v1;message"; @@ -101,4 +103,14 @@ message Message { google.protobuf.Value value_type = 13; // Description of repeated value repeated google.protobuf.Value repeated_value_type = 14; + google.protobuf.BoolValue bool_value_type = 15; + google.protobuf.BytesValue bytes_value_type = 16; + google.protobuf.Int32Value int32_value_type = 17; + google.protobuf.UInt32Value uint32_value_type = 18; + google.protobuf.StringValue string_value_type = 19; + google.protobuf.Int64Value int64_value_type = 20; + google.protobuf.UInt64Value uint64_value_type = 21; + google.protobuf.FloatValue float_value_type = 22; + google.protobuf.DoubleValue double_value_type = 23; + google.protobuf.Timestamp timestamp_type = 24; } diff --git a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi.yaml b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi.yaml index 14b82b38..624104e9 100644 --- a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi.yaml +++ b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi.yaml @@ -98,6 +98,52 @@ paths: type: array items: $ref: '#/components/schemas/GoogleProtobufValue' + - name: bool_value_type + in: query + schema: + type: boolean + - name: bytes_value_type + in: query + schema: + type: string + format: bytes + - name: int32_value_type + in: query + schema: + type: integer + format: int32 + - name: uint32_value_type + in: query + schema: + type: integer + format: uint32 + - name: string_value_type + in: query + schema: + type: string + - name: int64_value_type + in: query + schema: + type: string + - name: uint64_value_type + in: query + schema: + type: string + - name: float_value_type + in: query + schema: + type: number + format: float + - name: double_value_type + in: query + schema: + type: number + format: double + - name: timestamp_type + in: query + schema: + type: string + format: date-time responses: "200": description: OK @@ -211,6 +257,52 @@ paths: type: array items: $ref: '#/components/schemas/GoogleProtobufValue' + - name: bool_value_type + in: query + schema: + type: boolean + - name: bytes_value_type + in: query + schema: + type: string + format: bytes + - name: int32_value_type + in: query + schema: + type: integer + format: int32 + - name: uint32_value_type + in: query + schema: + type: integer + format: uint32 + - name: string_value_type + in: query + schema: + type: string + - name: int64_value_type + in: query + schema: + type: string + - name: uint64_value_type + in: query + schema: + type: string + - name: float_value_type + in: query + schema: + type: number + format: float + - name: double_value_type + in: query + schema: + type: number + format: double + - name: timestamp_type + in: query + schema: + type: string + format: date-time requestBody: content: application/json: @@ -326,6 +418,32 @@ components: items: $ref: '#/components/schemas/GoogleProtobufValue' description: Description of repeated value + bool_value_type: + type: boolean + bytes_value_type: + type: string + format: bytes + int32_value_type: + type: integer + format: int32 + uint32_value_type: + type: integer + format: uint32 + string_value_type: + type: string + int64_value_type: + type: string + uint64_value_type: + type: string + float_value_type: + type: number + format: float + double_value_type: + type: number + format: double + timestamp_type: + type: string + format: date-time Message_EmbMessage: type: object properties: diff --git a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_default_response.yaml b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_default_response.yaml index c60cbf26..f8594143 100644 --- a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_default_response.yaml +++ b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_default_response.yaml @@ -98,6 +98,52 @@ paths: type: array items: $ref: '#/components/schemas/GoogleProtobufValue' + - name: boolValueType + in: query + schema: + type: boolean + - name: bytesValueType + in: query + schema: + type: string + format: bytes + - name: int32ValueType + in: query + schema: + type: integer + format: int32 + - name: uint32ValueType + in: query + schema: + type: integer + format: uint32 + - name: stringValueType + in: query + schema: + type: string + - name: int64ValueType + in: query + schema: + type: string + - name: uint64ValueType + in: query + schema: + type: string + - name: floatValueType + in: query + schema: + type: number + format: float + - name: doubleValueType + in: query + schema: + type: number + format: double + - name: timestampType + in: query + schema: + type: string + format: date-time responses: "200": description: OK @@ -211,6 +257,52 @@ paths: type: array items: $ref: '#/components/schemas/GoogleProtobufValue' + - name: boolValueType + in: query + schema: + type: boolean + - name: bytesValueType + in: query + schema: + type: string + format: bytes + - name: int32ValueType + in: query + schema: + type: integer + format: int32 + - name: uint32ValueType + in: query + schema: + type: integer + format: uint32 + - name: stringValueType + in: query + schema: + type: string + - name: int64ValueType + in: query + schema: + type: string + - name: uint64ValueType + in: query + schema: + type: string + - name: floatValueType + in: query + schema: + type: number + format: float + - name: doubleValueType + in: query + schema: + type: number + format: double + - name: timestampType + in: query + schema: + type: string + format: date-time requestBody: content: application/json: @@ -326,6 +418,32 @@ components: items: $ref: '#/components/schemas/GoogleProtobufValue' description: Description of repeated value + boolValueType: + type: boolean + bytesValueType: + type: string + format: bytes + int32ValueType: + type: integer + format: int32 + uint32ValueType: + type: integer + format: uint32 + stringValueType: + type: string + int64ValueType: + type: string + uint64ValueType: + type: string + floatValueType: + type: number + format: float + doubleValueType: + type: number + format: double + timestampType: + type: string + format: date-time Message_EmbMessage: type: object properties: diff --git a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_fq_schema_naming.yaml b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_fq_schema_naming.yaml index 187bba79..1a674700 100644 --- a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_fq_schema_naming.yaml +++ b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_fq_schema_naming.yaml @@ -98,6 +98,52 @@ paths: type: array items: $ref: '#/components/schemas/google.protobuf.Value' + - name: boolValueType + in: query + schema: + type: boolean + - name: bytesValueType + in: query + schema: + type: string + format: bytes + - name: int32ValueType + in: query + schema: + type: integer + format: int32 + - name: uint32ValueType + in: query + schema: + type: integer + format: uint32 + - name: stringValueType + in: query + schema: + type: string + - name: int64ValueType + in: query + schema: + type: string + - name: uint64ValueType + in: query + schema: + type: string + - name: floatValueType + in: query + schema: + type: number + format: float + - name: doubleValueType + in: query + schema: + type: number + format: double + - name: timestampType + in: query + schema: + type: string + format: date-time responses: "200": description: OK @@ -211,6 +257,52 @@ paths: type: array items: $ref: '#/components/schemas/google.protobuf.Value' + - name: boolValueType + in: query + schema: + type: boolean + - name: bytesValueType + in: query + schema: + type: string + format: bytes + - name: int32ValueType + in: query + schema: + type: integer + format: int32 + - name: uint32ValueType + in: query + schema: + type: integer + format: uint32 + - name: stringValueType + in: query + schema: + type: string + - name: int64ValueType + in: query + schema: + type: string + - name: uint64ValueType + in: query + schema: + type: string + - name: floatValueType + in: query + schema: + type: number + format: float + - name: doubleValueType + in: query + schema: + type: number + format: double + - name: timestampType + in: query + schema: + type: string + format: date-time requestBody: content: application/json: @@ -342,6 +434,32 @@ components: items: $ref: '#/components/schemas/google.protobuf.Value' description: Description of repeated value + boolValueType: + type: boolean + bytesValueType: + type: string + format: bytes + int32ValueType: + type: integer + format: int32 + uint32ValueType: + type: integer + format: uint32 + stringValueType: + type: string + int64ValueType: + type: string + uint64ValueType: + type: string + floatValueType: + type: number + format: float + doubleValueType: + type: number + format: double + timestampType: + type: string + format: date-time tests.protobuftypes.message.v1.Message_EmbMessage: type: object properties: diff --git a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_json.yaml b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_json.yaml index c73847e1..c23150a1 100644 --- a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_json.yaml +++ b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_json.yaml @@ -98,6 +98,52 @@ paths: type: array items: $ref: '#/components/schemas/GoogleProtobufValue' + - name: boolValueType + in: query + schema: + type: boolean + - name: bytesValueType + in: query + schema: + type: string + format: bytes + - name: int32ValueType + in: query + schema: + type: integer + format: int32 + - name: uint32ValueType + in: query + schema: + type: integer + format: uint32 + - name: stringValueType + in: query + schema: + type: string + - name: int64ValueType + in: query + schema: + type: string + - name: uint64ValueType + in: query + schema: + type: string + - name: floatValueType + in: query + schema: + type: number + format: float + - name: doubleValueType + in: query + schema: + type: number + format: double + - name: timestampType + in: query + schema: + type: string + format: date-time responses: "200": description: OK @@ -211,6 +257,52 @@ paths: type: array items: $ref: '#/components/schemas/GoogleProtobufValue' + - name: boolValueType + in: query + schema: + type: boolean + - name: bytesValueType + in: query + schema: + type: string + format: bytes + - name: int32ValueType + in: query + schema: + type: integer + format: int32 + - name: uint32ValueType + in: query + schema: + type: integer + format: uint32 + - name: stringValueType + in: query + schema: + type: string + - name: int64ValueType + in: query + schema: + type: string + - name: uint64ValueType + in: query + schema: + type: string + - name: floatValueType + in: query + schema: + type: number + format: float + - name: doubleValueType + in: query + schema: + type: number + format: double + - name: timestampType + in: query + schema: + type: string + format: date-time requestBody: content: application/json: @@ -326,6 +418,32 @@ components: items: $ref: '#/components/schemas/GoogleProtobufValue' description: Description of repeated value + boolValueType: + type: boolean + bytesValueType: + type: string + format: bytes + int32ValueType: + type: integer + format: int32 + uint32ValueType: + type: integer + format: uint32 + stringValueType: + type: string + int64ValueType: + type: string + uint64ValueType: + type: string + floatValueType: + type: number + format: float + doubleValueType: + type: number + format: double + timestampType: + type: string + format: date-time Message_EmbMessage: type: object properties: diff --git a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_string_enum.yaml b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_string_enum.yaml index c60cbf26..f8594143 100644 --- a/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_string_enum.yaml +++ b/cmd/protoc-gen-openapi/examples/tests/protobuftypes/openapi_string_enum.yaml @@ -98,6 +98,52 @@ paths: type: array items: $ref: '#/components/schemas/GoogleProtobufValue' + - name: boolValueType + in: query + schema: + type: boolean + - name: bytesValueType + in: query + schema: + type: string + format: bytes + - name: int32ValueType + in: query + schema: + type: integer + format: int32 + - name: uint32ValueType + in: query + schema: + type: integer + format: uint32 + - name: stringValueType + in: query + schema: + type: string + - name: int64ValueType + in: query + schema: + type: string + - name: uint64ValueType + in: query + schema: + type: string + - name: floatValueType + in: query + schema: + type: number + format: float + - name: doubleValueType + in: query + schema: + type: number + format: double + - name: timestampType + in: query + schema: + type: string + format: date-time responses: "200": description: OK @@ -211,6 +257,52 @@ paths: type: array items: $ref: '#/components/schemas/GoogleProtobufValue' + - name: boolValueType + in: query + schema: + type: boolean + - name: bytesValueType + in: query + schema: + type: string + format: bytes + - name: int32ValueType + in: query + schema: + type: integer + format: int32 + - name: uint32ValueType + in: query + schema: + type: integer + format: uint32 + - name: stringValueType + in: query + schema: + type: string + - name: int64ValueType + in: query + schema: + type: string + - name: uint64ValueType + in: query + schema: + type: string + - name: floatValueType + in: query + schema: + type: number + format: float + - name: doubleValueType + in: query + schema: + type: number + format: double + - name: timestampType + in: query + schema: + type: string + format: date-time requestBody: content: application/json: @@ -326,6 +418,32 @@ components: items: $ref: '#/components/schemas/GoogleProtobufValue' description: Description of repeated value + boolValueType: + type: boolean + bytesValueType: + type: string + format: bytes + int32ValueType: + type: integer + format: int32 + uint32ValueType: + type: integer + format: uint32 + stringValueType: + type: string + int64ValueType: + type: string + uint64ValueType: + type: string + floatValueType: + type: number + format: float + doubleValueType: + type: number + format: double + timestampType: + type: string + format: date-time Message_EmbMessage: type: object properties: diff --git a/cmd/protoc-gen-openapi/generator/generator.go b/cmd/protoc-gen-openapi/generator/generator.go index 563aabf0..f9a4acd9 100644 --- a/cmd/protoc-gen-openapi/generator/generator.go +++ b/cmd/protoc-gen-openapi/generator/generator.go @@ -239,13 +239,9 @@ func (g *OpenAPIv3Generator) buildDocumentV3() *v3.Document { return d } -// filterCommentString removes line breaks and linter rules from comments. -func (g *OpenAPIv3Generator) filterCommentString(c protogen.Comments, removeNewLines bool) string { - comment := string(c) - if removeNewLines { - comment = strings.Replace(comment, "\n", "", -1) - } - comment = g.linterRulePattern.ReplaceAllString(comment, "") +// filterCommentString removes linter rules from comments. +func (g *OpenAPIv3Generator) filterCommentString(c protogen.Comments) string { + comment := g.linterRulePattern.ReplaceAllString(string(c), "") return strings.TrimSpace(comment) } @@ -273,6 +269,9 @@ func (g *OpenAPIv3Generator) findAndFormatFieldName(name string, inMessage *prot // In the case of a repeated type, the parameter can be repeated in the URL as ...?param=A¶m=B. // In the case of a message type, each field of the message is mapped to a separate parameter, // such as ...?foo.a=A&foo.b=B&foo.c=C. +// There are exceptions: +// - for wrapper types it will use the same representation as the wrapped primitive type in JSON +// - for google.protobuf.timestamp type it will be serialized as a string // // maps, Struct and Empty can NOT be used // messages can have any number of sub messages - including circular (e.g. sub.subsub.sub.subsub.id) @@ -288,7 +287,7 @@ func (g *OpenAPIv3Generator) _buildQueryParamsV3(field *protogen.Field, depths m parameters := []*v3.ParameterOrReference{} queryFieldName := g.reflect.formatFieldName(field.Desc) - fieldDescription := g.filterCommentString(field.Comments.Leading, true) + fieldDescription := g.filterCommentString(field.Comments.Leading) if field.Desc.IsMap() { // Map types are not allowed in query parameteres @@ -297,7 +296,8 @@ func (g *OpenAPIv3Generator) _buildQueryParamsV3(field *protogen.Field, depths m } else if field.Desc.Kind() == protoreflect.MessageKind { typeName := g.reflect.fullMessageTypeName(field.Desc.Message()) - if typeName == ".google.protobuf.Value" { + switch typeName { + case ".google.protobuf.Value": fieldSchema := g.reflect.schemaOrReferenceForField(field.Desc) parameters = append(parameters, &v3.ParameterOrReference{ @@ -312,7 +312,44 @@ func (g *OpenAPIv3Generator) _buildQueryParamsV3(field *protogen.Field, depths m }, }) return parameters - } else if field.Desc.IsList() { + + case ".google.protobuf.BoolValue", ".google.protobuf.BytesValue", ".google.protobuf.Int32Value", ".google.protobuf.UInt32Value", + ".google.protobuf.StringValue", ".google.protobuf.Int64Value", ".google.protobuf.UInt64Value", ".google.protobuf.FloatValue", + ".google.protobuf.DoubleValue": + valueField := getValueField(field.Message.Desc) + fieldSchema := g.reflect.schemaOrReferenceForField(valueField) + parameters = append(parameters, + &v3.ParameterOrReference{ + Oneof: &v3.ParameterOrReference_Parameter{ + Parameter: &v3.Parameter{ + Name: queryFieldName, + In: "query", + Description: fieldDescription, + Required: false, + Schema: fieldSchema, + }, + }, + }) + return parameters + + case ".google.protobuf.Timestamp": + fieldSchema := g.reflect.schemaOrReferenceForMessage(field.Message.Desc) + parameters = append(parameters, + &v3.ParameterOrReference{ + Oneof: &v3.ParameterOrReference_Parameter{ + Parameter: &v3.Parameter{ + Name: queryFieldName, + In: "query", + Description: fieldDescription, + Required: false, + Schema: fieldSchema, + }, + }, + }) + return parameters + } + + if field.Desc.IsList() { // Only non-repeated message types are valid return parameters } @@ -412,7 +449,7 @@ func (g *OpenAPIv3Generator) buildOperationV3( field := g.findField(pathParameter, inputMessage) if field != nil { fieldSchema = g.reflect.schemaOrReferenceForField(field.Desc) - fieldDescription = g.filterCommentString(field.Comments.Leading, true) + fieldDescription = g.filterCommentString(field.Comments.Leading) } else { // If field does not exist, it is safe to set it to string, as it is ignored downstream fieldSchema = &v3.SchemaOrReference{ @@ -647,20 +684,27 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr annotationsCount := 0 for _, method := range service.Methods { - comment := g.filterCommentString(method.Comments.Leading, false) + comment := g.filterCommentString(method.Comments.Leading) inputMessage := method.Input outputMessage := method.Output operationID := service.GoName + "_" + method.GoName - var path string - var methodName string - var body string + rules := make([]*annotations.HttpRule, 0) extHTTP := proto.GetExtension(method.Desc.Options(), annotations.E_Http) if extHTTP != nil && extHTTP != annotations.E_Http.InterfaceOf(annotations.E_Http.Zero()) { annotationsCount++ rule := extHTTP.(*annotations.HttpRule) + rules = append(rules, rule) + rules = append(rules, rule.AdditionalBindings...) + } + + for _, rule := range rules { + var path string + var methodName string + var body string + body = rule.Body switch pattern := rule.Pattern.(type) { case *annotations.HttpRule_Get: @@ -683,26 +727,26 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr default: path = "unknown-unsupported" } - } - if methodName != "" { - defaultHost := proto.GetExtension(service.Desc.Options(), annotations.E_DefaultHost).(string) + if methodName != "" { + defaultHost := proto.GetExtension(service.Desc.Options(), annotations.E_DefaultHost).(string) - op, path2 := g.buildOperationV3( - d, operationID, service.GoName, comment, defaultHost, path, body, inputMessage, outputMessage) + op, path2 := g.buildOperationV3( + d, operationID, service.GoName, comment, defaultHost, path, body, inputMessage, outputMessage) - // Merge any `Operation` annotations with the current - extOperation := proto.GetExtension(method.Desc.Options(), v3.E_Operation) - if extOperation != nil { - proto.Merge(op, extOperation.(*v3.Operation)) - } + // Merge any `Operation` annotations with the current + extOperation := proto.GetExtension(method.Desc.Options(), v3.E_Operation) + if extOperation != nil { + proto.Merge(op, extOperation.(*v3.Operation)) + } - g.addOperationToDocumentV3(d, op, path2, methodName) + g.addOperationToDocumentV3(d, op, path2, methodName) + } } } if annotationsCount > 0 { - comment := g.filterCommentString(service.Comments.Leading, false) + comment := g.filterCommentString(service.Comments.Leading) d.Tags = append(d.Tags, &v3.Tag{Name: service.GoName, Description: comment}) } } @@ -734,7 +778,7 @@ func (g *OpenAPIv3Generator) addSchemasForMessagesToDocumentV3(d *v3.Document, m } typeName := g.reflect.fullMessageTypeName(message.Desc) - messageDescription := g.filterCommentString(message.Comments.Leading, true) + messageDescription := g.filterCommentString(message.Comments.Leading) // `google.protobuf.Value` and `google.protobuf.Any` have special JSON transcoding // so we can't just reflect on the message descriptor. @@ -759,7 +803,7 @@ func (g *OpenAPIv3Generator) addSchemasForMessagesToDocumentV3(d *v3.Document, m var required []string for _, field := range message.Fields { // Get the field description from the comments. - description := g.filterCommentString(field.Comments.Leading, true) + description := g.filterCommentString(field.Comments.Leading) // Check the field annotations to see if this is a readonly or writeonly field. inputOnly := false outputOnly := false diff --git a/cmd/protoc-gen-openapi/generator/reflector.go b/cmd/protoc-gen-openapi/generator/reflector.go index 87d18cc9..97754f4e 100644 --- a/cmd/protoc-gen-openapi/generator/reflector.go +++ b/cmd/protoc-gen-openapi/generator/reflector.go @@ -126,6 +126,7 @@ func (r *OpenAPIv3Reflector) schemaReferenceForMessage(message protoreflect.Mess // the definition in `#/components/schemas/` func (r *OpenAPIv3Reflector) schemaOrReferenceForMessage(message protoreflect.MessageDescriptor) *v3.SchemaOrReference { typeName := r.fullMessageTypeName(message) + switch typeName { case ".google.api.HttpBody": @@ -150,6 +151,21 @@ func (r *OpenAPIv3Reflector) schemaOrReferenceForMessage(message protoreflect.Me // Empty is closer to JSON undefined than null, so ignore this field return nil //&v3.SchemaOrReference{Oneof: &v3.SchemaOrReference_Schema{Schema: &v3.Schema{Type: "null"}}} + case ".google.protobuf.BoolValue": + return wk.NewBooleanSchema() + + case ".google.protobuf.BytesValue": + return wk.NewBytesSchema() + + case ".google.protobuf.Int32Value", ".google.protobuf.UInt32Value": + return wk.NewIntegerSchema(getValueKind(message)) + + case ".google.protobuf.StringValue", ".google.protobuf.Int64Value", ".google.protobuf.UInt64Value": + return wk.NewStringSchema() + + case ".google.protobuf.FloatValue", ".google.protobuf.DoubleValue": + return wk.NewNumberSchema(getValueKind(message)) + default: ref := r.schemaReferenceForMessage(message) return &v3.SchemaOrReference{ diff --git a/cmd/protoc-gen-openapi/generator/utils.go b/cmd/protoc-gen-openapi/generator/utils.go index 35671289..ca7d47dd 100644 --- a/cmd/protoc-gen-openapi/generator/utils.go +++ b/cmd/protoc-gen-openapi/generator/utils.go @@ -17,6 +17,8 @@ package generator import ( "strings" + + "google.golang.org/protobuf/reflect/protoreflect" ) // contains returns true if an array contains a specified string. @@ -50,3 +52,13 @@ func singular(plural string) string { } return plural } + +func getValueKind(message protoreflect.MessageDescriptor) string { + valueField := getValueField(message) + return valueField.Kind().String() +} + +func getValueField(message protoreflect.MessageDescriptor) protoreflect.FieldDescriptor { + fields := message.Fields() + return fields.ByName("value") +} diff --git a/cmd/protoc-gen-openapi/plugin_test.go b/cmd/protoc-gen-openapi/plugin_test.go index 0c41d903..865cfc26 100644 --- a/cmd/protoc-gen-openapi/plugin_test.go +++ b/cmd/protoc-gen-openapi/plugin_test.go @@ -39,6 +39,7 @@ var openapiTests = []struct { {name: "Enum Options", path: "examples/tests/enumoptions/", protofile: "message.proto"}, {name: "OpenAPIv3 Annotations", path: "examples/tests/openapiv3annotations/", protofile: "message.proto"}, {name: "AllOf Wrap Message", path: "examples/tests/allofwrap/", protofile: "message.proto"}, + {name: "Additional Bindings", path: "examples/tests/additional_bindings/", protofile: "message.proto"}, } // Set this to true to generate/overwrite the fixtures. Make sure you set it back diff --git a/discovery/discovery.pb.go b/discovery/discovery.pb.go index d78acddd..5f56a746 100644 --- a/discovery/discovery.pb.go +++ b/discovery/discovery.pb.go @@ -16,8 +16,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 -// protoc v3.18.1 +// protoc-gen-go v1.28.1 +// protoc v3.21.12 // source: discovery/discovery.proto package discovery_v1 diff --git a/extensions/extension.pb.go b/extensions/extension.pb.go index a6a4ccca..66af9542 100644 --- a/extensions/extension.pb.go +++ b/extensions/extension.pb.go @@ -14,8 +14,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 -// protoc v3.18.1 +// protoc-gen-go v1.28.1 +// protoc v3.21.12 // source: extensions/extension.proto package gnostic_extension_v1 diff --git a/go.mod b/go.mod index 3dd1b50c..c05eb264 100644 --- a/go.mod +++ b/go.mod @@ -12,5 +12,5 @@ require ( google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 google.golang.org/protobuf v1.27.1 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 - gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 + gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 3a2f623c..9afc9993 100644 --- a/go.sum +++ b/go.sum @@ -152,7 +152,7 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/metrics/complexity.pb.go b/metrics/complexity.pb.go index 9717f7af..7c5a5c32 100644 --- a/metrics/complexity.pb.go +++ b/metrics/complexity.pb.go @@ -14,8 +14,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 -// protoc v3.18.1 +// protoc-gen-go v1.28.1 +// protoc v3.21.12 // source: metrics/complexity.proto package gnostic_metrics_v1 diff --git a/metrics/vocabulary.pb.go b/metrics/vocabulary.pb.go index 2b780ce3..25e593ae 100644 --- a/metrics/vocabulary.pb.go +++ b/metrics/vocabulary.pb.go @@ -14,8 +14,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 -// protoc v3.18.1 +// protoc-gen-go v1.28.1 +// protoc v3.21.12 // source: metrics/vocabulary.proto package gnostic_metrics_v1 diff --git a/openapiv2/OpenAPIv2.pb.go b/openapiv2/OpenAPIv2.pb.go index 06b60157..29848110 100644 --- a/openapiv2/OpenAPIv2.pb.go +++ b/openapiv2/OpenAPIv2.pb.go @@ -16,8 +16,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 -// protoc v3.18.1 +// protoc-gen-go v1.28.1 +// protoc v3.21.12 // source: openapiv2/OpenAPIv2.proto package openapi_v2 @@ -43,6 +43,7 @@ type AdditionalPropertiesItem struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *AdditionalPropertiesItem_Schema // *AdditionalPropertiesItem_Boolean Oneof isAdditionalPropertiesItem_Oneof `protobuf_oneof:"oneof"` @@ -2517,6 +2518,7 @@ type NonBodyParameter struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *NonBodyParameter_HeaderParameterSubSchema // *NonBodyParameter_FormDataParameterSubSchema // *NonBodyParameter_QueryParameterSubSchema @@ -3178,6 +3180,7 @@ type Parameter struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *Parameter_BodyParameter // *Parameter_NonBodyParameter Oneof isParameter_Oneof `protobuf_oneof:"oneof"` @@ -3306,6 +3309,7 @@ type ParametersItem struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *ParametersItem_Parameter // *ParametersItem_JsonReference Oneof isParametersItem_Oneof `protobuf_oneof:"oneof"` @@ -4366,6 +4370,7 @@ type ResponseValue struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *ResponseValue_Response // *ResponseValue_JsonReference Oneof isResponseValue_Oneof `protobuf_oneof:"oneof"` @@ -4790,6 +4795,7 @@ type SchemaItem struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *SchemaItem_Schema // *SchemaItem_FileSchema Oneof isSchemaItem_Oneof `protobuf_oneof:"oneof"` @@ -4917,6 +4923,7 @@ type SecurityDefinitionsItem struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *SecurityDefinitionsItem_BasicAuthenticationSecurity // *SecurityDefinitionsItem_ApiKeySecurity // *SecurityDefinitionsItem_Oauth2ImplicitSecurity diff --git a/openapiv3/OpenAPIv3.pb.go b/openapiv3/OpenAPIv3.pb.go index 90a56f55..d1c4ed81 100644 --- a/openapiv3/OpenAPIv3.pb.go +++ b/openapiv3/OpenAPIv3.pb.go @@ -16,8 +16,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.0 -// protoc v3.19.4 +// protoc-gen-go v1.28.1 +// protoc v3.21.12 // source: openapiv3/OpenAPIv3.proto package openapi_v3 @@ -43,6 +43,7 @@ type AdditionalPropertiesItem struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *AdditionalPropertiesItem_SchemaOrReference // *AdditionalPropertiesItem_Boolean Oneof isAdditionalPropertiesItem_Oneof `protobuf_oneof:"oneof"` @@ -178,6 +179,7 @@ type AnyOrExpression struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *AnyOrExpression_Any // *AnyOrExpression_Expression Oneof isAnyOrExpression_Oneof `protobuf_oneof:"oneof"` @@ -314,6 +316,7 @@ type CallbackOrReference struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *CallbackOrReference_Callback // *CallbackOrReference_Reference Oneof isCallbackOrReference_Oneof `protobuf_oneof:"oneof"` @@ -633,6 +636,7 @@ type DefaultType struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *DefaultType_Number // *DefaultType_Boolean // *DefaultType_String_ @@ -1116,6 +1120,7 @@ type ExampleOrReference struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *ExampleOrReference_Example // *ExampleOrReference_Reference Oneof isExampleOrReference_Oneof `protobuf_oneof:"oneof"` @@ -1490,6 +1495,7 @@ type HeaderOrReference struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *HeaderOrReference_Header // *HeaderOrReference_Reference Oneof isHeaderOrReference_Oneof `protobuf_oneof:"oneof"` @@ -1928,6 +1934,7 @@ type LinkOrReference struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *LinkOrReference_Link // *LinkOrReference_Reference Oneof isLinkOrReference_Oneof `protobuf_oneof:"oneof"` @@ -3613,6 +3620,7 @@ type ParameterOrReference struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *ParameterOrReference_Parameter // *ParameterOrReference_Reference Oneof isParameterOrReference_Oneof `protobuf_oneof:"oneof"` @@ -4178,6 +4186,7 @@ type RequestBodyOrReference struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *RequestBodyOrReference_RequestBody // *RequestBodyOrReference_Reference Oneof isRequestBodyOrReference_Oneof `protobuf_oneof:"oneof"` @@ -4338,6 +4347,7 @@ type ResponseOrReference struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *ResponseOrReference_Response // *ResponseOrReference_Reference Oneof isResponseOrReference_Oneof `protobuf_oneof:"oneof"` @@ -4857,6 +4867,7 @@ type SchemaOrReference struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *SchemaOrReference_Schema // *SchemaOrReference_Reference Oneof isSchemaOrReference_Oneof `protobuf_oneof:"oneof"` @@ -5144,6 +5155,7 @@ type SecuritySchemeOrReference struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *SecuritySchemeOrReference_SecurityScheme // *SecuritySchemeOrReference_Reference Oneof isSecuritySchemeOrReference_Oneof `protobuf_oneof:"oneof"` @@ -5463,6 +5475,7 @@ type SpecificationExtension struct { unknownFields protoimpl.UnknownFields // Types that are assignable to Oneof: + // // *SpecificationExtension_Number // *SpecificationExtension_Boolean // *SpecificationExtension_String_ diff --git a/openapiv3/annotations.pb.go b/openapiv3/annotations.pb.go index ae242f30..872b2595 100644 --- a/openapiv3/annotations.pb.go +++ b/openapiv3/annotations.pb.go @@ -14,8 +14,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.0 -// protoc v3.19.4 +// protoc-gen-go v1.28.1 +// protoc v3.21.12 // source: openapiv3/annotations.proto package openapi_v3 diff --git a/plugins/plugin.pb.go b/plugins/plugin.pb.go index 5e521cc4..ba8a0afb 100644 --- a/plugins/plugin.pb.go +++ b/plugins/plugin.pb.go @@ -22,8 +22,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 -// protoc v3.19.4 +// protoc-gen-go v1.28.1 +// protoc v3.21.12 // source: plugins/plugin.proto package gnostic_plugin_v1 diff --git a/surface/surface.pb.go b/surface/surface.pb.go index 932e15f9..6c827ce2 100644 --- a/surface/surface.pb.go +++ b/surface/surface.pb.go @@ -16,8 +16,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 -// protoc v3.18.1 +// protoc-gen-go v1.28.1 +// protoc v3.21.12 // source: surface/surface.proto package surface_v1