jennieji / protobuf2swagger Goto Github PK
View Code? Open in Web Editor NEWConvert protobuf v2 to swagger openapi v3 JSON
License: MIT License
Convert protobuf v2 to swagger openapi v3 JSON
License: MIT License
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)
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 ;
long allow to convert to number or string
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.
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)
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!
including: method
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.