Comments (6)
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.
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.
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.
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 standarddatetime.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.
@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).
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.
@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)
- Help wanted - Syntax for Array of object is not following specification HOT 1
- Support for 'description' options HOT 2
- Cannot convert proto HOT 3
- BUG: Using the --jsonschema_opt=enforce_oneof flag makes all "optional" fields in the .proto files required in the jsonschema HOT 3
- List on json-schema.org HOT 2
- expose internal package HOT 1
- Generating json schema for nested message HOT 1
- Add an option for KeepNewLinesInDescription flag HOT 1
- Add support for numerics HOT 1
- archived / unmaintained deps
- field meta data
- including comments in the file HOT 1
- [QUESTION] output options
- Multiple allowed in oneOf? HOT 2
- Generator "spin loops" (?)
- allow for $schema as an optional type
- Go package doesn't work correctly with Protobuf reflection
- Handling default in proto2
- Support nullable arrays when using `all_fields_required`
- Supressing output logging (info)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protoc-gen-jsonschema.