raml-org / raml-spec

RAML Specification
http://raml.org
3.87k stars 858 forks source link

Media type matching rules for inferring against which format (json, xml) to validate a request body #373

Closed svacas closed 8 years ago

svacas commented 8 years ago

I'm not sure if the spec is clear in this respect, so here's a short list of possible rules to match media types to body schema validation formats:

JSON matching rules

*/json (e.g: text/json, application/json)
*/*+json (e.g: application/alto-costmap+json)
*/*.json (e.g: application/vnd.apache.thrift.json)

XML matching rules

*/xml (e.g: text/xml, application/xml)
*/*+xml (e.g: application/alto-costmap+xml)
*/*.xml (e.g: application/vnd.apache.thrift.xml)
petrochenko-pavel-a commented 8 years ago

As for me validating request body is actually not related to media type. But according to matching rules I think we should use sub type from https://en.wikipedia.org/wiki/Media_type and check if it xml or json (this only restriction that comes to my mind is that you can not use xsd schema with json related media types and vice versa)

svacas commented 8 years ago

Any client tool like the RAML Console needs to know this rules in order to present valid examples for requests and responses. Otherwise the examples are useless.

sichvoge commented 8 years ago

@svacas the question is if you agree to what Pavel said?

svacas commented 8 years ago

I'm OK with it as long as it's clear in the spec

sichvoge commented 8 years ago

So @petrochenko-pavel-a is it enough to mention the matching rules that @svacas highlighted and that a RAML processor MUST validate a request body against these?

sichvoge commented 8 years ago

OK, thinking about that with a couple of people - it would be better to keep that not mandated by the specification. Every implementor should decide what media types their tooling supports and clearly state it. The specification should be free from that giving the needed flexibility. @svacas do you agree?

svacas commented 8 years ago

Agreed