Skip to content

Commit

Permalink
feat(ls): provide OpenAPI 3.1.0 lint and completion for Link object (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-lai authored Oct 27, 2022
1 parent 50baf52 commit beb02b9
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
62 changes: 62 additions & 0 deletions packages/apidom-ls/src/config/openapi/link/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ const completion: ApidomCompletionItem[] = [
{ namespace: 'openapi', version: '3.0.3' },
],
},
{
label: 'operationRef',
insertText: 'operationRef',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'A relative or absolute URI reference to an OAS operation. This field is mutually exclusive of the `operationId` field, and MUST point to an [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject). Relative `operationRef` values MAY be used to locate an existing [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject) in the OpenAPI definition. See the rules for resolving [Relative References](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#relativeReferencesURI).',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
},
{
label: 'operationId',
insertText: 'operationId',
Expand Down Expand Up @@ -68,6 +82,20 @@ const completion: ApidomCompletionItem[] = [
{ namespace: 'openapi', version: '3.0.3' },
],
},
{
label: 'parameters',
insertText: 'parameters',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'Map[`string`, Any | [`{expression}`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#runtimeExpression)]\n\\\n\\\nA map representing parameters to pass to an operation as specified with `operationId` or identified via `operationRef`. The key is the parameter name to be used, whereas the value can be a constant or an expression to be evaluated and passed to the linked operation. The parameter name can be qualified using the [parameter location](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterIn) `[{in}.]{name}` for operations that use the same parameter name in different locations (e.g. path.id).',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
},
{
label: 'requestBody',
insertText: 'requestBody',
Expand All @@ -87,6 +115,20 @@ const completion: ApidomCompletionItem[] = [
{ namespace: 'openapi', version: '3.0.3' },
],
},
{
label: 'requestBody',
insertText: 'requestBody',
kind: 14,
format: CompletionFormat.QUOTED,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'Any | [`{expression}`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#runtimeExpression)\n\\\n\\\nA literal value or [`{expression}`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#runtimeExpression) to use as a request body when calling the target operation.',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
},
{
label: 'description',
insertText: 'description',
Expand All @@ -112,6 +154,26 @@ const completion: ApidomCompletionItem[] = [
value:
'[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject)\n\\\n\\\nA server object to be used by the target operation.',
},
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' },
],
},
{
label: 'server',
insertText: 'server',
kind: 14,
format: CompletionFormat.OBJECT,
type: CompletionType.PROPERTY,
insertTextFormat: 2,
documentation: {
kind: 'markdown',
value:
'[Server Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#serverObject)\n\\\n\\\nA server object to be used by the target operation.',
},
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
},
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import ApilintCodes from '../../../codes';
import { LinterMeta } from '../../../../apidom-language-types';

// eslint-disable-next-line @typescript-eslint/naming-convention
const allowedFields3_1Lint: LinterMeta = {
code: ApilintCodes.NOT_ALLOWED_FIELDS,
source: 'apilint',
message: 'Object includes not allowed fields',
severity: 1,
linterFunction: 'allowedFields',
linterParams: [
['operationRef', 'operationId', 'parameters', 'requestBody', 'description', 'server'],
'x-',
],
marker: 'key',
conditions: [
{
function: 'missingField',
params: ['$ref'],
},
],
targetSpecs: [{ namespace: 'openapi', version: '3.1.0' }],
};
export default allowedFields3_1Lint;
2 changes: 2 additions & 0 deletions packages/apidom-ls/src/config/openapi/link/lint/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import allowedFields3_0Lint from './allowed-fields-3-0';
import allowedFields3_1Lint from './allowed-fields-3-1';
import operationRefFormatUriLink from './operation-ref--format-uri';
import operationIdTypeLint from './operation-id--type';
import descriptionTypeLint from './description--type';
Expand All @@ -10,6 +11,7 @@ const links = [
descriptionTypeLint,
serverTypeLint,
allowedFields3_0Lint,
allowedFields3_1Lint,
];

export default links;

1 comment on commit beb02b9

@char0n
Copy link
Member

@char0n char0n commented on beb02b9 Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've notice that requestBody was of type QUOTED, but should be OBJECT. Following PR remedies this: #2207

Please sign in to comment.