Code Monkey home page Code Monkey logo

Comments (6)

huttotw avatar huttotw commented on August 29, 2024 3

Pull request in to fix this (#12). Will output google/protobuf/timestamp.proto like:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "properties": {
        "timestamp": {
            "type": "string",
            "format": "date-time"
        }
    },
    "additionalProperties": true,
    "type": "object"
}

from protoc-gen-jsonschema.

huttotw avatar huttotw commented on August 29, 2024

We are having this issue as well, I am planning to hack on this today to see if I can get it to work.

from protoc-gen-jsonschema.

chrusty avatar chrusty commented on August 29, 2024

Hi @huttotw and @xliiauo, thanks for your interest. Sorry I don't get around to checking this very often.

I think we may have to support several formats for timestamps here, because in my experience different JSON marshalers will give different results.

For example, the "correct" marshaling should give a timestamp as a string, but naive marshaling would result in seconds and nanos. I'm guessing the best way would be to handle both.

from protoc-gen-jsonschema.

sttawm avatar sttawm commented on August 29, 2024

I don't think there's ambiguity in the format of the timestamp.

As per the protobuf authors:

// # JSON Mapping
//
// In JSON format, the Timestamp type is encoded as a string in the
// RFC 3339 format. That is, the
// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
// where {year} is always expressed using four digits while {month}, {day},
// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
// is required. A proto3 JSON serializer should always use UTC (as indicated by
// "Z") when printing the Timestamp type and a proto3 JSON parser should be
// able to accept both UTC and other timezones (as indicated by an offset).
//
// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
// 01:30 UTC on January 15, 2017.
//
// In JavaScript, one can convert a Date object to this format using the
// standard
// toISOString()
// method. In Python, a standard datetime.datetime object can be converted
// to this format using
// strftime with
// the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
// the Joda Time's [ISODateTimeFormat.dateTime()](
// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
// ) to obtain a formatter capable of generating timestamps in this format.

~ https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto

Anyway, I don't think validating as a string instead of object is a bad idea. It's not as strict as it should be (^ see above), but at least it lets a properly formatted timestamp pass validation.

from protoc-gen-jsonschema.

chrusty avatar chrusty commented on August 29, 2024

@huttotw I raised a new PR copied from your original one (was unable to merge your one because the layout of the project has changed significantly since then).

#25

It doesn't break any of the existing unit tests so I guess we should be fine, but I'd like to run it by a few other people first.

from protoc-gen-jsonschema.

chrusty avatar chrusty commented on August 29, 2024

@huttotw, @sttawm , @xliiauo I've merged this in now, and created a new release. Thanks for your comments!

https://github.com/chrusty/protoc-gen-jsonschema/releases/tag/0.9.0

from protoc-gen-jsonschema.

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.