Skip to content

Commit 028ab12

Browse files
feat: migrate parameter named "accept" is ignored rule
1 parent 46f0f7a commit 028ab12

File tree

5 files changed

+97
-2
lines changed

5 files changed

+97
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { DiagnosticSeverity } from 'vscode-languageserver-types';
2+
3+
import { OpenAPI3 } from '../../target-specs.ts';
4+
import ApilintCodes from '../../../codes.ts';
5+
6+
const inAcceptLint = {
7+
code: ApilintCodes.OPENAPI3_0_PARAMETER_FIELD_IN_CONTENT_TYPE,
8+
source: 'apilint',
9+
message:
10+
'Header Parameter named "Accept" is ignored. The values for the "Accept" header are defined by `requestBody.content.<media-type>`',
11+
severity: DiagnosticSeverity.Warning,
12+
linterParams: ['^(?!\\b(A|a)ccept\\b).*$'],
13+
linterFunction: 'apilintValueRegex',
14+
marker: 'value',
15+
target: 'name',
16+
data: {},
17+
conditions: [
18+
{
19+
targets: [
20+
{
21+
path: 'in',
22+
},
23+
],
24+
function: 'apilintContainsValue',
25+
params: ['header'],
26+
},
27+
],
28+
targetSpecs: OpenAPI3,
29+
};
30+
31+
export default inAcceptLint;

packages/apidom-ls/src/config/openapi/parameter/lint/in--content-type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';
33
import { OpenAPI3 } from '../../target-specs.ts';
44
import ApilintCodes from '../../../codes.ts';
55

6-
const inAuthorizationLint = {
6+
const inContentTypeLint = {
77
code: ApilintCodes.OPENAPI3_0_PARAMETER_FIELD_IN_CONTENT_TYPE,
88
source: 'apilint',
99
message:
@@ -28,4 +28,4 @@ const inAuthorizationLint = {
2828
targetSpecs: OpenAPI3,
2929
};
3030

31-
export default inAuthorizationLint;
31+
export default inContentTypeLint;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import inPathTemplateLint from './in-path-template.ts';
4545
import uniqueNameLint from './unique-name.ts';
4646
import inAuthorizationLint from './in--authorization.ts';
4747
import inContentTypeLint from './in--content-type.ts';
48+
import inAcceptLint from './in--accept.ts';
4849

4950
const lints = [
5051
nameTypeLint,
@@ -94,6 +95,7 @@ const lints = [
9495
allowedFields3_1Lint,
9596
inPathTemplateLint,
9697
inContentTypeLint,
98+
inAcceptLint,
9799
];
98100

99101
export default lints;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 1.0.0
4+
title: 'test'
5+
paths:
6+
/:
7+
get:
8+
responses:
9+
default:
10+
description: 'test'
11+
parameters:
12+
- in: header
13+
name: accept
14+
content:
15+
application/xml: {}

packages/apidom-ls/test/validate.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,6 +3814,53 @@ describe('apidom-ls-validate', function () {
38143814
languageService.terminate();
38153815
});
38163816

3817+
it('oas 3.0 / yaml - parameter accept is ignored', async function () {
3818+
const validationContext: ValidationContext = {
3819+
comments: DiagnosticSeverity.Error,
3820+
maxNumberOfProblems: 100,
3821+
relatedInformation: false,
3822+
};
3823+
3824+
const spec = fs
3825+
.readFileSync(
3826+
path.join(__dirname, 'fixtures', 'validation', 'oas', 'parameter-in-accept-3-0.yaml'),
3827+
)
3828+
.toString();
3829+
const doc: TextDocument = TextDocument.create(
3830+
'foo://bar/parameter-in-accept-3-0.yaml',
3831+
'yaml',
3832+
0,
3833+
spec,
3834+
);
3835+
3836+
const languageService: LanguageService = getLanguageService(contextNoSchema);
3837+
3838+
const result = await languageService.doValidation(doc, validationContext);
3839+
const expected: Diagnostic[] = [
3840+
{
3841+
code: 5150304,
3842+
data: {},
3843+
message:
3844+
'Header Parameter named "Accept" is ignored. The values for the "Accept" header are defined by `requestBody.content.<media-type>`',
3845+
range: {
3846+
end: {
3847+
character: 22,
3848+
line: 12,
3849+
},
3850+
start: {
3851+
character: 16,
3852+
line: 12,
3853+
},
3854+
},
3855+
severity: 2,
3856+
source: 'apilint',
3857+
},
3858+
];
3859+
assert.deepEqual(result, expected as Diagnostic[]);
3860+
3861+
languageService.terminate();
3862+
});
3863+
38173864
it('oas 3.1 / yaml - parameter object should be defined within path template', async function () {
38183865
const validationContext: ValidationContext = {
38193866
comments: DiagnosticSeverity.Error,

0 commit comments

Comments
 (0)