Comments (3)
As Kamesh says, this is a post-processing step at the moment, there's no support for including it in the output generated by protoc-gen-openapiv2. I think Kamesh is talking about using https://jsonpatch.com/ perhaps? But any way you want to post-process the file should work. I've used Go before.
from grpc-gateway.
You can have a json file similar to openapi output - having paths as key - with upload endpoints. Once openapi output is generated you can patch your custom file into generated output. Can be automated via script which will basically combine both json files, so manual update is not required everytime.
You can define patch file as:
{
"paths": {
"upload_endpoint": {
"methodType[post]": {
"requestBody": {.....}
}
}
}
}
from grpc-gateway.
For anyone else going down this path, here is an example patch file you can use:
{
"paths": {
"/v1/file": {
"post": {
"summary": "Upload a file",
"operationId": "Service_UploadFile",
"consumes": [
"multipart/form-data"
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1UploadFileResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "file",
"description": "The file being to be uploaded.",
"in": "formData",
"required": true,
"type": "file"
}
],
"tags": [
"Service"
]
}
}
},
"definitions": {
"v1UploadFileResponse": {
"type": "object",
"properties": {
"file": {
"$ref": "#/definitions/apiSomeOtherProtobuf"
}
}
}
}
}
For merging the json, I just tossed together a simple python script
#!/usr/bin/env python3
import argparse
import json
import mergedeep
def main():
parser = argparse.ArgumentParser(description='Merges two json files')
parser.add_argument('-b', '--base', required=True, help="the base json file")
parser.add_argument('-p', '--patch', required=True, help="the patch json file")
parser.add_argument('-o', '--out', required=True, help="the file to write the output to")
args = parser.parse_args()
with open(args.base) as f:
base = json.load(f)
with open(args.patch) as f:
patch = json.load(f)
mergedeep.merge(base, patch)
with open(args.out, 'w') as f:
json.dump(base, f, indent=2)
if __name__ == '__main__':
main()
from grpc-gateway.
Related Issues (20)
- genopenapi: Stable openapi names for nested types HOT 1
- snake_case response HOT 1
- api_visibility doesn't transitively apply to rpc request/response messages HOT 2
- protoc-gen-grpc-gateway and protoc-gen-openapiv2 return incorrect version HOT 1
- Dependency on google.golang.org/grpc/health/grpc_health_v1 conflicts with custom proto marshallers HOT 5
- JSONPb marshaler doesn't use indent on non proto fields
- WriteHeader is not called on 200s HOT 1
- How to set cookie to http response header? Why it doesn't work. HOT 2
- The API Gateway Vision HOT 2
- Support disabling default response rendering in bazel rule HOT 1
- Example and pattern annotations are not respect for query and path parameters HOT 8
- FieldMask as query param is not converted to snake case HOT 1
- an google.protobuf.Any type how to get openapiv2 output? HOT 1
- omit-enum-default-value Generates Invalid Spec for Enums with a Single Value HOT 1
- Content-Length not set in ForwardResponseMessage HOT 5
- Log level for errors is "info" HOT 5
- On `context deadline exceeded`, response headers aren't set HOT 3
- Add support for Etag & If-None-Match headers HOT 6
- TestOutgoingTrailerMatcher is non-deterministic
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-gateway.