Skip to content

Commit

Permalink
protoc-gen-jsonschema: Handle google.protobuf.Value (#302)
Browse files Browse the repository at this point in the history
* protoc-gen-jsonschema: Share type and format values

* protoc-gen-jsonschema: Handle google.protobuf.Value

+ add protobuf type tests from protoc-gen-openapi

* protoc-gen-openapi: fix info URL

* Fix info URL in tests as well
  • Loading branch information
morphar authored Feb 4, 2022
1 parent 8f951e5 commit 0d229df
Show file tree
Hide file tree
Showing 35 changed files with 1,229 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2021 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.protobuftypes.message.v1;

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

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

service Messaging {
option (google.api.default_host) = "foo.googleapi.com";
rpc CreateMessage(Message) returns (Message) {
option (google.api.http) = {
post : "/v1/messages/{message_id}"
body : "*"
};
}
rpc ListMessages(google.protobuf.Empty) returns (google.protobuf.Value) {
option (google.api.http) = {
get : "/v1/messages"
};
}
rpc GetMessage(Message) returns (Message) {
option (google.api.http) = {
get : "/v1/messages/{message_id}"
};
}
rpc UpdateMessage(Message) returns (google.protobuf.Struct) {
option (google.api.http) = {
patch : "/v1/messages/{message_id}"
body : "body"
};
}
}

message RecursiveParent {
int32 parent_id = 1;
RecursiveChild child = 2;
}
message RecursiveChild {
int32 child_id = 1;
RecursiveParent parent = 2;
}

message SubMessage {
string message_id = 1;
SubSubMessage sub_sub_message = 2;
}

message SubSubMessage {
string message_id = 1;
repeated int32 integers = 2;
}

message Message {
message EmbMessage { string message_id = 1; }
string message_id = 1;
string string_type = 2;
RecursiveParent recursive_type = 3;
EmbMessage embedded_type = 4;
SubMessage sub_type = 5;
repeated string repeated_type = 6;
repeated SubMessage repeated_sub_type = 7;
repeated RecursiveParent repeated_recursive_type = 8;
map<string, string> map_type = 9;
google.protobuf.Struct body = 10;
repeated google.protobuf.Struct media = 11;
google.protobuf.Empty not_used = 12;
// Description of value
google.protobuf.Value value_type = 13;
// Description of repeated value
repeated google.protobuf.Value repeated_value_type = 14;
}
303 changes: 303 additions & 0 deletions cmd/protoc-gen-jsonschema/examples/tests/protobuftypes/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
# 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
servers:
- url: https://foo.googleapi.com
paths:
/v1/messages:
get:
tags:
- Messaging
operationId: Messaging_ListMessages
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/AnyJSONValue'
/v1/messages/{message_id}:
get:
tags:
- Messaging
operationId: Messaging_GetMessage
parameters:
- name: message_id
in: path
required: true
schema:
type: string
- name: string_type
in: query
schema:
type: string
- name: recursive_type.parent_id
in: query
schema:
type: integer
format: int32
- name: recursive_type.child.child_id
in: query
schema:
type: integer
format: int32
- name: recursive_type.child.parent.parent_id
in: query
schema:
type: integer
format: int32
- name: recursive_type.child.parent.child.child_id
in: query
schema:
type: integer
format: int32
- name: embedded_type.message_id
in: query
schema:
type: string
- name: sub_type.message_id
in: query
schema:
type: string
- name: sub_type.sub_sub_message.message_id
in: query
schema:
type: string
- name: sub_type.sub_sub_message.integers
in: query
schema:
type: array
items:
type: integer
format: int32
- name: repeated_type
in: query
schema:
type: array
items:
type: string
- name: value_type
in: query
description: Description of value
schema:
$ref: '#/components/schemas/AnyJSONValue'
- name: repeated_value_type
in: query
description: Description of repeated value
schema:
type: array
items:
$ref: '#/components/schemas/AnyJSONValue'
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Message'
post:
tags:
- Messaging
operationId: Messaging_CreateMessage
parameters:
- name: message_id
in: path
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Message'
required: true
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Message'
patch:
tags:
- Messaging
operationId: Messaging_UpdateMessage
parameters:
- name: message_id
in: path
required: true
schema:
type: string
- name: string_type
in: query
schema:
type: string
- name: recursive_type.parent_id
in: query
schema:
type: integer
format: int32
- name: recursive_type.child.child_id
in: query
schema:
type: integer
format: int32
- name: recursive_type.child.parent.parent_id
in: query
schema:
type: integer
format: int32
- name: recursive_type.child.parent.child.child_id
in: query
schema:
type: integer
format: int32
- name: embedded_type.message_id
in: query
schema:
type: string
- name: sub_type.message_id
in: query
schema:
type: string
- name: sub_type.sub_sub_message.message_id
in: query
schema:
type: string
- name: sub_type.sub_sub_message.integers
in: query
schema:
type: array
items:
type: integer
format: int32
- name: repeated_type
in: query
schema:
type: array
items:
type: string
- name: value_type
in: query
description: Description of value
schema:
$ref: '#/components/schemas/AnyJSONValue'
- name: repeated_value_type
in: query
description: Description of repeated value
schema:
type: array
items:
$ref: '#/components/schemas/AnyJSONValue'
requestBody:
content:
application/json:
schema:
type: object
required: true
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
components:
schemas:
AnyJSONValue:
oneOf:
- type: string
- type: number
- type: integer
- type: boolean
- type: object
- type: array
items:
$ref: '#/components/schemas/AnyJSONValue'
description: AnyJSONValue is a "catch all" type that can hold any JSON value, except null as this is not allowed in OpenAPI
Message:
type: object
properties:
message_id:
type: string
string_type:
type: string
recursive_type:
$ref: '#/components/schemas/RecursiveParent'
embedded_type:
$ref: '#/components/schemas/Message_EmbMessage'
sub_type:
$ref: '#/components/schemas/SubMessage'
repeated_type:
type: array
items:
type: string
repeated_sub_type:
type: array
items:
$ref: '#/components/schemas/SubMessage'
repeated_recursive_type:
type: array
items:
$ref: '#/components/schemas/RecursiveParent'
map_type:
type: object
additionalProperties:
type: string
body:
type: object
media:
type: array
items:
type: object
value_type:
$ref: '#/components/schemas/AnyJSONValue'
repeated_value_type:
type: array
items:
$ref: '#/components/schemas/AnyJSONValue'
description: Description of repeated value
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
integers:
type: array
items:
type: integer
format: int32
tags:
- name: Messaging
Loading

0 comments on commit 0d229df

Please sign in to comment.