jdiegodcp / ramlfications

Python parser for RAML
https://ramlfications.readthedocs.org
Apache License 2.0
234 stars 50 forks source link

Support optionality for all the things #131

Open econchick opened 7 years ago

econchick commented 7 years ago

In RAML 0.8, only methods w/i resource types were optional, denoted with a question mark (e.g. get?.

In RAML 1.0, a lot more can be optional. We should figure out a sane approach to parsing and reflecting how a named attribute is optional.

sichvoge commented 7 years ago

I don't think that this is true. The spec states

To accommodate this need, a resource type definition MAY append a question mark ("?") suffix to the name of any method to declare the method as optional, resulting in the following behavior:

econchick commented 7 years ago

@sichvoge Under the General headline, it says:

A trailing question mark, for example description?, indicates an optional property.

There's also many examples of non-methods having trailing question marks. For instance, in the table listing nodes for the Root of a RAML file.

sichvoge commented 7 years ago

OH, maybe it's a bit confusing first; but that general headline only talks about optional nodes in RAML. That means, when we say

A trailing question mark, for example description?, indicates an optional property.

It really mean, whenever you see (inside the specification document) a node with a question mark; it is an optional node. For example:

#%RAML 1.0
title: A

description: Test
#%RAML 1.0 
title: A

Both examples are valid, since description is an optional node. On the other hand, title is a required node and leaving it out is not valid.

When you said "In RAML 0.8, only methods w/i resource types were optional, denoted with a question mark (e.g. get?).", you referred to a mechanism that is available in a resource type definition. Marking a method "optional" does nothing else than having you to declare it explicitly on the resource to apply it. For example:

#%RAML 1.0
title: A

resourceTypes:
  collection:
    get:
    post?:

/resource:
  type: collection
/resource1:
  type: collection
  post:

In that case, /resource has only one HTTP method get, but resource1 has post and get.