Skip to content

Commit

Permalink
protoc-gen-openapi: Convert maps and lists of sub messages (#271)
Browse files Browse the repository at this point in the history
* protoc-gen-openapi: Convert maps and lists of sub messages

This ensures proper conversion of maps and lists of standard types, (some) google.protobuf types and sub messages.

* Fix map types

Map types are now expressed as type object with no properties and a schema on additionalProperties.

* Add support for nested protobuf message definitions (protoc-gen-openapi)

Co-authored-by: Tim Burks <timburks@google.com>
  • Loading branch information
morphar and timburks authored Nov 28, 2021
1 parent 6215ae6 commit 6c71457
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 164 deletions.
14 changes: 13 additions & 1 deletion apps/protoc-gen-openapi/examples/tests/mapfields/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ syntax = "proto3";
package tests.mapfields.message.v1;

import "google/api/annotations.proto";
import "google/protobuf/struct.proto";

option go_package = "github.com/google/gnostic/apps/protoc-gen-openapi/examples/tests/mapfields/message/v1;message";

Expand All @@ -29,7 +30,18 @@ service Messaging {
};
}
}

message Message {
message SubMessage {
int64 id = 1;
string label = 2;
}
string message_id = 1;
map<string, string> labels = 2;
SubMessage sub_message = 2;
repeated string string_list = 3;
repeated SubMessage sub_message_list = 4;
repeated google.protobuf.Struct object_list = 5;
map<string, string> strings_map = 6;
map<string, SubMessage> sub_messages_map = 7;
map<string, google.protobuf.Struct> objects_map = 8;
}
33 changes: 32 additions & 1 deletion apps/protoc-gen-openapi/examples/tests/mapfields/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,38 @@ components:
properties:
message_id:
type: string
labels:
sub_message:
$ref: '#/components/schemas/SubMessage'
string_list:
type: array
items:
type: string
sub_message_list:
type: array
items:
$ref: '#/components/schemas/SubMessage'
object_list:
type: array
items:
type: object
strings_map:
type: object
additionalProperties:
type: string
sub_messages_map:
type: object
additionalProperties:
$ref: '#/components/schemas/SubMessage'
objects_map:
type: object
additionalProperties:
type: object
SubMessage:
properties:
id:
type: integer
format: int64
label:
type: string
tags:
- name: Messaging
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,38 @@ components:
properties:
messageId:
type: string
labels:
subMessage:
$ref: '#/components/schemas/SubMessage'
stringList:
type: array
items:
type: string
subMessageList:
type: array
items:
$ref: '#/components/schemas/SubMessage'
objectList:
type: array
items:
type: object
stringsMap:
type: object
additionalProperties:
type: string
subMessagesMap:
type: object
additionalProperties:
$ref: '#/components/schemas/SubMessage'
objectsMap:
type: object
additionalProperties:
type: object
SubMessage:
properties:
id:
type: integer
format: int64
label:
type: string
tags:
- name: Messaging
Loading

0 comments on commit 6c71457

Please sign in to comment.