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

Feature: Add simple array validation rules #215

Closed
TrampGuy opened this issue Dec 4, 2018 · 6 comments
Closed

Feature: Add simple array validation rules #215

TrampGuy opened this issue Dec 4, 2018 · 6 comments

Comments

@TrampGuy
Copy link

TrampGuy commented Dec 4, 2018

Detailed description

Most current rules don't seem to support a property (object) containing an array.

Context

Given the following:

security:
  - A
    - aaa
  - B
    - bbb

I would like to check if the security property contains at least one of A, B or C

I thought or might do it, but it turns out most of the rules don't quite support this array structure.

@TrampGuy
Copy link
Author

Is this not described properly? too wide? or could already be achieved somehow?

@pderaaij
Copy link
Contributor

pderaaij commented Jan 4, 2019

Not completely sure, but when #239 is merged you can try with using $key as a parameter and make a regex for it. Not the most beautiful way but it might work.

I created the following rule to make sure an oauth2 security scheme is defined:

  {
       "name":"security-scheme-oauth2",
       "object": "securityScheme",
       "enabled": true,
       "description": "must define an oauth2 security scheme",
       "pattern": { "property": "type", "value": "oauth2" }
   }

@MikeRalphson
Copy link
Contributor

You might want to anchor that regex value, just in case.

@philsturgeon
Copy link
Contributor

It's been merged, so you can pull and try with master, or use docker run wework/speccy:nightly lint foo.yaml.

@MikeRalphson
Copy link
Contributor

The next version of the oas-kit linter has a JSON schema rule, so I think you could do something like:

name: oneof-a-b-or-c
object: security
schema:
  type: array
  items:
    oneOf:
    - required:
      - A
    - required:
      - B
    - required:
      - C

@philsturgeon
Copy link
Contributor

Great work Mike! All new rules will be going in via oas-kit, and once we merge #248 we'll have all their awesome rules.

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

No branches or pull requests

4 participants