Skip to content

Commit 46f0f7a

Browse files
feat: migrate parameter named "content-type" is ignored rule
1 parent 555703b commit 46f0f7a

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ enum ApilintCodes {
978978
OPENAPI3_0_PARAMETER_FIELD_IN_REQUIRED,
979979
OPENAPI3_0_PARAMETER_FIELD_IN_EQUALS,
980980
OPENAPI3_0_PARAMETER_FIELD_IN_AUTHORIZATION,
981+
OPENAPI3_0_PARAMETER_FIELD_IN_CONTENT_TYPE,
981982
OPENAPI3_0_PARAMETER_FIELD_DESCRIPTION_TYPE = 5150400,
982983
OPENAPI3_0_PARAMETER_FIELD_REQUIRED_TYPE = 5150500,
983984
OPENAPI3_0_PARAMETER_FIELD_REQUIRED_REQUIRED,
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 inAuthorizationLint = {
7+
code: ApilintCodes.OPENAPI3_0_PARAMETER_FIELD_IN_CONTENT_TYPE,
8+
source: 'apilint',
9+
message:
10+
'Header Parameter named "Content-Type" is ignored. The values for the "Content-Type" header are defined by `requestBody.content.<media-type>`',
11+
severity: DiagnosticSeverity.Warning,
12+
linterParams: ['^(?!\\b(C|c)ontent-(T|t)ype\\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 inAuthorizationLint;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import multipleOfTypeLint from './multiple-of--type.ts';
4444
import inPathTemplateLint from './in-path-template.ts';
4545
import uniqueNameLint from './unique-name.ts';
4646
import inAuthorizationLint from './in--authorization.ts';
47+
import inContentTypeLint from './in--content-type.ts';
4748

4849
const lints = [
4950
nameTypeLint,
@@ -92,6 +93,7 @@ const lints = [
9293
allowedFields3_0Lint,
9394
allowedFields3_1Lint,
9495
inPathTemplateLint,
96+
inContentTypeLint,
9597
];
9698

9799
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: content-type
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
@@ -3767,6 +3767,53 @@ describe('apidom-ls-validate', function () {
37673767
languageService.terminate();
37683768
});
37693769

3770+
it('oas 3.0 / yaml - parameter content-type is ignored', async function () {
3771+
const validationContext: ValidationContext = {
3772+
comments: DiagnosticSeverity.Error,
3773+
maxNumberOfProblems: 100,
3774+
relatedInformation: false,
3775+
};
3776+
3777+
const spec = fs
3778+
.readFileSync(
3779+
path.join(__dirname, 'fixtures', 'validation', 'oas', 'parameter-in-content-type-3-0.yaml'),
3780+
)
3781+
.toString();
3782+
const doc: TextDocument = TextDocument.create(
3783+
'foo://bar/parameter-in-authorization-3-0.yaml',
3784+
'yaml',
3785+
0,
3786+
spec,
3787+
);
3788+
3789+
const languageService: LanguageService = getLanguageService(contextNoSchema);
3790+
3791+
const result = await languageService.doValidation(doc, validationContext);
3792+
const expected: Diagnostic[] = [
3793+
{
3794+
code: 5150304,
3795+
data: {},
3796+
message:
3797+
'Header Parameter named "Content-Type" is ignored. The values for the "Content-Type" header are defined by `requestBody.content.<media-type>`',
3798+
range: {
3799+
end: {
3800+
character: 28,
3801+
line: 12,
3802+
},
3803+
start: {
3804+
character: 16,
3805+
line: 12,
3806+
},
3807+
},
3808+
severity: 2,
3809+
source: 'apilint',
3810+
},
3811+
];
3812+
assert.deepEqual(result, expected as Diagnostic[]);
3813+
3814+
languageService.terminate();
3815+
});
3816+
37703817
it('oas 3.1 / yaml - parameter object should be defined within path template', async function () {
37713818
const validationContext: ValidationContext = {
37723819
comments: DiagnosticSeverity.Error,

0 commit comments

Comments
 (0)