Skip to content

Commit

Permalink
feat(ls): add missing OpenAPI 2.0 semantic tokens (#3508)
Browse files Browse the repository at this point in the history
Refs #3477
  • Loading branch information
char0n authored Dec 5, 2023
1 parent c89dab3 commit 4ffce6f
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 85 deletions.
12 changes: 12 additions & 0 deletions packages/apidom-ls/src/config/ads/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const tokens = [
'main',
'info',
'principle',
'standard',
'standardIdentifier',
'requirement',
'requirementLevel',
'scenario',
];

export default tokens;
45 changes: 45 additions & 0 deletions packages/apidom-ls/src/config/asyncapi/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const tokens = [
'parameter',
'api-version',
'spec-version',
'info',
'operation',
'components',
'components-parameters',
'components-schemas',
'components-security-schemes',
'components-messageTraits',
'components-operationTraits',
'components-messages',
'schema',
'server',
'servers',
'server-variables',
'channelItem',
'channels',
'reference-element',
'reference-value',
'channel-binding',
'license',
'message',
'server-url',
'asyncapi-reference',
'json-reference',
'parameters',
'reference',
'contact',
'identifier',
'tags',
'externalDocumentation',
'securityScheme',
'oAuthFlow',
'oAuthFlows',
'discriminator',
'messageTrait',
'messageTraits',
'operationTrait',
'operationTraits',
'security',
];

export default tokens;
98 changes: 98 additions & 0 deletions packages/apidom-ls/src/config/openapi/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const openAPI2Tokens = [
'swagger-host',
'swagger-base-path',
'swagger-schemes',
'swagger-consumes',
'swagger-produces',
'swagger-security',
'swagger-tags',
'definitions',
'parametersDefinitions',
'responsesDefinitions',
'securityDefinitions',
'externalDocumentation',
'info',
'contact',
'license',
'paths',
'pathItem',
'parameters',
'operation',
'operation-consumes',
'operation-produces',
'httpMethod',
'responses',
'security',
'items',
'response',
'headers',
'header',
'tag',
'reference',
'reference-element',
'reference-value',
'openapi-reference',
'json-reference',
'schema',
'xml',
'scopes',
'securityRequirement',
];

const openAPI3Tokens = [
'parameter',
'api-version',
'spec-version',
'info',
'operation',
'pathItem',
'components',
'components-parameters',
'components-schemas',
'components-responses',
'components-examples',
'components-request-bodies',
'components-headers',
'components-security-schemes',
'components-links',
'components-callbacks',
'components-path-items',
'openapi-reference',
'server-url',
'content',
'mediaType',
'openapi',
'parameters',
'paths',
'reference',
'requestBody',
'response',
'responses',
'schema',
'server',
'servers',
'server-variables',
'reference-element',
'reference-value',
'contact',
'httpMethod',
'license',
'tags',
'webhooks',
'jsonSchemaDialect',
'externalDocumentation',
'example',
'examples',
'callback',
'header',
'operation-callbacks',
'securityScheme',
'oAuthFlow',
'oAuthFlows',
'discriminator',
'security',
];

const tokens = [...openAPI2Tokens, ...openAPI3Tokens];

export default tokens;
93 changes: 10 additions & 83 deletions packages/apidom-ls/src/config/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,10 @@
export default [
'value',
'string',
'number',
'key',
'parameter',
'api-version',
'spec-version',
'specVersion',
'info',
'operation',
'pathItem',
'components',
'components-parameters',
'components-schemas',
'components-responses',
'components-examples',
'components-request-bodies',
'components-headers',
'components-security-schemes',
'components-links',
'components-callbacks',
'components-path-items',
'components-messageTraits',
'components-operationTraits',
'openapi-reference',
'server-url',
'Asyncapi-reference',
'json-reference',
'content',
'mediaType',
'openapi',
'parameters',
'paths',
'reference',
'requestBody',
'response',
'responses',
'schema',
'server',
'servers',
'server-variables',
'title',
'channelItem',
'channels',
'reference-element',
'reference-value',
'components-messages',
'principle',
'requirement',
'requirementLevel',
'scenario',
'standard',
'standardIdentifier',
'channel-binding',
'contact',
'httpMethod',
'identifier',
'license',
'message',
'tags',
'webhooks',
'jsonSchemaDialect',
'externalDocumentation',
'example',
'examples',
'callback',
'header',
'operation-callbacks',
'securityScheme',
'oAuthFlow',
'oAuthFlows',
'discriminator',
'messageTrait',
'messageTraits',
'operationTrait',
'operationTraits',
'security',
'parametersDefinitions',
'responsesDefinitions',
'parametersDefinitions',
'definitions',
];
import adsTokens from './ads/tokens';
import asyncapiTokens from './asyncapi/tokens';
import openapiTokens from './openapi/tokens';

// creating list of unique tokens
const tokens = Array.from(
new Set(['value', 'string', 'number', 'key', ...adsTokens, ...asyncapiTokens, ...openapiTokens]),
);

export default tokens;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class OperationTags extends ArrayElement {
constructor(content?: Array<unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.classes.push(OperationTags.primaryClass);
this.classes.push('tags');
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/apidom-ns-openapi-2/src/refractor/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { specificationObj as JSONSchemaDraft4Specification } from '@swagger-api/
import FallbackVisitor from './visitors/FallbackVisitor';
import SwaggerVisitor from './visitors/open-api-2';
import SwaggerSwaggerVisitor from './visitors/open-api-2/SwaggerVisitor';
import SwaggerHostVisitor from './visitors/open-api-2/HostVisitor';
import SwaggerBasePathVisitor from './visitors/open-api-2/BasePathVisitor';
import SwaggerSchemesVisitor from './visitors/open-api-2/SchemesVisitor';
import SwaggerConsumesVisitor from './visitors/open-api-2/ConsumesVisitor';
import SwaggerProducesVisitor from './visitors/open-api-2/ProducesVisitor';
Expand Down Expand Up @@ -80,8 +82,8 @@ const specification = {
info: {
$ref: '#/visitors/document/objects/Info',
},
host: { $ref: '#/visitors/value' },
basePath: { $ref: '#/visitors/value' },
host: SwaggerHostVisitor,
basePath: SwaggerBasePathVisitor,
schemes: SwaggerSchemesVisitor,
consumes: SwaggerConsumesVisitor,
produces: SwaggerProducesVisitor,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import stampit from 'stampit';
import { StringElement, BREAK, cloneDeep } from '@swagger-api/apidom-core';

import FallbackVisitor from '../FallbackVisitor';

const BasePathVisitor = stampit(FallbackVisitor, {
methods: {
StringElement(stringElement: StringElement) {
this.element = cloneDeep(stringElement);
this.element.classes.push('swagger-base-path');

return BREAK;
},
},
});

export default BasePathVisitor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import stampit from 'stampit';
import { StringElement, BREAK, cloneDeep } from '@swagger-api/apidom-core';

import FallbackVisitor from '../FallbackVisitor';

const HostVisitor = stampit(FallbackVisitor, {
methods: {
StringElement(stringElement: StringElement) {
this.element = cloneDeep(stringElement);
this.element.classes.push('swagger-host');

return BREAK;
},
},
});

export default HostVisitor;
Loading

0 comments on commit 4ffce6f

Please sign in to comment.