raml-spec icon indicating copy to clipboard operation
raml-spec copied to clipboard

Nullable type

Open carowright opened this issue 6 years ago • 6 comments

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.

carowright avatar Nov 29 '17 15:11 carowright

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?

sichvoge avatar Dec 28 '17 07:12 sichvoge

@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.

alvassin avatar May 18 '18 16:05 alvassin

@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.

jstoiko avatar May 18 '18 17:05 jstoiko

@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

sheamunion avatar Jun 25 '19 18:06 sheamunion

@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]!

jstoiko avatar Jun 25 '19 20:06 jstoiko

Thanks! Done and done.

sheamunion avatar Jun 25 '19 21:06 sheamunion