Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field and schema extensions #2418

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/docs/mapping/customizing_openapi_output.md
Expand Up @@ -39,6 +39,12 @@ message ABitOfEverything {
description: "Find out more about ABitOfEverything";
}
example: "{\"uuid\": \"0cf361e1-4b44-483d-a159-54dabdf7e814\"}"
extensions: {
key: "x-irreversible";
value {
bool_value: true;
}
}
};

string uuid = 1 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {description: "The UUID field."}];
Expand Down Expand Up @@ -78,6 +84,29 @@ service ABitOfEverythingService {
}
```

[Swagger Extensions](https://swagger.io/docs/specification/2-0/swagger-extensions/) can be added as key-value pairs to the options. Keys must begin with `x-` and values can be of any type listed [here](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#value). For example:
```
extensions: {
key: "x-amazon-apigateway-authorizer";
value {
struct_value {
fields {
key: "type";
value {
string_value: "token";
}
}
fields {
key: "authorizerResultTtlInSeconds";
value {
number_value: 60;
}
}
}
}
}
```

Please see this [a_bit_of_everything.proto](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/examples/internal/proto/examplepb/a_bit_of_everything.proto) for examples of the options being used.

## Using google.api.field_behavior
Expand Down
16 changes: 16 additions & 0 deletions examples/internal/clients/abe/api/swagger.yaml
Expand Up @@ -159,6 +159,7 @@ paths:
required: false
type: "string"
pattern: "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"
x-internal: true
x-exportParamName: "Uuid"
x-optionalDataType: "String"
- name: "floatValue"
Expand Down Expand Up @@ -472,6 +473,7 @@ paths:
required: false
type: "string"
pattern: "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"
x-internal: true
x-exportParamName: "Uuid"
x-optionalDataType: "String"
- name: "floatValue"
Expand Down Expand Up @@ -776,6 +778,7 @@ paths:
required: false
type: "string"
pattern: "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"
x-internal: true
x-exportParamName: "Uuid"
x-optionalDataType: "String"
- name: "floatValue"
Expand Down Expand Up @@ -1069,6 +1072,7 @@ paths:
in: "path"
required: true
type: "string"
x-internal: true
x-exportParamName: "UuidName"
- name: "singleNested.name"
in: "query"
Expand Down Expand Up @@ -1549,6 +1553,7 @@ paths:
required: false
type: "string"
pattern: "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"
x-internal: true
x-exportParamName: "Uuid"
x-optionalDataType: "String"
- name: "bytesValue"
Expand Down Expand Up @@ -1702,6 +1707,7 @@ paths:
in: "path"
required: true
type: "string"
x-internal: true
x-exportParamName: "UuidName"
- in: "body"
name: "body"
Expand Down Expand Up @@ -2211,6 +2217,7 @@ paths:
in: "path"
required: true
type: "string"
x-internal: true
x-exportParamName: "UuidName"
- in: "body"
name: "abe"
Expand Down Expand Up @@ -2261,6 +2268,7 @@ paths:
in: "path"
required: true
type: "string"
x-internal: true
x-exportParamName: "UuidName"
- in: "body"
name: "abe"
Expand Down Expand Up @@ -2661,6 +2669,7 @@ paths:
in: "path"
required: true
type: "string"
x-internal: true
x-exportParamName: "UuidName"
- in: "body"
name: "body"
Expand Down Expand Up @@ -2798,6 +2807,7 @@ definitions:
type: "string"
minLength: 1
pattern: "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"
x-internal: true
nested:
type: "array"
items:
Expand Down Expand Up @@ -2932,6 +2942,7 @@ definitions:
example:
int64_value: 12
double_value: 12.3
x-a-bit-of-everything-foo: "bar"
examplepbABitOfEverythingRepeated:
type: "object"
properties:
Expand Down Expand Up @@ -3337,6 +3348,7 @@ definitions:
example:
int64_value: 12
double_value: 12.3
x-a-bit-of-everything-foo: "bar"
v1exampledeep_pathsingleNested.name_singleNested:
properties:
amount:
Expand All @@ -3362,6 +3374,7 @@ definitions:
type: "string"
minLength: 1
pattern: "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"
x-internal: true
nested:
type: "array"
items:
Expand Down Expand Up @@ -3496,6 +3509,7 @@ definitions:
example:
int64_value: 12
double_value: 12.3
x-a-bit-of-everything-foo: "bar"
The book to update.:
type: "object"
properties:
Expand Down Expand Up @@ -3655,6 +3669,7 @@ definitions:
example:
int64_value: 12
double_value: 12.3
x-a-bit-of-everything-foo: "bar"
A bit of everything_3:
type: "object"
required:
Expand Down Expand Up @@ -3799,6 +3814,7 @@ definitions:
example:
int64_value: 12
double_value: 12.3
x-a-bit-of-everything-foo: "bar"
A bit of everything_4:
required:
- "doubleValue"
Expand Down