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

refactor(ls): scope OpenAPI 3.x.y rules explicitly (batch 4) #3505

Merged
merged 1 commit into from
Dec 5, 2023
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
13 changes: 6 additions & 7 deletions packages/apidom-ls/src/config/openapi/request-body/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CompletionFormat,
CompletionType,
} from '../../../apidom-language-types';
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';

const completion: ApidomCompletionItem[] = [
{
Expand All @@ -16,6 +17,7 @@ const completion: ApidomCompletionItem[] = [
kind: 'markdown',
value: 'A reference to a Request Body.',
},
targetSpecs: OpenAPI3,
},
{
label: 'description',
Expand All @@ -29,6 +31,7 @@ const completion: ApidomCompletionItem[] = [
value:
'A brief description of the request body. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.',
},
targetSpecs: OpenAPI3,
},
{
label: 'content',
Expand All @@ -42,12 +45,7 @@ const completion: ApidomCompletionItem[] = [
value:
'Map[`string`, [Media Type Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#mediaTypeObject)]\n\\\n\\\n**REQUIRED**. The content of the request body. The key is a media type or [media type range](https://tools.ietf.org/html/rfc7231#appendix-D) and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*',
},
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
label: 'content',
Expand All @@ -61,7 +59,7 @@ const completion: ApidomCompletionItem[] = [
value:
'Map[`string`, [Media Type Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject)]\n\\\n\\\n**REQUIRED**. The content of the request body. The key is a media type or [media type range](https://tools.ietf.org/html/rfc7231#appendix-D) and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
{
label: 'required',
Expand All @@ -74,6 +72,7 @@ const completion: ApidomCompletionItem[] = [
kind: 'markdown',
value: 'Determines if the request body is required in the request. Defaults to `false`.',
},
targetSpecs: OpenAPI3,
},
];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
import { OpenAPI30, OpenAPI31, OpenAPI3 } from '../target-specs';

const documentation = [
{
target: 'description',
docs: 'A brief description of the request body. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.',
targetSpecs: OpenAPI3,
},
{
target: 'content',
docs: 'Map[`string`, [Media Type Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#mediaTypeObject)]\n\\\n\\\n**REQUIRED**. The content of the request body. The key is a media type or [media type range](https://tools.ietf.org/html/rfc7231#appendix-D) and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*',
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
target: 'content',
docs: 'Map[`string`, [Media Type Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject)]\n\\\n\\\n**REQUIRED**. The content of the request body. The key is a media type or [media type range](https://tools.ietf.org/html/rfc7231#appendix-D) and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*',
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
{
target: 'required',
docs: 'Determines if the request body is required in the request. Defaults to `false`.',
targetSpecs: OpenAPI3,
},
{
docs: '#### [Request Body Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#requestBodyObject)\n\nDescribes a single request body.\n\n##### Fixed Fields\nField Name | Type | Description\n---|:---:|---\ndescription | `string` | A brief description of the request body. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.\ncontent | Map[`string`, [Media Type Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#mediaTypeObject)] | **REQUIRED**. The content of the request body. The key is a media type or [media type range](https://tools.ietf.org/html/rfc7231#appendix-D) and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*\nrequired | `boolean` | Determines if the request body is required in the request. Defaults to `false`.\n\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##### Request Body Examples\n\nA request body with a referenced model definition.\n\n\\\nJSON\n```json\n{\n "description": "user to add to the system",\n "content": {\n "application/json": {\n "schema": {\n "$ref": "#/components/schemas/User"\n },\n "examples": {\n "user" : {\n "summary": "User Example",\n "externalValue": "http://foo.bar/examples/user-example.json"\n }\n }\n },\n "application/xml": {\n "schema": {\n "$ref": "#/components/schemas/User"\n },\n "examples": {\n "user" : {\n "summary": "User example in XML",\n "externalValue": "http://foo.bar/examples/user-example.xml"\n }\n }\n },\n "text/plain": {\n "examples": {\n "user" : {\n "summary": "User example in Plain text",\n "externalValue": "http://foo.bar/examples/user-example.txt"\n }\n }\n },\n "*/*": {\n "examples": {\n "user" : {\n "summary": "User example in other format",\n "externalValue": "http://foo.bar/examples/user-example.whatever"\n }\n }\n }\n }\n}\n```\n\n\n\\\nYAML\n```yaml\ndescription: user to add to the system\ncontent:\n \'application/json\':\n schema:\n $ref: \'#/components/schemas/User\'\n examples:\n user:\n summary: User Example\n externalValue: \'http://foo.bar/examples/user-example.json\'\n \'application/xml\':\n schema:\n $ref: \'#/components/schemas/User\'\n examples:\n user:\n summary: User Example in XML\n externalValue: \'http://foo.bar/examples/user-example.xml\'\n \'text/plain\':\n examples:\n user:\n summary: User example in text plain format\n externalValue: \'http://foo.bar/examples/user-example.txt\'\n \'*/*\':\n examples:\n user:\n summary: User example in other format\n externalValue: \'http://foo.bar/examples/user-example.whatever\'\n```\n\nA body parameter that is an array of string values:\n```json\n{\n "description": "user to add to the system",\n "content": {\n "text/plain": {\n "schema": {\n "type": "array",\n "items": {\n "type": "string"\n }\n }\n }\n }\n}\n```\n\n```yaml\ndescription: user to add to the system\nrequired: true\ncontent:\n text/plain:\n schema:\n type: array\n items:\n type: string\n```',
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
},
{
docs: '#### [Request Body Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#requestBodyObject)\n\nDescribes a single request body.\n\n##### Fixed Fields\nField Name | Type | Description\n---|:---:|---\ndescription | `string` | A brief description of the request body. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.\ncontent | Map[`string`, [Media Type Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject)] | **REQUIRED**. The content of the request body. The key is a media type or [media type range](https://tools.ietf.org/html/rfc7231#appendix-D) and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*\nrequired | `boolean` | Determines if the request body is required in the request. Defaults to `false`.\n\n\\\nThis object MAY be extended with [Specification Extensions](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions).\n\n##### Request Body Examples\n\nA request body with a referenced model definition.\n\n\\\nJSON\n```json\n{\n "description": "user to add to the system",\n "content": {\n "application/json": {\n "schema": {\n "$ref": "#/components/schemas/User"\n },\n "examples": {\n "user" : {\n "summary": "User Example", \n "externalValue": "https://foo.bar/examples/user-example.json"\n } \n }\n },\n "application/xml": {\n "schema": {\n "$ref": "#/components/schemas/User"\n },\n "examples": {\n "user" : {\n "summary": "User example in XML",\n "externalValue": "https://foo.bar/examples/user-example.xml"\n }\n }\n },\n "text/plain": {\n "examples": {\n "user" : {\n "summary": "User example in Plain text",\n "externalValue": "https://foo.bar/examples/user-example.txt" \n }\n } \n },\n "*/*": {\n "examples": {\n "user" : {\n "summary": "User example in other format",\n "externalValue": "https://foo.bar/examples/user-example.whatever"\n }\n }\n }\n }\n}\n```\n\n\n\\\nYAML\n```yaml\ndescription: user to add to the system\ncontent: \n \'application/json\':\n schema:\n $ref: \'#/components/schemas/User\'\n examples:\n user:\n summary: User Example\n externalValue: \'https://foo.bar/examples/user-example.json\'\n \'application/xml\':\n schema:\n $ref: \'#/components/schemas/User\'\n examples:\n user:\n summary: User example in XML\n externalValue: \'https://foo.bar/examples/user-example.xml\'\n \'text/plain\':\n examples:\n user:\n summary: User example in Plain text\n externalValue: \'https://foo.bar/examples/user-example.txt\'\n \'*/*\':\n examples:\n user: \n summary: User example in other format\n externalValue: \'https://foo.bar/examples/user-example.whatever\'\n```\n\nA body parameter that is an array of string values:\n```json\n{\n "description": "user to add to the system",\n "required": true,\n "content": {\n "text/plain": {\n "schema": {\n "type": "array",\n "items": {\n "type": "string"\n }\n }\n }\n }\n}\n```\n\n```yaml\ndescription: user to add to the system\nrequired: true\ncontent:\n text/plain:\n schema:\n type: array\n items:\n type: string\n```',
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DiagnosticSeverity } from 'vscode-languageserver-types';

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

// eslint-disable-next-line @typescript-eslint/naming-convention
const allowedFields3_0Lint: LinterMeta = {
Expand All @@ -12,12 +13,7 @@ const allowedFields3_0Lint: LinterMeta = {
linterFunction: 'allowedFields',
linterParams: [['description', 'content', 'required', '$ref'], 'x-'],
marker: 'key',
targetSpecs: [
{ namespace: 'openapi', version: '3.0.0' },
{ namespace: 'openapi', version: '3.0.1' },
{ namespace: 'openapi', version: '3.0.2' },
{ namespace: 'openapi', version: '3.0.3' },
],
targetSpecs: OpenAPI30,
};

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

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

// eslint-disable-next-line @typescript-eslint/naming-convention
const allowedFields3_0Lint: LinterMeta = {
Expand All @@ -18,7 +19,7 @@ const allowedFields3_0Lint: LinterMeta = {
params: ['$ref'],
},
],
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
targetSpecs: OpenAPI31,
};

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

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

const requiredRequiredLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_REQUEST_BODY_FIELD_CONTENT_REQUIRED,
Expand All @@ -27,6 +28,7 @@ const requiredRequiredLint: LinterMeta = {
params: ['$ref'],
},
],
targetSpecs: OpenAPI3,
};

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

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

const contentValuesTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_REQUEST_BODY_FIELD_CONTENT_VALUES_TYPE,
Expand All @@ -14,6 +15,7 @@ const contentValuesTypeLint: LinterMeta = {
markerTarget: 'content',
target: 'content',
data: {},
targetSpecs: OpenAPI3,
};

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

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

const descriptionTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_REQUEST_BODY_FIELD_DESCRIPTION_TYPE,
Expand All @@ -13,6 +14,7 @@ const descriptionTypeLint: LinterMeta = {
marker: 'value',
target: 'description',
data: {},
targetSpecs: OpenAPI3,
};

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

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

const requiredTypeLint: LinterMeta = {
code: ApilintCodes.OPENAPI3_0_REQUEST_BODY_FIELD_REQUIRED_TYPE,
Expand All @@ -13,6 +14,7 @@ const requiredTypeLint: LinterMeta = {
marker: 'value',
target: 'required',
data: {},
targetSpecs: OpenAPI3,
};

export default requiredTypeLint;
Loading