Giter Site home page Giter Site logo

Comments (3)

johanbrandhorst avatar johanbrandhorst commented on May 22, 2024 1

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.

kamesh-09 avatar kamesh-09 commented on May 22, 2024

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.

joshgarnett avatar joshgarnett commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.