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

Fixed: path-must-specify-tags #40

Merged
merged 6 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions rules/endpoint/path-must-specify-tags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ describe("path-must-specify-tags", () => {
expect(result[0].code).toEqual("path-must-specify-tags");
});

it("do not fail if the keywords for http methods are used in components", async () => {
const result = await spectral.run(getComponentTestSpec());
expect(result).toHaveLength(0);
});

it("ignores paths under the well-known route", async () => {
const result = await spectral.run(getTestSpec(undefined, "/well-known/health"));
expect(result).toHaveLength(0);
Expand Down Expand Up @@ -60,4 +65,50 @@ describe("path-must-specify-tags", () => {
},
},
});

const getComponentTestSpec = (tags?: string[], path = "/api/some/path") =>
JSON.stringify({
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's neccessary to have the full spec for this unit test. Only a path and a component should be neccessary to reproduce the issue.

"openapi": "3.0.2",
"tags": [
{
"name": "SomeTag",
"description": "some description"
}
],
"paths": {
"/twin/api/v1/somethings": {
"get": {
"operationId": "GetSomething",
"description": "hi test",
"tags": [
"SomeTag"
],
}
}
},
"components": {
"schemas": {
"ShowMe": {
"type": "object",
"properties": {
"input": {
"type": "object",
"properties": {
"get": {
"type": "string"
},
"delete": {
"type": "boolean"
},
"options": {
"type": "string",
"nullable": true
}
}
}
}
}
}
}
});
});
2 changes: 1 addition & 1 deletion rules/endpoint/path-must-specify-tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rules:
severity: error
formats:
- oas3
given: $.paths[?(!@property.match(/well-known/ig))].[get,post,put,delete,patch,options,head,trace]
given: $.paths[?(!@property.match(/well-known/ig))][get,post,put,delete,patch,options,head,trace]
then:
- field: tags
function: truthy
Expand Down
2 changes: 1 addition & 1 deletion spectral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ rules:
description: Every route must specify at least one tag it belongs to
message: "{{description}}; property tags is missing at: {{path}}"
severity: error
given: $.paths[?(!@property.match(/well-known/ig))].[get,post,put,delete,patch,options,head,trace]
given: $.paths[?(!@property.match(/well-known/ig))][get,post,put,delete,patch,options,head,trace]
then:
- field: tags
function: truthy
Expand Down
Loading