dredd: Enums can't be nullable

Problems with nullable enums were reported by multiple users in https://github.com/apiaryio/mson/issues/61. We should investigate the problem.

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 1
  • Comments: 17 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve got an example reproducing this issue. I believe it is the generated JSON schema that is incorrect.

My apib file:

FORMAT: 1A

# Test API

### Test route [GET /test]

+ Response 200 (application/json)
    + Attributes (Item, fixed-type)

# Data Structures

## Item (object)

- type (Type, nullable)

## Type (enum)

- type1
- type2

Generated schema versus the tested response: https://jsonschemalint.com/#/version/draft-04/markup/json?gist=86082c8c39b53359fe6835163fc65569

If I add null (without quotes) as one of the possible enum types, the generated JSON schema includes “null” (with quotes) as a possible enum type.

So, this:

## Type (enum)

- null
- type1
- type2

results in this generate schema versus the tested response: https://jsonschemalint.com/#/version/draft-04/markup/json?gist=f80347a08900d60c4d264b9c8bd1ca79

Finally, I’d like to conclude with a working combination: https://jsonschemalint.com/#/version/draft-04/markup/json?gist=458a3729bd732bd5109dbe1fc5d93619

@andybarilla I’ve prepared a fix in https://github.com/apiaryio/api-elements.js/pull/59, I hope you don’t mind that I’ve taken parts of your example Swagger 2 document to reproduce in our test fixtures.

Yes, x-nullable by default would mean null in enum. But when you provide a different enum, then they would contradict and enum gets priority since it is actually directly JSON Schema instead of an extension.

This was fixed in Drafter. Soon it should propagate to Dredd.