-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new rule to restrict media types in paths (#31)
* feat: add rule for no media types in resources New rule to address: #24 * Added more media types to description * Added more tests * feat: add rule for no media types in resources New rule to address: #24 * Added more media types to description * Added more tests * Update src/ruleset.ts * Update src/ruleset.ts reduce code duplication on regex Co-authored-by: Phil Sturgeon <[email protected]> * tests-added-oas2-tests Added tests for OAS2 api definitions and removed old test Co-authored-by: Phil Sturgeon <[email protected]>
- Loading branch information
1 parent
3e729a4
commit b4ff918
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
import testRule from './__helpers__/helper'; | ||
|
||
testRule('no-file-extensions-in-paths', [ | ||
{ | ||
name: 'valid case', | ||
document: { | ||
swagger: "2.0", | ||
info: { version: '1.0' }, | ||
paths: { 'resources': {} } | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: 'an API definition that is returning a json file', | ||
document: { | ||
swagger: "2.0", | ||
info: { version: '1.0' }, | ||
paths: { 'resources.json': {} } | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Paths must not include file extensions such as .json, .xml, .html and .txt. Use the OpenAPI `content` keyword to tell consumers which Media Types are available.', | ||
path: ["paths", "resources.json"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'an API definition that is returning a xml file', | ||
document: { | ||
swagger: "2.0", | ||
info: { version: '1.0' }, | ||
paths: { 'resources.xml': {} } | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Paths must not include file extensions such as .json, .xml, .html and .txt. Use the OpenAPI `content` keyword to tell consumers which Media Types are available.', | ||
path: ["paths", "resources.xml"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'an API definition that is returning a html file', | ||
document: { | ||
swagger: "2.0", | ||
info: { version: '1.0' }, | ||
paths: { 'resources.html': {} } | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Paths must not include file extensions such as .json, .xml, .html and .txt. Use the OpenAPI `content` keyword to tell consumers which Media Types are available.', | ||
path: ["paths", "resources.html"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'an API definition that is returning a txt file', | ||
document: { | ||
swagger: "2.0", | ||
info: { version: '1.0' }, | ||
paths: { 'resources.txt': {} } | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Paths must not include file extensions such as .json, .xml, .html and .txt. Use the OpenAPI `content` keyword to tell consumers which Media Types are available.', | ||
path: ["paths", "resources.txt"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
} | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
import testRule from './__helpers__/helper'; | ||
|
||
testRule('no-file-extensions-in-paths', [ | ||
{ | ||
name: 'valid case', | ||
document: { | ||
openapi: '3.1.0', | ||
info: { version: '1.0' }, | ||
paths: { 'resources': {} } | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: 'an API definition that is returning a json file', | ||
document: { | ||
openapi: '3.1.0', | ||
info: { version: '1.0' }, | ||
paths: { 'resources.json': {} } | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Paths must not include file extensions such as .json, .xml, .html and .txt. Use the OpenAPI `content` keyword to tell consumers which Media Types are available.', | ||
path: ["paths", "resources.json"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'an API definition that is returning a xml file', | ||
document: { | ||
openapi: '3.1.0', | ||
info: { version: '1.0' }, | ||
paths: { 'resources.xml': {} } | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Paths must not include file extensions such as .json, .xml, .html and .txt. Use the OpenAPI `content` keyword to tell consumers which Media Types are available.', | ||
path: ["paths", "resources.xml"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'an API definition that is returning a html file', | ||
document: { | ||
openapi: '3.1.0', | ||
info: { version: '1.0' }, | ||
paths: { 'resources.html': {} } | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Paths must not include file extensions such as .json, .xml, .html and .txt. Use the OpenAPI `content` keyword to tell consumers which Media Types are available.', | ||
path: ["paths", "resources.html"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'an API definition that is returning a txt file', | ||
document: { | ||
openapi: '3.1.0', | ||
info: { version: '1.0' }, | ||
paths: { 'resources.txt': {} } | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Paths must not include file extensions such as .json, .xml, .html and .txt. Use the OpenAPI `content` keyword to tell consumers which Media Types are available.', | ||
path: ["paths", "resources.txt"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
} | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters