Skip to content

Commit

Permalink
fix: only include methods of paths in rule "path-must-specify-tags"
Browse files Browse the repository at this point in the history
* do not version pnpm-lock.yaml

* added spectral-runtime, because without it did not build

* added new test for "path-must-specify-tags" and fixed the jsonpath selector to not fetch none "paths" paths

* build with npm instead of pnpm.

* reduced the example spec.

* merged new rules to spectral.yml
  • Loading branch information
LucasMaciuga committed Apr 30, 2024
1 parent 6dc5b5f commit 68d460e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
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({
"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

0 comments on commit 68d460e

Please sign in to comment.