Giter VIP home page Giter VIP logo

protobuf-jsonschema's Introduction

protobuf-jsonschema

Compiles Protocol Buffer IDL to JSON Schema definitions.

Usage

You can use protobuf-jsonschema as a command line tool, or as a function in node.

The CLI can output JSON or YAML (e.g. for Swagger). If you specify a protobuf message name along with a file, it will output just that message and all dependencies. Otherwise, it will output all messages.

$ npm install protobuf-jsonschema -g
$ protobuf-jsonschema --help

  Usage: protobuf-jsonschema [options] <file> [model]

  Options:

    -h, --help             output usage information
    -V, --version          output the version number
    -f, --format [format]  output format: json or yaml [json]

In node, protobuf-jsonschema exports a single function that returns an object with the JSON Schema model.

var compile = require('protobuf-jsonschema');

var all = compile('models.proto');
var single = compile('models.proto', 'MyModel');

License

MIT

protobuf-jsonschema's People

Contributors

devongovett avatar iceinn avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

protobuf-jsonschema's Issues

proto3 syntax not supported

hello team i tried your library for proto3 syntax but it seems like not supoorted ,(look parser.js line 355 there is no check for syntax).

Problem converting messages with recursive type references.

I am using the version 1.1.1 of the protobuf-jsonschema and I try to convert the following proto file:

syntax = "proto3";

message Directory {
	string name = 1;
	repeated Directory sub_directories = 2;
	repeated File files = 3;
}

message File {
	string name = 1;
}

The result of the execution is the following

/home/.../lib/node_modules/protobuf-jsonschema/index.js:85
    var id = lookup.slice(0, i).concat(type).join('.');
                                             ^

RangeError: Maximum call stack size exceeded
    at Array.join (native)
    at Compiler.resolve (/home/.../lib/node_modules/protobuf-jsonschema/index.js:85:46)
    at Compiler.build (/home/.../lib/node_modules/protobuf-jsonschema/index.js:128:18)
    at Compiler.<anonymous> (/home/.../lib/node_modules/protobuf-jsonschema/index.js:175:14)
    at Array.forEach (<anonymous>)
    at Compiler.compileMessage (/home/.../lib/node_modules/protobuf-jsonschema/index.js:157:18)
    at Compiler.resolve (/home/.../lib/node_modules/protobuf-jsonschema/index.js:101:18)
    at Compiler.build (/home/.../lib/node_modules/protobuf-jsonschema/index.js:128:18)
    at Compiler.<anonymous> (/home/.../lib/node_modules/protobuf-jsonschema/index.js:175:14)
    at Array.forEach (<anonymous>)

I am using the node module on

  • Linux x86_64 16.04
  • node v8.11.4
  • npm 5.6.0

Any chance for transferring proto comments directly above a field to `"$comment"` keyword inside the json type?

i.e. PROTO:

message TIMESTAMP {
        // Represents seconds of UTC time since Unix epoch
        required int64 seconds = 1;   

        // Non-negative fractions of a second at millisecond resolution
        required int32 millis = 2;        
}

JSON SCHEMA:

"TIMESTAMP": {
      "title": "TIMESTAMP",
      "type": "object",
      "properties": {
        "seconds": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991,
          "$comment" : "Represents seconds of UTC time since Unix epoch"
        },
        "millis": {
          "type": "integer",
          "minimum": -2147483648,
          "maximum": 2147483647,
          "$comment" : "Non-negative fractions of a second at millisecond resolution",
        }
      },
      "required": [
        "seconds",
        "millis"
      ]
    }

Licence

Hello, thank you for your work. Can you specify the MIT (or Apache2,...) license in a LICENSE file

error when handle map<int32, int32> type

When map<int32, int32> appears in .proto file, it will throw error.
throw new Error('Can only use strings as map keys at ' + message.id + '.' + field.name);

Is it possible to solve?

what draft? schema field is missing

Converting a .proto file to json using this tool creates a list of definitions, but none of them have the $schema$ field. This is a problem, because then you don't know what version of JSONschema the schema is, and you can't validate it against it.

In the short term however, what draft of jsonschema does this tool generate out?

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.