redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Add linting rule to validate nullable enums

Open dmarra opened this issue 1 year ago • 2 comments

Currently, the OpenAPI spec has this to say about nullable enums:

image

Despite running our API spec through the linter with a non-conforming nullable enum, it passed! The end result was that a consumer downstream was having trouble integrating because they could not generate a client from the spec

I think it would be a great benefit to add a rule that explicitly checks:

IF `type` is `enum` AND `nullable` is `true`: ensure null appears in the list of values

The temporary solution I was considering is a custom rule, but this feels like something that should come out of the box as a built-in rule

Here is an example of something that should not pass linting, but does:

        myEnumType:
          type: string
          nullable: true
          enum:
            - "foo"
            - "bar"
            - "baz"           

And this is what it should be in order to conform:

        myEnumType:
          type: string
          nullable: true
          enum:
            - "foo"
            - "bar"
            - "baz"
            - null           

conversely, this should also fail:

        myEnumType:
          type: string
          nullable: false
          enum:
            - "foo"
            - "bar"
            - "baz"  
            - null         

dmarra avatar Apr 20 '23 21:04 dmarra

Hi, thanks for reporting!

Could you specify the exact and OAS and Redocly CLI versions?

tatomyr avatar Apr 24 '23 08:04 tatomyr

Of course! Sorry I should have included that originally

  • OpenAPI version: 3.0.1
  • Readocly CLI version: 1.0.0-beta.125

dmarra avatar Apr 24 '23 16:04 dmarra