-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ls): add rules for OpenAPI 2.0 Responses Object (#3664)
Refs #3606
- Loading branch information
Showing
6 changed files
with
55 additions
and
8 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
6 changes: 5 additions & 1 deletion
6
packages/apidom-ls/src/config/openapi/responses/documentation.ts
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
27 changes: 27 additions & 0 deletions
27
packages/apidom-ls/src/config/openapi/responses/lint/allowed-fields-2-0.ts
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,27 @@ | ||
import { range } from 'ramda'; | ||
import { DiagnosticSeverity } from 'vscode-languageserver-types'; | ||
|
||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
import { OpenAPI2 } from '../../target-specs'; | ||
|
||
/** | ||
* Validation here is based on IANA HTTP Status code registry: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml | ||
* | ||
* Clarification of OpenAPI specification what are accepted HTTP Status code comes from https://github.com/OAI/OpenAPI-Specification/issues/2471. | ||
*/ | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const allowedFields2_0Lint: LinterMeta = { | ||
code: ApilintCodes.NOT_ALLOWED_FIELDS, | ||
source: 'apilint', | ||
message: | ||
'Responses Object uses HTTP Status Codes outside of allowed IANA HTTP Status code registry', | ||
severity: DiagnosticSeverity.Error, | ||
linterFunction: 'allowedFields', | ||
linterParams: [['default', ...range(100, 600).map(String)], 'x-'], | ||
marker: 'key', | ||
targetSpecs: OpenAPI2, | ||
}; | ||
|
||
export default allowedFields2_0Lint; |
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
5 changes: 3 additions & 2 deletions
5
packages/apidom-ls/src/config/openapi/responses/lint/index.ts
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import allowedFieldsLint from './allowed-fields'; | ||
import allowedFields2_0Lint from './allowed-fields-2-0'; | ||
import allowedFields3_0__3_1Lint from './allowed-fields-3-0--3-1'; | ||
import valuesTypeLint from './values--type'; | ||
|
||
const lints = [valuesTypeLint, allowedFieldsLint]; | ||
const lints = [valuesTypeLint, allowedFields2_0Lint, allowedFields3_0__3_1Lint]; | ||
|
||
export default lints; |
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