Skip to content

Commit 0fa98c8

Browse files
feat(ls): add OpenAPI 3.x validation for Paramter.style fixed field (#4955)
Closes #2355
1 parent b9fc150 commit 0fa98c8

File tree

5 files changed

+63
-9
lines changed

5 files changed

+63
-9
lines changed

packages/apidom-ls/src/config/codes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ enum ApilintCodes {
982982
OPENAPI3_0_PARAMETER_FIELD_REQUIRED_EQUALS,
983983
OPENAPI3_0_PARAMETER_FIELD_DEPRECATED_TYPE = 5150600,
984984
OPENAPI3_0_PARAMETER_FIELD_ALLOW_EMPTY_VALUE_TYPE = 5150700,
985-
OPENAPI3_0_PARAMETER_FIELD_STYLE_TYPE = 5150800,
985+
OPENAPI3_0_PARAMETER_FIELD_STYLE_EQUALS = 5150800,
986986
OPENAPI3_0_PARAMETER_FIELD_EXPLODE_TYPE = 5150900,
987987
OPENAPI3_0_PARAMETER_FIELD_ALLOW_RESERVED_TYPE = 5151000,
988988
OPENAPI3_0_PARAMETER_FIELD_SCHEMA_TYPE = 5151100,

packages/apidom-ls/src/config/openapi/parameter/lint/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import requiredRequiredLint from './required--required.ts';
1414
import requiredEqualsLint from './required--equals.ts';
1515
import deprecatedTypeLint from './deprecated--type.ts';
1616
import allowEmptyValueTypeLint from './allow-empty-value--type.ts';
17-
import styleTypeLint from './style--type.ts';
17+
import styleEqualsLint from './style--equals.ts';
1818
import explodeTypeLint from './explode--type.ts';
1919
import allowReservedTypeLint from './allow-reserved--type.ts';
2020
import schemaTypeLint from './schema--type.ts';
@@ -56,7 +56,7 @@ const lints = [
5656
requiredEqualsLint,
5757
deprecatedTypeLint,
5858
allowEmptyValueTypeLint,
59-
styleTypeLint,
59+
styleEqualsLint,
6060
explodeTypeLint,
6161
allowReservedTypeLint,
6262
schemaTypeLint,

packages/apidom-ls/src/config/openapi/parameter/lint/style--type.ts renamed to packages/apidom-ls/src/config/openapi/parameter/lint/style--equals.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import ApilintCodes from '../../../codes.ts';
44
import { LinterMeta } from '../../../../apidom-language-types.ts';
55
import { OpenAPI3 } from '../../target-specs.ts';
66

7-
const styleTypeLint: LinterMeta = {
8-
code: ApilintCodes.OPENAPI3_0_PARAMETER_FIELD_STYLE_TYPE,
7+
const styleEqualsLint: LinterMeta = {
8+
code: ApilintCodes.OPENAPI3_0_PARAMETER_FIELD_STYLE_EQUALS,
99
source: 'apilint',
10-
message: 'style must be a string',
10+
message: 'style must be one of allowed values: form, simple',
1111
severity: DiagnosticSeverity.Error,
12-
linterFunction: 'apilintType',
13-
linterParams: ['string'],
12+
linterFunction: 'apilintValueOrArray',
13+
linterParams: [['form', 'simple']],
1414
marker: 'value',
1515
target: 'style',
1616
data: {},
1717
targetSpecs: OpenAPI3,
1818
};
1919

20-
export default styleTypeLint;
20+
export default styleEqualsLint;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
openapi: 3.1.0
2+
info:
3+
title: Foo
4+
version: 0.1.0
5+
paths:
6+
/foo/find:
7+
get:
8+
parameters:
9+
- name: fooId
10+
in: query
11+
schema:
12+
type: string
13+
style: label
14+
- name: name
15+
in: query
16+
schema:
17+
type: string
18+
style: simple
19+
- name: status
20+
in: query
21+
schema:
22+
type: string
23+
style: form

packages/apidom-ls/test/validate.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,4 +3757,35 @@ describe('apidom-ls-validate', function () {
37573757

37583758
languageService.terminate();
37593759
});
3760+
3761+
it('oas - parameters style should allow only "simple" and "form" values', async function () {
3762+
const spec = fs
3763+
.readFileSync(
3764+
path.join(__dirname, 'fixtures', 'validation', 'sample-api-validation-parameters.yaml'),
3765+
)
3766+
.toString();
3767+
const doc: TextDocument = TextDocument.create(
3768+
'foo://bar/sample-api-validation-parameters.yaml',
3769+
'yaml',
3770+
0,
3771+
spec,
3772+
);
3773+
3774+
const languageService: LanguageService = getLanguageService(contextNoSchema);
3775+
3776+
const result = await languageService.doValidation(doc);
3777+
const expected: Diagnostic[] = [
3778+
{
3779+
message: 'style must be one of allowed values: form, simple',
3780+
severity: 1,
3781+
code: 5150800,
3782+
source: 'apilint',
3783+
data: {},
3784+
range: { start: { line: 12, character: 17 }, end: { line: 12, character: 22 } },
3785+
},
3786+
];
3787+
assert.deepEqual(result, expected);
3788+
3789+
languageService.terminate();
3790+
});
37603791
});

0 commit comments

Comments
 (0)