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

Allow pattern matching on key #239

Merged
merged 3 commits into from
Jan 4, 2019
Merged

Allow pattern matching on key #239

merged 3 commits into from
Jan 4, 2019

Conversation

pderaaij
Copy link
Contributor

@pderaaij pderaaij commented Jan 4, 2019

This PR makes it possible to create rules that does pattern matching on the key of an object.

For example, for the key of a path you can create the following rule:

   {
       "name":"path-item-lowercased-hyphens",
       "object": "pathItem",
       "enabled": true,
       "description": "path items must be lowercase and separated with hyphens",
       "pattern": { "property": "$key", "split": "/", "value": "^{[^}]*}$|^([a-z-\/]*)$" }
   }

This relates to #214

@pderaaij
Copy link
Contributor Author

pderaaij commented Jan 4, 2019

Unsure what I can do about the breaking builds. Seems circleci related.

@MikeRalphson
Copy link
Contributor

@pderaaij I think you're right. Also patch LGTM for the approach.

@bottoy
Copy link

bottoy commented Jan 11, 2019

I have been testing this new rule together with the linter update (Mermade/oas-kit@310fd30) for the 'responses' object.

'{
"name": "response_number",
"object": "responses",
"enabled": true,
"description": "The response needs to be a number value",
"pattern": { "property": "$key", "value": "^([0-9])*$"}
}'

I think code in speccy - linter.js should be
'const target = (property === '$key') ? Object.keys(object)[0] : object[property];'

With 'response' object only I do not get the key value, but the string referring to the pattern (eg. response)

generic question:

  • When the OAS has an object to validate the key (eg response key, path key, ...) you do it from the parent object (paths, responses) or from within each item (pathItem, response) - or we allow the both

Cheers,
Bram

@MikeRalphson
Copy link
Contributor

Hi @bottoy I think @pderaaij has just fixed this over in oas-kit in Mermade/oas-kit#134

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 this pull request may close these issues.

4 participants