Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report duplicated values in enum #1478

Closed
Amachua opened this issue Jan 14, 2021 · 2 comments · Fixed by #1485
Closed

Report duplicated values in enum #1478

Amachua opened this issue Jan 14, 2021 · 2 comments · Fixed by #1485

Comments

@Amachua
Copy link
Contributor

Amachua commented Jan 14, 2021

User story.
As an API Designer, when I define an enumeration with duplicated value, then I want that a warning is raised.

Describe the solution you'd like
When I use the following dummy.yml file

openapi: 3.0.0

info:
  title: Dummy title
  description: Dummy description
  version: 1.0.0

paths:
  /dummy:
    get:
      description: Dummy description
      parameters:
        - in: header
          name: some_header
          description: Some header description.
          schema:
            type: string
            enum: [dummy, dummy, not_so_dummy]
      responses:
        "200":
          description: All is good
        "400":
          description: All is good

And I run the command line

yarn spectral lint .\dummy.yml

Then I want to have an issue that is raised as the entry dummy appears too times in the some_header parameter.

Rule proposition

I've already prepared the following rule so that it could be included (if found useful), in the next version of Spectral.

  enum-duplicated-entry:
    type: validation
    severity: warn
    recommended: true
    formats: ["oas3"]
    message: "A duplicated entry in the enum was found. Error: {{error}}"
    given: $..enum
    then:
      function: schema
      functionOptions:
        schema:
          type: array
          uniqueItems: true

Should I open a Pull request to add it in your ruleset? :)

@P0lip
Copy link
Contributor

P0lip commented Jan 20, 2021

Hey @Amachua
My apologies for the silence on the radio.
Yes, go ahead, please.
It's a neat rule. I like it.
We might need to tweak the given path a bit, to make sure we actually lint a portion of JSON Schema.

@Amachua
Copy link
Contributor Author

Amachua commented Jan 26, 2021

I've started to work on this point, I hope I'll be able to open a Pull Request soon in your repository!

While working on this, what tweak do you think we'll need on the given?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants