From 3751138311725a0e9d353b805b2e121c94155d18 Mon Sep 17 00:00:00 2001 From: Tim Burks Date: Fri, 2 Dec 2022 07:55:38 -0800 Subject: [PATCH 1/3] Update CI to run on "main" branch. (#371) --- .github/workflows/go.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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: From 9ddb282af5d42bda235570ee5020eaa11e6afb24 Mon Sep 17 00:00:00 2001 From: Ajay Kemparaj Date: Tue, 21 Feb 2023 08:27:37 -0800 Subject: [PATCH 2/3] chore: yaml bump and protoc move to google.golang.org (#377) --- COMPILE-PROTOS.sh | 2 +- discovery/discovery.pb.go | 4 ++-- extensions/extension.pb.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- metrics/complexity.pb.go | 4 ++-- metrics/vocabulary.pb.go | 4 ++-- openapiv2/OpenAPIv2.pb.go | 11 +++++++++-- openapiv3/OpenAPIv3.pb.go | 17 +++++++++++++++-- openapiv3/annotations.pb.go | 4 ++-- plugins/plugin.pb.go | 4 ++-- surface/surface.pb.go | 4 ++-- 12 files changed, 42 insertions(+), 22 deletions(-) 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/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 From 8c84f3c81114a94a9bf860ea9d63413a4c959a3b Mon Sep 17 00:00:00 2001 From: Silas Sewell Date: Fri, 24 Mar 2023 11:15:44 -0400 Subject: [PATCH 3/3] Don't remove newlines from openapi descriptions (#370) --- .../google/example/library/v1/openapi.yaml | 52 +++++++++++++++---- .../library/v1/openapi_default_response.yaml | 52 +++++++++++++++---- .../library/v1/openapi_fq_schema_naming.yaml | 52 +++++++++++++++---- .../example/library/v1/openapi_json.yaml | 52 +++++++++++++++---- .../library/v1/openapi_string_enum.yaml | 52 +++++++++++++++---- cmd/protoc-gen-openapi/generator/generator.go | 22 ++++---- 6 files changed, 219 insertions(+), 63 deletions(-) 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/generator/generator.go b/cmd/protoc-gen-openapi/generator/generator.go index 686eed50..bce4e28b 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) } @@ -288,7 +284,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 @@ -412,7 +408,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,7 +643,7 @@ 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 @@ -709,7 +705,7 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr } 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}) } } @@ -741,7 +737,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. @@ -766,7 +762,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