jdiegodcp / ramlfications

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

RAML 0.8: optional resourceTypes methods support #101

Closed alvassin closed 8 years ago

alvassin commented 8 years ago

Following code with raise error InvalidParameterError: Response code '200?' must be an integer representing an HTTP code.:

resourceTypes:
  - base:
      get?:
        responses:
          200?:
            description: "The request has succeeded."

Also, if i would have both optional & required responses codes, i will get following error:

  File "/usr/local/lib/python3.5/site-packages/ramlfications/parser.py", line 561, in wrap
    responses=responses(data),
  File "/usr/local/lib/python3.5/site-packages/ramlfications/parser.py", line 457, in responses
    return sorted(response_objects, key=lambda x: x.code)
TypeError: unorderable types: int() < str()

Optional resource response codes are officially supported in RAML 0.8 as described:

When defining resource types and traits, it can be useful to capture patterns that manifest several levels below the inheriting resource or method, without requiring the creation of the intermediate levels. For example, a resource type definition may describe a body parameter that will be used if the API defines a post method for that resource, but the processing application should not create the post method itself.

To accommodate this need, a resource type or trait definition MAY append a question mark ("?") suffix to the name of any non-scalar property that should not be applied if it doesn't already exist in the resource or method at the corresponding level. This optional structure key indicates that the value of the property should be applied if the property name itself (without the question mark) is already defined (whether explicitly or implicitly) at the corresponding level in that resource or method.

Could you please fix that?

econchick commented 8 years ago

Hey @alvassin ! Good catch, yes - this issue is already filed in #43 and is in the backlog for the 0.2.0 release. I'm going to go ahead and close as a duplicate, but let me know if anything else comes up!

Cheers!