-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat: allow linting OpenAPI path templates #3532
Conversation
@@ -83,4 +84,5 @@ export default { | |||
tag: tagMeta, | |||
xml: xmlMeta, | |||
schema: schemaMeta, | |||
'path-template': pathTemplateMeta, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we're attaching our meta (containing linting rules) to the path-template
meta class.
linterFunction: 'apilintOpenAPIPathTemplateValid', | ||
marker: 'value', | ||
targetSpecs: OpenAPI, | ||
conditions: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to validate matching of Paramater Objects only when the path template is well formed and contains at least one template expression
. That is achieved by params: [true]
.
message: "'path' must begin with '/' and be relative to an individual endpoint", | ||
severity: DiagnosticSeverity.Error, | ||
linterFunction: 'apilintOpenAPIPathTemplateWellFormed', | ||
linterParams: [false], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we don't care if path template contains at least one template expression, as long as the entire path template is well formed.
}, | ||
{ | ||
functionName: 'apilintOpenAPIPathTemplateValid', | ||
function: (element: Element) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where you need to implement the logic of matching template expressions against the Parameter Objects.
@@ -26,6 +26,8 @@ const PathsVisitor = stampit(PatternedFieldsVisitor, FallbackVisitor, { | |||
this.element | |||
.filter(isPathItemElement) | |||
.forEach((pathItemElement: PathItemElement, key: StringElement) => { | |||
key.classes.push('openapi-path-template'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attaching metadata classes.
@@ -26,6 +26,8 @@ const PathsVisitor = stampit(PatternedFieldsVisitor, FallbackVisitor, { | |||
this.element | |||
.filter(isPathItemElement) | |||
.forEach((pathItemElement: PathItemElement, key: StringElement) => { | |||
key.classes.push('openapi-path-template'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attaching metadata classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work and thanks for the comments, they helped me a lot 🎉
Refs #3517