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

feat: allow linting OpenAPI path templates #3532

Merged
merged 2 commits into from
Dec 13, 2023
Merged

feat: allow linting OpenAPI path templates #3532

merged 2 commits into from
Dec 13, 2023

Conversation

char0n
Copy link
Member

@char0n char0n commented Dec 13, 2023

Refs #3517

@@ -83,4 +84,5 @@ export default {
tag: tagMeta,
xml: xmlMeta,
schema: schemaMeta,
'path-template': pathTemplateMeta,
Copy link
Member Author

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: [
Copy link
Member Author

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],
Copy link
Member Author

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) => {
Copy link
Member Author

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');
Copy link
Member Author

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');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attaching metadata classes.

Copy link
Contributor

@kowalczyk-krzysztof kowalczyk-krzysztof left a 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 🎉

@char0n char0n merged commit b0b03a2 into main Dec 13, 2023
8 checks passed
@char0n char0n deleted the char0n/3517 branch December 13, 2023 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants