Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Is there a way to define the format attribute? #43

Open
sciutand opened this issue Nov 5, 2015 · 14 comments
Open

Is there a way to define the format attribute? #43

sciutand opened this issue Nov 5, 2015 · 14 comments

Comments

@sciutand
Copy link

sciutand commented Nov 5, 2015

Json schema has a 'format' keyword. Is this supported by mson? I couldn't find any reference

http://json-schema.org/latest/json-schema-validation.html#anchor104

@pksunkara
Copy link
Contributor

@sciutand I don't think we support it yet.

@zdne
Copy link
Contributor

zdne commented Nov 9, 2015

@sciutand not at this moment no. I was thinking about adding some validations to MSON. Can you please elaborate a bit? What is the particular validation you are looking for?

@geemus
Copy link

geemus commented Feb 24, 2016

@zdne some I have found useful would be email and uuid (though I think we defined uuid ourselves with a regex). Additionally something like datetime for iso8601 timestamp strings is really helpful.

@zdne
Copy link
Contributor

zdne commented Feb 25, 2016

Thanks for the input!

I would like to keep collecting the feedback on this and then implement the most requested format / validators based on that.

@geemus
Copy link

geemus commented Feb 25, 2016

Sure, in addition to those, I think all the ones from json-schema validation spec are handy: date-time, email, hostname, ipv4, ipv6, and uri.

@kevinswiber
Copy link

I'm currently looking to do this with uri. 👍

@zdne
Copy link
Contributor

zdne commented Jun 9, 2016

... so basically all of the predefined validations 😎

@jmatsushita
Copy link

Hi there,

Do note that the spec says MAY add custom format attributes. so I think it does make sense to have a syntax which allows adding an arbitrary format in MSON. Given that any keyword with the format key seems valid, it seems that MSON only needs a syntax that would allow for that, and doesn't need to define anything particular about each format and can delegate to JSON Schema validators to take care of interpreting the format values. Unless I'm missing something.

The popular ajv for instance validates the spec formats and a few more: https://github.com/epoberezkin/ajv#formats

Also check out the v5 proposal implemented in ajv for much more general way to implement validations.

Anyway, getting back to the topic.

Proposal for format syntax in MSON.

Here a proposal for a format syntax in MSON which would generate the following schema:

{ '$schema': 'http://json-schema.org/draft-04/schema#',
  type: 'object',
  properties: { prop: { type: 'string' } } }

So the following data should validate:

{ 
 "prop": "1985-04-12T23:20:50.52Z"
}

Proposal: Use []

# format
- `prop`: `1985-04-12T23:20:50.52Z` (string[date-time])

The advantage of this over other variations I've tried is that it's valid MSON and drafter returns it as a simple string.

{ '$schema': 'http://json-schema.org/draft-04/schema#',
  type: 'object',
  properties: { prop: { type: 'string' } } }

The square brackets [] are used for Nested Member Types and Generics for Structure Types, so not used for primitive types. Although the spec doesn't seem to specify this, format seems to only apply to the string primitive.

What do you think?

Cheers,

Jun

@zdne
Copy link
Contributor

zdne commented Jul 26, 2016

Hey @jmatsushita,
thanks for your detailed reply! Definitely good pointers there!

We have originally intended to use the validation (validations) keyword for format validation. See the stub here https://github.com/apiaryio/mson/blob/master/MSON%20Specification.md#46-validations

So in the case of string[date-time] I would rather see a custom type with validations. Eg.

# Date Type (string)
This is a description

## Validations
...

## Sample
1985-04-12T23:20:50.52Z

Note this is not valid syntax at this moment..

@jmatsushita
Copy link

That sounds good! I guess that would mean you'd have some predefined validations for the formats in the JSON Schema spec? date-time, email, hostname, ipv4, ipv6, and uri ?

@zdne
Copy link
Contributor

zdne commented Jul 27, 2016

@jmatsushita could be, see #43 (comment)

@namoscato
Copy link

Any update on plans to support JSON schema's defined formats? I am particularly interested in date-time but see no reason why others should not also be supported.

@alangibson-philips
Copy link

Are there any plans to support this? It would be nice to have a firm statement, even if it's "no."

@pksunkara
Copy link
Contributor

Definitely yes. But we can't give an ETA.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants