jdiegodcp / ramlfications

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

Base URI parameters need not have defaults. #20

Closed vrajmohan closed 8 years ago

vrajmohan commented 9 years ago

When I have a parameter entry under baseUriParameters and it does not have a default, ramlfications validate complains with: Error validating file foo.raml: The 'default' parameter is not set for base URI parameter 'bar'.

AFAIK, from the RAML spec, a baseURIParameter need not have a default.

econchick commented 9 years ago

Hi there!

The RAML spec does in fact require defaults for base URI params. If you look under the section "base URI and base URI parameters" for the spec it says:

"If a URI template variable in the base URI is not explicitly described in a baseUriParameters property, and is not specified in a resource-level baseUriParameters property, it MUST still be treated as a base URI parameter with defaults as specified in the Named Parameters section of this specification. Its type is "string", it is required, and its displayName is its name (i.e. without the surrounding curly brackets [{] and [}])."

If it's causing you trouble while a RAML file is under development/might change, you can set validate=False in your config file like here.

vrajmohan commented 9 years ago

Pardon me, but I read the very same section and interpreted it to mean that IF (and only IF) a URI template variable in the base URI is not explicitly described in a baseUriParameters property, and is not specified in a resource-level baseUriParameters property, THEN it MUST still be treated as a base URI parameter with defaults as specified in the Named Parameters section of this specification. The defaults as specified in the Named Parameters section of this specification are:

  1. default for the "type" property is "string"
  2. default for the "required" property is true (from "For a URI parameter, the required attribute MAY be omitted, but its default value is 'true'.")
  3. default for the "displayName" property is its name

There is nothing here that states that the template variable must have a "default" property.

To illustrate, consider the fragment below: baseUri: https://api.foo.com/{version}/accounts/{account_id} version: 1.0 baseUriParameters: account_id: displayName: Account ID type: integer

Here I have explicitly overridden the type and displayName. This means that the account_id parameter has a displayName of "Account ID", its type is integer and it is required.

The "default" property for a named parameter, on the other hand, is the value the server uses if the client does not send a value (see below). It woud rarely make sense to have one for a URI parameter.

(Optional) The default attribute specifies the default value to use for the property if the property is omitted or its value is not specified. This SHOULD NOT be interpreted as a requirement for the client to send the default attribute's value if there is no other value to send. Instead, the default attribute's value is the value the server uses if the client does not send a value.

econchick commented 9 years ago

OK so you're correct in that I incorrect interpreted that section (was quickly reading on mobile).

I'm looking at other parsers right now to see how it's handled. But I think you are correct that default isn't required for baseUriParams - thanks for letting me know.

econchick commented 8 years ago

Addressed in #29 - thanks!