Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const $ref3RequestBodiesLint: LinterMeta = {
{
targets: [{ path: '$ref' }],
function: 'apilintValueRegex',
params: ['^(?!.*#/components/schemas).*$'],
params: ['^(?!.*#/components/schemas)(#/).*$'],
},
],
marker: 'value',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const $ref3HeaderNamingLint: LinterMeta = {
{
targets: [{ path: '$ref' }],
function: 'apilintValueRegex',
params: ['^(?!.*#/components/headers).*$'],
params: ['^(?!.*#/components/headers)(#/).*$'],
},
],
marker: 'value',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const $ref3ParameterNamingLint: LinterMeta = {
function: 'parentExistFields',
params: [['paths']],
},
{
targets: [{ path: '$ref' }],
function: 'apilintValueRegex',
params: ['^(#/).*$'],
},
],
data: {},
targetSpecs: OpenAPI30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const $ref3RequestBodiesNamingSchemaLint: LinterMeta = {
{
targets: [{ path: '$ref' }],
function: 'apilintValueRegex',
params: ['^(.*#/components/schemas).*$'],
params: ['^(.*#/components/schemas)(?!#/).*$'],
},
],
marker: 'value',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const $ref3RequestBodiesNamingLint: LinterMeta = {
{
targets: [{ path: '$ref' }],
function: 'apilintValueRegex',
params: ['^(?!.*#/components/(requestBodies|schemas)).*$'],
params: ['^(?!.*#/components/(requestBodies|schemas))(#/).*$'],
},
],
marker: 'value',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
openapi: 3.0.0
info:
version: 1.0.0
title: 'test'
paths:
/foo:
get:
responses:
'200':
description: OK
headers:
X-MyHeader:
$ref: 'https://api.github.com/users/github/orgs'
components:
headers:
MyHeader:
description: ID of the user
required: true
schema:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
openapi: 3.0.0
info:
version: 1.0.0
title: 'test'
paths:
/foo:
parameters:
- $ref: 'https://api.github.com/users/github/orgs'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
openapi: 3.0.0
info:
version: 1.0.0
title: 'test'
paths:
/:
post:
responses:
default:
description: 'test'
operationId: myId
requestBody:
content:
application/json:
schema:
$ref: 'https://api.github.com/users/github/orgs'
components:
requestBodies:
MyBody:
content:
application/json:
schema:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
openapi: 3.0.0
info:
version: 1.0.0
title: 'test'
paths:
/:
post:
responses:
default:
description: 'test'
operationId: myId
requestBody:
$ref: 'https://api.github.com/users/github/orgs'
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
openapi: 3.0.0
info:
version: 1.0.0
title: 'test'
paths:
/:
post:
responses:
default:
description: 'test'
operationId: myId
requestBody:
$ref: 'https://api.github.com/users/github/orgs'
components:
requestBodies:
MyBody:
content:
application/json:
schema:
type: string
148 changes: 148 additions & 0 deletions packages/apidom-ls/test/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3112,6 +3112,33 @@ describe('apidom-ls-validate', function () {
languageService.terminate();
});

it('oas 3.0 / yaml - requestBody $refs must point to a position where can be legally placed should not be reported against external refs', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
maxNumberOfProblems: 100,
relatedInformation: false,
};

const spec = fs
.readFileSync(
path.join(__dirname, 'fixtures', 'validation', 'oas', 'ref-request-bodies-external.yaml'),
)
.toString();
const doc: TextDocument = TextDocument.create(
'foo://bar/ref-request-bodies-external.yaml',
'yaml',
0,
spec,
);

const languageService: LanguageService = getLanguageService(contextNoSchema);

const result = await languageService.doValidation(doc, validationContext);
assert.deepEqual(result, []);

languageService.terminate();
});

it('oas 3.0 / yaml - requestBody $refs must point to a position naming', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
Expand Down Expand Up @@ -3168,6 +3195,40 @@ describe('apidom-ls-validate', function () {
languageService.terminate();
});

it('oas 3.0 / yaml - requestBody $refs must point to a position naming should not be reported against external refs', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
maxNumberOfProblems: 100,
relatedInformation: false,
};

const spec = fs
.readFileSync(
path.join(
__dirname,
'fixtures',
'validation',
'oas',
'ref-request-bodies-naming-external.yaml',
),
)
.toString();
const doc: TextDocument = TextDocument.create(
'foo://bar/ref-request-bodies-naming-external.yaml',
'yaml',
0,
spec,
);

const languageService: LanguageService = getLanguageService(contextNoSchema);

const result = await languageService.doValidation(doc, validationContext);

assert.deepEqual(result, []);

languageService.terminate();
});

it('oas 3.0 / yaml - requestBody $refs must point to a position naming schema', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
Expand Down Expand Up @@ -3230,6 +3291,39 @@ describe('apidom-ls-validate', function () {
languageService.terminate();
});

it('oas 3.0 / yaml - requestBody $refs must point to a position naming schema should not be reported against external refs', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
maxNumberOfProblems: 100,
relatedInformation: false,
};

const spec = fs
.readFileSync(
path.join(
__dirname,
'fixtures',
'validation',
'oas',
'ref-request-bodies-naming-schema-external.yaml',
),
)
.toString();
const doc: TextDocument = TextDocument.create(
'foo://bar/ref-request-bodies-naming-schema-external.yaml',
'yaml',
0,
spec,
);

const languageService: LanguageService = getLanguageService(contextNoSchema);

const result = await languageService.doValidation(doc, validationContext);
assert.deepEqual(result, []);

languageService.terminate();
});

it('oas 3.0 / yaml - OAS3 header $Ref should point to Header Object', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
Expand Down Expand Up @@ -3296,6 +3390,33 @@ describe('apidom-ls-validate', function () {
languageService.terminate();
});

it('oas 3.0 / yaml - OAS3 header $Ref should point to Header Object should not be reported against external refs', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
maxNumberOfProblems: 100,
relatedInformation: false,
};

const spec = fs
.readFileSync(
path.join(__dirname, 'fixtures', 'validation', 'oas', 'ref-header-external.yaml'),
)
.toString();
const doc: TextDocument = TextDocument.create(
'foo://bar/ref-header-external.yaml',
'yaml',
0,
spec,
);

const languageService: LanguageService = getLanguageService(contextNoSchema);
const result = await languageService.doValidation(doc, validationContext);

assert.deepEqual(result, []);

languageService.terminate();
});

it('oas 3.0 / yaml - OAS3 parameter $Ref should point to Parameter Object', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
Expand Down Expand Up @@ -3356,6 +3477,33 @@ describe('apidom-ls-validate', function () {
languageService.terminate();
});

it('oas 3.0 / yaml - OAS3 parameter $Ref should point to Parameter Object should not be reported against external refs', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
maxNumberOfProblems: 100,
relatedInformation: false,
};

const spec = fs
.readFileSync(
path.join(__dirname, 'fixtures', 'validation', 'oas', 'ref-parameter-external.yaml'),
)
.toString();
const doc: TextDocument = TextDocument.create(
'foo://bar/ref-parameter-external.yaml',
'yaml',
0,
spec,
);

const languageService: LanguageService = getLanguageService(contextNoSchema);
const result = await languageService.doValidation(doc, validationContext);

assert.deepEqual(result, []);

languageService.terminate();
});

it('oas / yaml - test editor issue 3626 / inidrect ref', async function () {
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
Expand Down