diff --git a/packages/apidom-ls/src/config/common/schema/lint/$ref-3-0--request-bodies.ts b/packages/apidom-ls/src/config/common/schema/lint/$ref-3-0--request-bodies.ts index e51654d9e..361b8b865 100644 --- a/packages/apidom-ls/src/config/common/schema/lint/$ref-3-0--request-bodies.ts +++ b/packages/apidom-ls/src/config/common/schema/lint/$ref-3-0--request-bodies.ts @@ -16,7 +16,7 @@ const $ref3RequestBodiesLint: LinterMeta = { { targets: [{ path: '$ref' }], function: 'apilintValueRegex', - params: ['^(?!.*#/components/schemas).*$'], + params: ['^(?!.*#/components/schemas)(#/).*$'], }, ], marker: 'value', diff --git a/packages/apidom-ls/src/config/openapi/header/lint/$ref-3-0--header.ts b/packages/apidom-ls/src/config/openapi/header/lint/$ref-3-0--header.ts index fc0a9d7f3..2760945d8 100644 --- a/packages/apidom-ls/src/config/openapi/header/lint/$ref-3-0--header.ts +++ b/packages/apidom-ls/src/config/openapi/header/lint/$ref-3-0--header.ts @@ -15,7 +15,7 @@ const $ref3HeaderNamingLint: LinterMeta = { { targets: [{ path: '$ref' }], function: 'apilintValueRegex', - params: ['^(?!.*#/components/headers).*$'], + params: ['^(?!.*#/components/headers)(#/).*$'], }, ], marker: 'value', diff --git a/packages/apidom-ls/src/config/openapi/parameter/lint/$ref-3-0--parameter.ts b/packages/apidom-ls/src/config/openapi/parameter/lint/$ref-3-0--parameter.ts index ef82446f2..fc0f0d091 100644 --- a/packages/apidom-ls/src/config/openapi/parameter/lint/$ref-3-0--parameter.ts +++ b/packages/apidom-ls/src/config/openapi/parameter/lint/$ref-3-0--parameter.ts @@ -19,6 +19,11 @@ const $ref3ParameterNamingLint: LinterMeta = { function: 'parentExistFields', params: [['paths']], }, + { + targets: [{ path: '$ref' }], + function: 'apilintValueRegex', + params: ['^(#/).*$'], + }, ], data: {}, targetSpecs: OpenAPI30, diff --git a/packages/apidom-ls/src/config/openapi/request-body/lint/$ref-3-0--request-bodies-naming-schema.ts b/packages/apidom-ls/src/config/openapi/request-body/lint/$ref-3-0--request-bodies-naming-schema.ts index f45d1560a..1a4753464 100644 --- a/packages/apidom-ls/src/config/openapi/request-body/lint/$ref-3-0--request-bodies-naming-schema.ts +++ b/packages/apidom-ls/src/config/openapi/request-body/lint/$ref-3-0--request-bodies-naming-schema.ts @@ -16,7 +16,7 @@ const $ref3RequestBodiesNamingSchemaLint: LinterMeta = { { targets: [{ path: '$ref' }], function: 'apilintValueRegex', - params: ['^(.*#/components/schemas).*$'], + params: ['^(.*#/components/schemas)(?!#/).*$'], }, ], marker: 'value', diff --git a/packages/apidom-ls/src/config/openapi/request-body/lint/$ref-3-0--request-bodies-naming.ts b/packages/apidom-ls/src/config/openapi/request-body/lint/$ref-3-0--request-bodies-naming.ts index 734be287c..cf34c047e 100644 --- a/packages/apidom-ls/src/config/openapi/request-body/lint/$ref-3-0--request-bodies-naming.ts +++ b/packages/apidom-ls/src/config/openapi/request-body/lint/$ref-3-0--request-bodies-naming.ts @@ -15,7 +15,7 @@ const $ref3RequestBodiesNamingLint: LinterMeta = { { targets: [{ path: '$ref' }], function: 'apilintValueRegex', - params: ['^(?!.*#/components/(requestBodies|schemas)).*$'], + params: ['^(?!.*#/components/(requestBodies|schemas))(#/).*$'], }, ], marker: 'value', diff --git a/packages/apidom-ls/test/fixtures/validation/oas/ref-header-external.yaml b/packages/apidom-ls/test/fixtures/validation/oas/ref-header-external.yaml new file mode 100644 index 000000000..ea0845727 --- /dev/null +++ b/packages/apidom-ls/test/fixtures/validation/oas/ref-header-external.yaml @@ -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 diff --git a/packages/apidom-ls/test/fixtures/validation/oas/ref-parameter-external.yaml b/packages/apidom-ls/test/fixtures/validation/oas/ref-parameter-external.yaml new file mode 100644 index 000000000..dd778d433 --- /dev/null +++ b/packages/apidom-ls/test/fixtures/validation/oas/ref-parameter-external.yaml @@ -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' diff --git a/packages/apidom-ls/test/fixtures/validation/oas/ref-request-bodies-external.yaml b/packages/apidom-ls/test/fixtures/validation/oas/ref-request-bodies-external.yaml new file mode 100644 index 000000000..c9953275d --- /dev/null +++ b/packages/apidom-ls/test/fixtures/validation/oas/ref-request-bodies-external.yaml @@ -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 diff --git a/packages/apidom-ls/test/fixtures/validation/oas/ref-request-bodies-naming-external.yaml b/packages/apidom-ls/test/fixtures/validation/oas/ref-request-bodies-naming-external.yaml new file mode 100644 index 000000000..6835a2a87 --- /dev/null +++ b/packages/apidom-ls/test/fixtures/validation/oas/ref-request-bodies-naming-external.yaml @@ -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' diff --git a/packages/apidom-ls/test/fixtures/validation/oas/ref-request-bodies-naming-schema-external.yaml b/packages/apidom-ls/test/fixtures/validation/oas/ref-request-bodies-naming-schema-external.yaml new file mode 100644 index 000000000..b8f09210f --- /dev/null +++ b/packages/apidom-ls/test/fixtures/validation/oas/ref-request-bodies-naming-schema-external.yaml @@ -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 diff --git a/packages/apidom-ls/test/validate.ts b/packages/apidom-ls/test/validate.ts index 70b6fa1e8..07ca49108 100644 --- a/packages/apidom-ls/test/validate.ts +++ b/packages/apidom-ls/test/validate.ts @@ -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, @@ -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, @@ -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, @@ -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, @@ -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,