-
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 linting rule for OAS server variable enum and default
- Loading branch information
Showing
9 changed files
with
241 additions
and
2 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
25 changes: 25 additions & 0 deletions
25
packages/apidom-ls/src/config/openapi/server-variable/lint/default--in-enum-3-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,25 @@ | ||
import { DiagnosticSeverity } from 'vscode-languageserver-types'; | ||
|
||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const defaultInEnum3_0Lint: LinterMeta = { | ||
code: ApilintCodes.OPENAPI3_O_SERVER_VARIABLE_FIELD_DEFAULT_IN_ENUM, | ||
source: 'apilint', | ||
message: "'default' value should exist in the enum's values.", | ||
severity: DiagnosticSeverity.Warning, | ||
linterFunction: 'apilintIncludedInArray', | ||
linterParams: ['parent.enum', false], | ||
marker: 'value', | ||
target: 'default', | ||
data: {}, | ||
targetSpecs: [ | ||
{ namespace: 'openapi', version: '3.0.0' }, | ||
{ namespace: 'openapi', version: '3.0.1' }, | ||
{ namespace: 'openapi', version: '3.0.2' }, | ||
{ namespace: 'openapi', version: '3.0.3' }, | ||
], | ||
}; | ||
|
||
export default defaultInEnum3_0Lint; |
20 changes: 20 additions & 0 deletions
20
packages/apidom-ls/src/config/openapi/server-variable/lint/default--in-enum-3-1.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,20 @@ | ||
import { DiagnosticSeverity } from 'vscode-languageserver-types'; | ||
|
||
import ApilintCodes from '../../../codes'; | ||
import { LinterMeta } from '../../../../apidom-language-types'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const defaultInEnum3_1Lint: LinterMeta = { | ||
code: ApilintCodes.OPENAPI3_1_SERVER_VARIABLE_FIELD_DEFAULT_IN_ENUM, | ||
source: 'apilint', | ||
message: "'default' value must exist in the enum's values.", | ||
severity: DiagnosticSeverity.Error, | ||
linterFunction: 'apilintIncludedInArray', | ||
linterParams: ['parent.enum', false], | ||
marker: 'value', | ||
target: 'default', | ||
data: {}, | ||
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }], | ||
}; | ||
|
||
export default defaultInEnum3_1Lint; |
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
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
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
34 changes: 34 additions & 0 deletions
34
packages/apidom-ls/test/fixtures/validation/oas/server-variables-3-0.yaml
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,34 @@ | ||
openapi: 3.0.2 | ||
info: | ||
title: test | ||
version: 1.0.0 | ||
servers: | ||
- url: https://{host}:{port}/{basePath}/{otherPath} | ||
description: Live Bookstore dynamic servers | ||
variables: | ||
host: | ||
default: test.book.com | ||
enum: | ||
- test.book.com | ||
- staging.book.com | ||
- sandbox.book.com | ||
- production.book.com | ||
port: | ||
default: '443' | ||
enum: [] | ||
basePath: | ||
default: v2.0 | ||
enum: | ||
- v1.0 | ||
- v1.1 | ||
- v1.2 | ||
- v1.3 | ||
otherPath: | ||
default: foo | ||
paths: | ||
/a: | ||
get: | ||
operationId: aget | ||
responses: | ||
'200': | ||
description: test |
31 changes: 31 additions & 0 deletions
31
packages/apidom-ls/test/fixtures/validation/oas/server-variables.yaml
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,31 @@ | ||
openapi: 3.1.0 | ||
info: | ||
title: test | ||
version: 1.0.0 | ||
servers: | ||
- url: https://{host}:{port}/{basePath}/{otherPath} | ||
description: Live Bookstore dynamic servers | ||
variables: | ||
host: | ||
default: test.book.com | ||
enum: | ||
- test.book.com | ||
- staging.book.com | ||
- sandbox.book.com | ||
- production.book.com | ||
port: | ||
default: '443' | ||
enum: [] | ||
basePath: | ||
default: v2.0 | ||
enum: | ||
- v1.0 | ||
- v1.1 | ||
- v1.2 | ||
- v1.3 | ||
otherPath: | ||
default: foo | ||
paths: | ||
/a: | ||
get: | ||
operationId: aget |
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