Skip to content

Commit

Permalink
protoc-gen-openapi: Add type to schema objects (#282)
Browse files Browse the repository at this point in the history
All schemas defined in "components" will now have "type" set to "object".
  • Loading branch information
morphar authored Jan 6, 2022
1 parent 7f9a651 commit ba78c7c
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ components:
Book:
required:
- name
type: object
properties:
name:
type: string
Expand Down Expand Up @@ -346,6 +347,7 @@ components:
format: date-time
description: A single book in the library.
ListBooksResponse:
type: object
properties:
books:
type: array
Expand All @@ -357,6 +359,7 @@ components:
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
properties:
shelves:
type: array
Expand All @@ -371,6 +374,7 @@ components:
required:
- name
- other_shelf_name
type: object
properties:
name:
type: string
Expand All @@ -383,6 +387,7 @@ components:
required:
- name
- other_shelf_name
type: object
properties:
name:
type: string
Expand All @@ -394,6 +399,7 @@ components:
Shelf:
required:
- name
type: object
properties:
name:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ components:
Book:
required:
- name
type: object
properties:
name:
type: string
Expand Down Expand Up @@ -346,6 +347,7 @@ components:
format: date-time
description: A single book in the library.
ListBooksResponse:
type: object
properties:
books:
type: array
Expand All @@ -357,6 +359,7 @@ components:
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
properties:
shelves:
type: array
Expand All @@ -371,6 +374,7 @@ components:
required:
- name
- otherShelfName
type: object
properties:
name:
type: string
Expand All @@ -383,6 +387,7 @@ components:
required:
- name
- otherShelfName
type: object
properties:
name:
type: string
Expand All @@ -394,6 +399,7 @@ components:
Shelf:
required:
- name
type: object
properties:
name:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ paths:
components:
schemas:
Message:
type: object
properties:
message_id:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ paths:
components:
schemas:
Message:
type: object
properties:
messageId:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ paths:
components:
schemas:
Message:
type: object
properties:
message_id:
type: string
Expand All @@ -73,6 +74,7 @@ components:
not_used:
type: string
Message2:
type: object
properties:
message_id:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ paths:
components:
schemas:
Message:
type: object
properties:
messageId:
type: string
Expand All @@ -74,6 +75,7 @@ components:
notUsed:
type: string
Message2:
type: object
properties:
message_id:
type: string
Expand Down
3 changes: 3 additions & 0 deletions apps/protoc-gen-openapi/examples/tests/mapfields/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ paths:
components:
schemas:
AnotherMessage:
type: object
properties:
id:
type: integer
format: int64
label:
type: string
Message:
type: object
properties:
message_id:
type: string
Expand Down Expand Up @@ -72,6 +74,7 @@ components:
additionalProperties:
type: object
Message_SubMessage:
type: object
properties:
id:
type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ paths:
components:
schemas:
AnotherMessage:
type: object
properties:
id:
type: integer
format: int64
label:
type: string
Message:
type: object
properties:
messageId:
type: string
Expand Down Expand Up @@ -72,6 +74,7 @@ components:
additionalProperties:
type: object
Message_SubMessage:
type: object
properties:
id:
type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ paths:
components:
schemas:
Message:
type: object
properties:
id:
type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ paths:
components:
schemas:
Message:
type: object
properties:
id:
type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ paths:
components:
schemas:
Message:
type: object
properties:
message_id:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ paths:
components:
schemas:
Message:
type: object
properties:
messageId:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ paths:
components:
schemas:
Message:
type: object
properties:
message_id:
type: string
Expand Down Expand Up @@ -204,30 +205,35 @@ components:
items:
type: object
Message_EmbMessage:
type: object
properties:
message_id:
type: string
RecursiveChild:
type: object
properties:
child_id:
type: integer
format: int32
parent:
$ref: '#/components/schemas/RecursiveParent'
RecursiveParent:
type: object
properties:
parent_id:
type: integer
format: int32
child:
$ref: '#/components/schemas/RecursiveChild'
SubMessage:
type: object
properties:
message_id:
type: string
sub_sub_message:
$ref: '#/components/schemas/SubSubMessage'
SubSubMessage:
type: object
properties:
message_id:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ paths:
components:
schemas:
Message:
type: object
properties:
messageId:
type: string
Expand Down Expand Up @@ -204,30 +205,35 @@ components:
items:
type: object
Message_EmbMessage:
type: object
properties:
messageId:
type: string
RecursiveChild:
type: object
properties:
childId:
type: integer
format: int32
parent:
$ref: '#/components/schemas/RecursiveParent'
RecursiveParent:
type: object
properties:
parentId:
type: integer
format: int32
child:
$ref: '#/components/schemas/RecursiveChild'
SubMessage:
type: object
properties:
messageId:
type: string
subSubMessage:
$ref: '#/components/schemas/SubSubMessage'
SubSubMessage:
type: object
properties:
messageId:
type: string
Expand Down
1 change: 1 addition & 0 deletions apps/protoc-gen-openapi/generator/openapi-v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ func (g *OpenAPIv3Generator) addSchemasToDocumentV3(d *v3.Document, messages []*
Value: &v3.SchemaOrReference{
Oneof: &v3.SchemaOrReference_Schema{
Schema: &v3.Schema{
Type: "object",
Description: messageDescription,
Properties: definitionProperties,
Required: required,
Expand Down

0 comments on commit ba78c7c

Please sign in to comment.