GithubHelp home page GithubHelp logo

protobuf2swagger's People

Contributors

jennieji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

protobuf2swagger's Issues

Transform hook - enum SyntaxError: Unexpected reserved word

There's another way to access the enums?
the code from the doc generates an error

const [enum] = args;
               ^^^^
SyntaxError: Unexpected reserved word
    at wrapSafe (internal/modules/cjs/loader.js:1029:16)
    at Module._compile (internal/modules/cjs/loader.js:1078:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Module.load (internal/modules/cjs/loader.js:979:32)
    at Function.Module._load (internal/modules/cjs/loader.js:819:12)
    at Module.require (internal/modules/cjs/loader.js:1003:19)
    at require (internal/modules/cjs/helpers.js:107:18)

It seems like you might not have tested the use of the 'required' keyword in a .proto file

In message2JSON.js line 5, you declare an array named required which is intended to hold a list of the names of message fields that were declared with a required keyword. However, on line 7, inside the arrow function in the reduce call, you then declare a const required which gets assigned the boolean property of the Field class instance that you are working with. Then you test both optional and required to decide whether to push the field.

Unfortunately, the array has been occulted by the bool, and so the push method is not accessible. Even if the method were accessible, you're pushing the entire field instead of just the name. I think lines 7-9 should be rewritten as follows:

  const { optional, required: is_required } = field;
    if (!optional || is_required) {
      required.push(field.name);

There may be another issue, which I have not fully confirmed yet. It seems that certain swagger validators complain if the required array is empty, and I don't know if this conforms to the specification. You may need to rewrite the return statement on lines 16-21 as follows:

  let $return = {
    type: 'object',
    properties,
    required,
    description,
  };
  if(!required.length) delete $return.required ;
  return $return ;

Support for protobuf 3

Does this tool support proto3? I tried using it, and it seems to work at the first glance. I am just not entirely sure if this works as expected.

Incorrect field resolution in output openapi object

Hi Jenny,
I added this testcase in mine forked branch, that shows incorrect resolution of StaticRoute field:
master...80220:protobuf2swagger:patch/bad_resolution
Looking at Json Descriptor object (root) I can't find a way to resolve this import properly. Wonder if that is a problem in dependant lib (protobufjs) maybe it creates invalid tree out of proto files?

Adding logging to display the field, its type is StaticRoute and the root tree contains 2 definitions of it under different namespaces and the wrong one is resolved (not the one indicated by import in request.proto file)

image

My assumption is, that the type attribute of the field should be set to:
type: 'a.b.c.d.StaticRoute', (as per import statement)
instead of
type: 'StaticRoute',
that would assure proper resolution.
But if so then the problem is in protobuf.js that builds this json tree out of proto files.
Gimme your thoughts on this/thanks!

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.