raml-org / raml-spec

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

Nullable type #665

Open carowright opened 6 years ago

carowright commented 6 years ago

There is an example in nil type section that adds a question mark on the property type side:

types:
  NilValue:
    type: object
    properties:
      name:
      comment: nil | string # equivalent to ->
                             # comment: string?
    example:
      name: Fred
      comment: # Providing a value or not providing a value here is allowed.

As it's mentioned in the comment, it's the same as:

types:
  NilValue:
    type: object
    properties:
      name:
      comment: string?

example:
      name: Fred
      comment: # Providing a value or not providing a value here is allowed.

This example can be found in here. Besides this example there is no mention of how this construction works. So, either the example is invalid or this construction needs to be defined somewhere in the spec.

sichvoge commented 6 years ago

Hi Caro. It is defined, but not very clear indeed. Look into the first example of yours. the important line is:

comment: nil | string # equivalent to ->
                      # comment: string?

As you can see, comment: string? is syntactic sugar and equivalent to comment: nil | string.

I am sure we could clarify this a bit more. If you have time, may I ask you to send us a PR?

alvassin commented 6 years ago

@sichvoge seems to be a bug.

according to nil | string equals to comment? means that comment is optional, but it should be not like that.

technically comment must be required, but can have as null as string values as well.

jstoiko commented 6 years ago

@alvassin: comment? and string? are two different things.

comment: nil | string

is equivalent to:

comment: string?

and means that the value of comment can be null whereas:

comment?: string

means that comment is not required.

We could also have:

comment?: string?

which would mean that comment can be null and is also not required.

sheamunion commented 5 years ago

@jstoiko I'm trying to create a required, nullable property with a user-defined type in a separate file. For some reason, my IDE (MuleSoft Anypoint Studio) considers this invalid. Am I trying to do something invalid or is my IDE incorrect?

Response.raml

#%RAML 1.0 DataType

type: object
properties:
  error: nil | !include Error.raml

Error.raml

#%RAML 1.0 DataType

type: object
properties:
  code: string
  message: string
jstoiko commented 5 years ago

@sheamunion: you cannot use an !include in a union. If you’d like to discuss this further though, could you please create a separate issue. This is a different topic. Also, feel to join our (Slack community)[https://raml.org/slack]!

sheamunion commented 5 years ago

Thanks! Done and done.