Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ls): add rules for OpenAPI 2.0 External Documentation Object #3593

Merged
merged 1 commit into from
Jan 1, 2024
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
5 changes: 5 additions & 0 deletions packages/apidom-ls/src/config/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,11 @@ enum ApilintCodes {
OPENAPI2_OPERATION_FIELD_SECURITY_TYPE = 3081300,
OPENAPI2_OPERATION_FIELD_SECURITY_ITEMS_TYPE,

OPENAPI2_EXTERNAL_DOCUMENTATION = 3090000,
OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_DESCRIPTION_TYPE = 3090100,
OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_URL_FORMAT_URI = 3090200,
OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_URL_REQUIRED,

OPENAPI3_0 = 5000000,

OPENAPI3_0_OPENAPI_VALUE_PATTERN_3_0_0 = 5000100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@ import {
CompletionFormat,
CompletionType,
} from '../../../apidom-language-types';
import { OpenAPI3 } from '../target-specs';
import { OpenAPI2, OpenAPI3 } from '../target-specs';

const completion: ApidomCompletionItem[] = [
{
label: 'description',
insertText: 'description',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'A short description of the target documentation. [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) can be used for rich text representation.',
},
targetSpecs: OpenAPI2,
},
{
label: 'description',
insertText: 'description',
Expand All @@ -20,6 +34,20 @@ const completion: ApidomCompletionItem[] = [
},
targetSpecs: OpenAPI3,
},
{
label: 'url',
insertText: 'url',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'**Required.** The URL for the target documentation. Value MUST be in the format of a URL.',
},
targetSpecs: OpenAPI2,
},
{
label: 'url',
insertText: 'url',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';
import { OpenAPI2, OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';

const documentation = [
{
target: 'description',
docs: 'A short description of the target documentation. [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) can be used for rich text representation.',
targetSpecs: OpenAPI2,
},
{
target: 'description',
docs: 'A description of the target documentation. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.',
targetSpecs: OpenAPI3,
},
{
target: 'url',
docs: '**Required.** The URL for the target documentation. Value MUST be in the format of a URL.',
targetSpecs: OpenAPI2,
},
{
target: 'url',
docs: '**REQUIRED**. The URL for the target documentation. This MUST be in the form of a URL.',
targetSpecs: OpenAPI3,
},
{
docs: '#### [External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#external-documentation-object)\n\nAllows referencing an external resource for extended documentation.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\ndescription | `string` | A short description of the target documentation. [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) can be used for rich text representation.\nurl | `string` | **Required.** The URL for the target documentation. Value MUST be in the format of a URL.\n\n##### Patterned Objects\n\nField Pattern | Type | Description\n---|:---:|---\n^x- | Any | Allows extensions to the Swagger Schema. The field name MUST begin with `x-`, for example, `x-internal-id`. The value can be `null`, a primitive, an array or an object. See [Vendor Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#vendorExtensions) for further details.\n\n##### External Documentation Object Example\n\n```js\n{\n "description": "Find more info here",\n "url": "https://swagger.io"\n}\n```\n\n\n\\\nYAML\n```yaml\ndescription: Find more info here\nurl: https://swagger.io\n```',
targetSpecs: OpenAPI2,
},
{
docs: '#### [External Documentation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#externalDocumentationObject)\n\nAllows referencing an external resource for extended documentation.\n\n##### Fixed Fields\n\nField Name | Type | Description\n---|:---:|---\ndescription | `string` | A short description of the target documentation. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.\nurl | `string` | **REQUIRED**. The URL for the target documentation. Value MUST be in the format of a URL.\n\nThis object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions).\n\n##### External Documentation Object Example\n\n\n\\\nJSON\n```json\n{\n "description": "Find more info here",\n "url": "https://example.com"\n}\n```\n\n\n\\\nYAML\n```yaml\ndescription: Find more info here\nurl: https://example.com\n```',
targetSpecs: OpenAPI30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';
import { OpenAPI2, OpenAPI3 } from '../../target-specs';

const allowedFieldsLint: LinterMeta = {
code: ApilintCodes.NOT_ALLOWED_FIELDS,
Expand All @@ -12,7 +12,7 @@ const allowedFieldsLint: LinterMeta = {
linterFunction: 'allowedFields',
linterParams: [['description', 'url'], 'x-'],
marker: 'key',
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default allowedFieldsLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';
import { OpenAPI2, OpenAPI3 } from '../../target-specs';

const descriptionTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_EXTERNAL_DOCUMENTATION_FIELD_DESCRIPTION_TYPE,
code: ApilintCodes.OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_DESCRIPTION_TYPE,
source: 'apilint',
message: "'description' must be a string",
severity: DiagnosticSeverity.Error,
Expand All @@ -14,7 +14,7 @@ const descriptionTypeLint: LinterMeta = {
marker: 'value',
target: 'description',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default descriptionTypeLint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';
import { OpenAPI2, OpenAPI3 } from '../../target-specs';

const urlFormatURILint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_EXTERNAL_DOCUMENTATION_FIELD_URL_FORMAT_URI,
code: ApilintCodes.OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_URL_FORMAT_URI,
source: 'apilint',
message: "'url' value must be a valid URL",
severity: DiagnosticSeverity.Error,
linterFunction: 'apilintValidURI',
marker: 'value',
target: 'url',
data: {},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default urlFormatURILint;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';
import { OpenAPI3 } from '../../target-specs';
import { OpenAPI2, OpenAPI3 } from '../../target-specs';

const urlRequiredLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_EXTERNAL_DOCUMENTATION_FIELD_URL_REQUIRED,
code: ApilintCodes.OPENAPI2_EXTERNAL_DOCUMENTATION_FIELD_URL_REQUIRED,
source: 'apilint',
message: "should always have an 'url'",
severity: DiagnosticSeverity.Error,
Expand All @@ -22,7 +22,7 @@ const urlRequiredLint: LinterMeta = {
},
],
},
targetSpecs: OpenAPI3,
targetSpecs: [...OpenAPI2, ...OpenAPI3],
};

export default urlRequiredLint;