@redocly/openapi-language-server 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ import { NormalizedProblem } from '@redocly/openapi-core';
2
+ import type { TextDocument } from 'vscode-languageserver-textdocument';
3
+ import type { NormalizedNodeType } from '@redocly/openapi-core/lib/types';
4
+ export declare type DefinitionData = {
5
+ name: string;
6
+ uri: string;
7
+ };
8
+ export declare type BundleData = DefinitionData & {
9
+ definition: Record<string, any>;
10
+ rootType: NormalizedNodeType;
11
+ refTypes: [string, NormalizedNodeType][];
12
+ htmlTempalteStyles?: string | null;
13
+ errors?: NormalizedProblem[];
14
+ };
15
+ export declare function bundleOpenAPI(textDocument: TextDocument, errors: NormalizedProblem[]): Promise<void>;
16
+ export declare function getBundle(path: string): any;
17
+ export declare function getBundles(): BundleData[];
18
+ export declare function getRefTypes(path: string): NormalizedNodeType | undefined | null;
@@ -0,0 +1,17 @@
1
+ import { CompletionItem, CompletionItemKind, InsertTextFormat, Command } from 'vscode-languageserver/browser';
2
+ import type { CompletionItemOptions } from '../../types/completion';
3
+ export interface KeyCompletionOptions extends CompletionItemOptions {
4
+ insertTextFormat?: InsertTextFormat;
5
+ data?: any;
6
+ }
7
+ export declare class KeyCompletion implements CompletionItem {
8
+ kind: CompletionItemKind;
9
+ label: string;
10
+ insertText: string;
11
+ filterText: string;
12
+ sortText?: string;
13
+ command?: Command;
14
+ insertTextFormat: InsertTextFormat;
15
+ data?: any;
16
+ constructor({ kind, label, insertText, insertTextFormat, filterText, sortText, data, }: KeyCompletionOptions);
17
+ }
@@ -0,0 +1,4 @@
1
+ import { ValueCompletion, ValueCompletionOptions } from './ValueCompletion';
2
+ export declare class LocalFileCompletion extends ValueCompletion {
3
+ constructor(completionOptions: ValueCompletionOptions);
4
+ }
@@ -0,0 +1,6 @@
1
+ import { Command } from 'vscode-languageserver/browser';
2
+ import { ValueCompletion, ValueCompletionOptions } from './ValueCompletion';
3
+ export declare class LocalFolderCompletion extends ValueCompletion {
4
+ command: Command;
5
+ constructor(completionOptions: ValueCompletionOptions);
6
+ }
@@ -0,0 +1,23 @@
1
+ import { YAMLScalar } from '@redocly/yaml-language-server-parser';
2
+ import { CompletionItem, CompletionItemKind, TextEdit, InsertReplaceEdit, Position, Command } from 'vscode-languageserver/browser';
3
+ import type { CompletionItemOptions } from '../../types/completion';
4
+ export interface ValueCompletionDataOptions {
5
+ position?: Position;
6
+ node?: YAMLScalar;
7
+ lineOffset?: number;
8
+ }
9
+ export interface ValueCompletionOptions extends CompletionItemOptions {
10
+ value?: string;
11
+ data: ValueCompletionDataOptions;
12
+ }
13
+ export declare class ValueCompletion implements CompletionItem {
14
+ kind: CompletionItemKind;
15
+ label: string;
16
+ insertText: string;
17
+ filterText: string;
18
+ sortText?: string;
19
+ command?: Command;
20
+ textEdit?: TextEdit | InsertReplaceEdit;
21
+ constructor({ kind, label, value, textEdit, filterText, sortText, data, }: ValueCompletionOptions);
22
+ getTextEdit(node: YAMLScalar, position: Position, lineOffset: number): TextEdit | InsertReplaceEdit;
23
+ }
@@ -0,0 +1,7 @@
1
+ export declare const fieldNames: {
2
+ example: string;
3
+ default: string;
4
+ enum: string;
5
+ ref: string;
6
+ };
7
+ export declare const userEnumCompletionKeys: string[];
@@ -0,0 +1,9 @@
1
+ import * as yamlAst from '@redocly/yaml-language-server-parser';
2
+ import { CompletionItem, Position } from 'vscode-languageserver/browser';
3
+ import { DocumentUri } from 'vscode-languageserver-textdocument';
4
+ import { ValueCompletion } from './ValueCompletion';
5
+ import { YamlCompletionContext } from './context';
6
+ export declare function getCompletionKeys(completionContext: YamlCompletionContext): CompletionItem[];
7
+ export declare function getCompletionValues(uri: DocumentUri, completionContext: YamlCompletionContext<yamlAst.YAMLScalar>): Promise<ValueCompletion[]>;
8
+ export declare function getCompletion(uri: DocumentUri, position: Position): Promise<CompletionItem[]>;
9
+ export declare function resolveCompletion(item: CompletionItem): CompletionItem;
@@ -0,0 +1,25 @@
1
+ import { DocumentUri, Position } from 'vscode-languageserver-textdocument';
2
+ import { YAMLNode } from '@redocly/yaml-language-server-parser';
3
+ import { URI } from 'vscode-uri';
4
+ import { NodePath } from '../../types/context-core';
5
+ import { ExtendedNormalizedNodeType } from '../../types/completion';
6
+ export interface YamlCompletionContext<NodeType = YAMLNode> {
7
+ currentAst: YAMLNode;
8
+ node: NodeType;
9
+ nodePath: NodePath;
10
+ position: Position;
11
+ lineText: string;
12
+ lineOffset: number;
13
+ openApiType: ExtendedNormalizedNodeType | null;
14
+ }
15
+ export interface RefPathResolverContext {
16
+ docAbsolutePath: URI;
17
+ docAbsoluteDirPath: URI;
18
+ refPath: string;
19
+ refDirPath: URI;
20
+ refDirAbsolutePath: URI;
21
+ isAbsolutePath: boolean;
22
+ root: string;
23
+ }
24
+ export declare function createCompletionContext<NodeType = YAMLNode>(uri: DocumentUri, position: Position): Promise<YamlCompletionContext<NodeType>>;
25
+ export declare function createRefPathResolverContext(uri: DocumentUri, refPath: string): Promise<RefPathResolverContext>;
@@ -0,0 +1,15 @@
1
+ import type { NormalizedNodeType } from '@redocly/openapi-core/lib/types';
2
+ export declare type PartialNodeType = {
3
+ items?: NormalizedNodeType['items'];
4
+ required?: NormalizedNodeType['required'];
5
+ };
6
+ declare function getKeyValue(key: string, type?: PartialNodeType): string;
7
+ declare function getBeforeKeyValue(key: string, value: string, beforeKey: string, type?: PartialNodeType): string;
8
+ declare function getAfterKeyValue(key: string): "" | ": ";
9
+ declare function getBeforeKey(lineText?: string): "" | " " | "\n ";
10
+ declare function getAfterValue(beforeKey: string, properties?: NormalizedNodeType['properties']): "" | "\n " | "\n ";
11
+ declare function getInsertSnippet(key: string, data?: {
12
+ properties?: NormalizedNodeType['properties'];
13
+ lineText: string;
14
+ } & PartialNodeType, addNewLine?: boolean): string;
15
+ export { getInsertSnippet, getAfterKeyValue, getAfterValue, getKeyValue, getBeforeKey, getBeforeKeyValue, };
@@ -0,0 +1,26 @@
1
+ import { DocumentUri } from 'vscode-languageserver-textdocument';
2
+ import { YAMLScalar } from '@redocly/yaml-language-server-parser';
3
+ import { SupportedLanguage } from '../../../config';
4
+ import { LocalFolderCompletion } from './LocalFolderCompletion';
5
+ import { LocalFileCompletion } from './LocalFileCompletion';
6
+ import { YamlCompletionContext, RefPathResolverContext } from './context';
7
+ export declare const LOCAL_FILES_SUPPORTED_SUGGESTIONS: SupportedLanguage[];
8
+ export declare enum FsNodeType {
9
+ File = 0,
10
+ Folder = 1
11
+ }
12
+ export interface RefFileStat {
13
+ type: FsNodeType;
14
+ name: string;
15
+ }
16
+ export interface RefPathOption extends RefFileStat {
17
+ value: string;
18
+ matchBy: string;
19
+ sortBy: string;
20
+ }
21
+ export declare function getToTopOption(pathResolverContext: RefPathResolverContext): RefPathOption;
22
+ export declare function getChildrenOfPath(files: string[], config: {
23
+ supportedFiles: SupportedLanguage[];
24
+ }, pathResolverContext: RefPathResolverContext): Promise<RefFileStat[]>;
25
+ export declare function getRefPathOptions(fileStats: RefFileStat[], pathResolverContext: RefPathResolverContext): RefPathOption[];
26
+ export declare function getLocalFsRefs(uri: DocumentUri, completionContext: YamlCompletionContext<YAMLScalar>): Promise<(LocalFolderCompletion | LocalFileCompletion)[]>;
@@ -0,0 +1,20 @@
1
+ import { OasVersion, OasMajorVersion } from '@redocly/openapi-core';
2
+ import * as yamlAst from '@redocly/yaml-language-server-parser';
3
+ import type { Position } from 'vscode-languageserver/browser';
4
+ import type { NormalizedNodeType } from '@redocly/openapi-core/lib/types';
5
+ import type { ContextData, ExistingValues } from './types/context-core';
6
+ import type { OpenApiVersion, TextDocumentWithLineOffset, NodeWithPath, NodePath } from './types/context-core';
7
+ export declare function getContextData(uri: string, position: Position): Promise<ContextData>;
8
+ export declare function getAstNodeByPath(currentAst: yamlAst.YAMLNode | null, path: (number | string)[]): yamlAst.YAMLNode | null;
9
+ export declare function getAstNodeByPosition(start: NodeWithPath, position: Position, document: TextDocumentWithLineOffset, isContextData?: boolean): NodeWithPath;
10
+ export declare function getNodeLineIndent(node: yamlAst.YAMLNode | null | undefined, document: TextDocumentWithLineOffset): number;
11
+ export declare function getTypesByNodePath(types: any, nodePath: NodePath): {
12
+ currentType: NormalizedNodeType | null;
13
+ parentType: NormalizedNodeType | null;
14
+ endPath: string | null;
15
+ };
16
+ export declare function getRootTypes(ast: yamlAst.YAMLNode, uri: string): NormalizedNodeType | null;
17
+ export declare function getOASVersion(ast: yamlAst.YAMLNode): OpenApiVersion<OasVersion>;
18
+ export declare function getOASMajorVersion(ast: yamlAst.YAMLNode): OpenApiVersion<OasMajorVersion>;
19
+ export declare function getChildNodes(node?: yamlAst.YAMLNode | null): yamlAst.YAMLNode[];
20
+ export declare function getExistingValues(node: yamlAst.YAMLSequence, values?: ExistingValues, indent?: number): ExistingValues;
@@ -0,0 +1,16 @@
1
+ import { DocumentUri } from 'vscode-languageserver/browser';
2
+ import { TextDocument } from 'vscode-languageserver-textdocument';
3
+ export declare type DocumentStats = {
4
+ dependencyPaths: Set<string>;
5
+ durationMS: number;
6
+ };
7
+ export declare type DependencyStats = {
8
+ documentPath: string;
9
+ durationMS: number;
10
+ };
11
+ export declare function updateDependencyMap(path: string, stats: DocumentStats): Map<string, DocumentStats>;
12
+ export declare function getPathsByDependency(depPath: string): DependencyStats[];
13
+ export declare function getDocumentLanguageId(uri: DocumentUri): string;
14
+ export declare function getDocumentByURI(uri: DocumentUri): Promise<TextDocument>;
15
+ export declare function isJsonFile(uri: DocumentUri): boolean;
16
+ export declare function isYamlFile(uri: DocumentUri): boolean;
@@ -0,0 +1,5 @@
1
+ import { BaseResolver, Source } from '@redocly/openapi-core';
2
+ export declare class ExternalResolver extends BaseResolver {
3
+ resolveExternalRef(base: string, ref: string): string;
4
+ loadExternalRef(absoluteRef: string): Promise<Source>;
5
+ }
@@ -0,0 +1,7 @@
1
+ import { CompletionItem } from 'vscode-languageserver/browser';
2
+ import { ExtendedNormalizedNodeType } from './types/completion';
3
+ export declare const START_SEQ_LABEL = "newItem";
4
+ export declare const START_MAP_LABEL = "propertyName";
5
+ export declare const ADD_NEW_LINE = "newLine";
6
+ export declare function hasHints(type: ExtendedNormalizedNodeType): boolean;
7
+ export declare function getAdditionalCompletionItem(name: string): CompletionItem[];
@@ -0,0 +1,7 @@
1
+ import { Config as OpenAPIConfig } from '@redocly/openapi-core';
2
+ export { CONFIG_FILE_NAMES } from '@redocly/openapi-core';
3
+ export declare function isConfigFile(uri: string): boolean;
4
+ export declare function getOpenAPIConfig({ cache }?: {
5
+ cache?: boolean;
6
+ }): Promise<OpenAPIConfig>;
7
+ export declare function updateOpenApiConfig(): Promise<OpenAPIConfig>;
@@ -0,0 +1,76 @@
1
+ import { ExtendedNormalizedNodeType } from './types/completion';
2
+ import { mapTypeToComponent } from '@redocly/openapi-core';
3
+ declare const typeExtensions: {
4
+ Schema: {
5
+ name: string;
6
+ value: {
7
+ type: string;
8
+ name: string;
9
+ };
10
+ }[];
11
+ PathItem: {
12
+ name: string;
13
+ value: {
14
+ type: string;
15
+ name: string;
16
+ };
17
+ }[];
18
+ Parameter: {
19
+ name: string;
20
+ value: {
21
+ type: string;
22
+ name: string;
23
+ };
24
+ }[];
25
+ Response: {
26
+ name: string;
27
+ value: {
28
+ type: string;
29
+ name: string;
30
+ };
31
+ }[];
32
+ Example: {
33
+ name: string;
34
+ value: {
35
+ type: string;
36
+ name: string;
37
+ };
38
+ }[];
39
+ RequestBody: {
40
+ name: string;
41
+ value: {
42
+ type: string;
43
+ name: string;
44
+ };
45
+ }[];
46
+ Header: {
47
+ name: string;
48
+ value: {
49
+ type: string;
50
+ name: string;
51
+ };
52
+ }[];
53
+ SecuritySchema: {
54
+ name: string;
55
+ value: {
56
+ type: string;
57
+ name: string;
58
+ };
59
+ }[];
60
+ Link: {
61
+ name: string;
62
+ value: {
63
+ type: string;
64
+ name: string;
65
+ };
66
+ }[];
67
+ Callback: {
68
+ name: string;
69
+ value: {
70
+ type: string;
71
+ name: string;
72
+ };
73
+ }[];
74
+ };
75
+ declare function extendOASType(type: ExtendedNormalizedNodeType): ExtendedNormalizedNodeType;
76
+ export { typeExtensions, extendOASType, mapTypeToComponent };
@@ -0,0 +1,8 @@
1
+ import { DocumentUri } from 'vscode-languageserver/browser';
2
+ import { URI } from 'vscode-uri';
3
+ export declare function parseUri(path: string): URI;
4
+ export declare function isHttpPath(path: string): boolean;
5
+ export declare function uriBaseName(uri: DocumentUri): string;
6
+ export declare function getFileExtension(uri: DocumentUri): string;
7
+ export declare function noTrailingSlash(path: string): string;
8
+ export declare function getClosestExistingDir(uri: URI, baseDir?: string): Promise<URI>;
@@ -0,0 +1,43 @@
1
+ export declare function getSortText(typeName: string | null, label?: string): string;
2
+ export declare enum SortTypes {
3
+ FileCompletion = "FileCompletion",
4
+ FolderCompletion = "FolderCompletion",
5
+ LocalComponentCompletion = "LocalComponentCompletion",
6
+ NewLine = "newLine",
7
+ PropertyName = "propertyName",
8
+ NewItem = "newItem",
9
+ PathMap = "PathMap",
10
+ MediaTypeMap = "MediaTypeMap",
11
+ DefinitionRoot = "DefinitionRoot",
12
+ DefinitionRootOpenapi = "DefinitionRoot_openapi",
13
+ DefinitionRootInfo = "DefinitionRoot_info",
14
+ DefinitionRootJsonSchemaDialect = "DefinitionRoot_jsonSchemaDialect",
15
+ DefinitionRootServers = "DefinitionRoot_servers",
16
+ DefinitionRootPaths = "DefinitionRoot_paths",
17
+ DefinitionRootWebhooks = "DefinitionRoot_webhooks",
18
+ DefinitionRootComponents = "DefinitionRoot_components",
19
+ DefinitionRootSecurity = "DefinitionRoot_security",
20
+ DefinitionRootTags = "DefinitionRoot_tags",
21
+ DefinitionRootExternalDocs = "DefinitionRoot_externalDocs",
22
+ Info = "Info",
23
+ InfoTitle = "Info_title",
24
+ InfoSummary = "Info_summary",
25
+ InfoDescription = "Info_description",
26
+ InfoTermsOfService = "Info_termsOfService",
27
+ InfoContact = "Info_contact",
28
+ ContactName = "Contact_name",
29
+ ContactUrl = "Contact_url",
30
+ ContactEmail = "Contact_email",
31
+ InfoLicense = "Info_license",
32
+ LicenseName = "License_name",
33
+ LicenseIdentifier = "License_identifier",
34
+ LicenseUrl = "License_url",
35
+ InfoVersion = "Info_version",
36
+ jsonSchemaDialect = "jsonSchemaDialect",
37
+ ServerList = "Server_List",
38
+ ServerUrl = "Server_url",
39
+ ServerDescription = "Server_description",
40
+ ServerVariables = "Server_variables",
41
+ Default = "Default"
42
+ }
43
+ export declare const sortLabelObject: Record<SortTypes, string>;
@@ -0,0 +1,16 @@
1
+ import { NormalizedNodeType } from '@redocly/openapi-core/lib/types';
2
+ import { CompletionItemKind, TextEdit, InsertReplaceEdit } from 'vscode-languageserver/browser';
3
+ declare type ExtendedNormalizedNodeType = NormalizedNodeType & {
4
+ isExample?: true;
5
+ enum?: string[];
6
+ type?: string;
7
+ };
8
+ interface CompletionItemOptions {
9
+ label: string;
10
+ kind?: CompletionItemKind;
11
+ sortText?: string;
12
+ textEdit?: TextEdit | InsertReplaceEdit;
13
+ insertText?: string;
14
+ filterText?: string;
15
+ }
16
+ export type { ExtendedNormalizedNodeType, CompletionItemOptions };
@@ -0,0 +1,42 @@
1
+ import yamlAst from '@redocly/yaml-language-server-parser';
2
+ import type { TextDocument } from 'vscode-languageserver-textdocument';
3
+ import type { NormalizedNodeType } from '@redocly/openapi-core/lib/types';
4
+ export declare enum ContextErrorCodes {
5
+ FILE_TYPE_NOT_SUPPORTED = 0
6
+ }
7
+ export declare type ContextError = {
8
+ error: {
9
+ code: ContextErrorCodes;
10
+ message: string;
11
+ };
12
+ };
13
+ export declare type ExistingValues = {
14
+ [key: string]: {
15
+ value: string | null;
16
+ startOffset: number;
17
+ endOffset: number | null;
18
+ indent: number;
19
+ type?: 'scalar' | 'map' | 'sequence';
20
+ rawValue?: string;
21
+ };
22
+ };
23
+ export declare type ContextData = {
24
+ nodePath: (string | number)[];
25
+ endPath: string | null;
26
+ type: NormalizedNodeType | null;
27
+ existingValues: ExistingValues;
28
+ types: NormalizedNodeType | null;
29
+ };
30
+ declare type OpenApiVersion<T> = {
31
+ version: T;
32
+ isDefault: boolean;
33
+ };
34
+ declare type NodePath = (string | number)[];
35
+ declare type NodeWithPath = {
36
+ node: yamlAst.YAMLNode | null;
37
+ nodePath: NodePath;
38
+ };
39
+ declare type TextDocumentWithLineOffset = TextDocument & {
40
+ _lineOffsets: number[];
41
+ };
42
+ export { OpenApiVersion, NodeWithPath, NodePath, TextDocumentWithLineOffset };
@@ -0,0 +1,16 @@
1
+ import { YAMLNode } from '@redocly/yaml-language-server-parser';
2
+ import type { TextDocument } from 'vscode-languageserver-textdocument';
3
+ declare type Func<T> = (textDocument: TextDocument) => T | Promise<T>;
4
+ export declare function debounceDocument<T>(func: Func<T>, wait?: number, immediate?: boolean): Func<Promise<T>>;
5
+ export declare function removeCirculars(object: any): any;
6
+ export declare function isRefField(field: string): boolean;
7
+ export declare function isString<T>(value: T): boolean;
8
+ export declare function isFunction<T>(f: T): boolean;
9
+ export declare function isPromise<T>(value: T): boolean;
10
+ export declare function isYamlMap(node: YAMLNode | null): boolean;
11
+ export declare function isYamlMapping(node: YAMLNode | null): boolean;
12
+ export declare function isYamlSequence(node: YAMLNode | null): boolean;
13
+ export declare function surroundByNodeQuotes(valueToSurround: string, options: Record<string, any> & {
14
+ singleQuoted?: boolean;
15
+ }): string;
16
+ export {};
@@ -0,0 +1,7 @@
1
+ import { NormalizedProblem } from '@redocly/openapi-core';
2
+ import { PublishDiagnosticsParams } from 'vscode-languageserver/browser';
3
+ import { TextDocument } from 'vscode-languageserver-textdocument';
4
+ export declare const validateOpenAPI: (textDocument: TextDocument) => Promise<PublishDiagnosticsParams[]> | Promise<Promise<PublishDiagnosticsParams[]>>;
5
+ export declare function revalidateAllDocuments(): (Promise<PublishDiagnosticsParams[]> | Promise<Promise<PublishDiagnosticsParams[]>>)[];
6
+ export declare function handleUnexpectedError(fileURI: string, error: any, diagnosticsParams?: PublishDiagnosticsParams[]): PublishDiagnosticsParams[];
7
+ export declare function getValidationErrorsForBundle(problems: NormalizedProblem[]): NormalizedProblem[];
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@redocly/openapi-language-server",
3
+ "version": "0.0.3",
4
+ "description": "Redocly OpenAPI language server",
5
+ "module": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
+ "scripts": {
8
+ "build": "npm run clean && node esbuild.cjs",
9
+ "compile": "npm run clean && tsc -p tsconfig.json",
10
+ "build:types": "tsc --emitDeclarationOnly --declaration --project tsconfig.json",
11
+ "deploy": "npm publish",
12
+ "clean": "rm -rf lib",
13
+ "prettier-base": "prettier \"**/*.{json,js,jsx,ts,tsx,yml,yaml,html,md}\"",
14
+ "prettier": "npm run prettier-base -- --write",
15
+ "prettier:check": "npm run prettier-base -- --check",
16
+ "ts:check": "tsc --noEmit --skipLibCheck",
17
+ "lint": "eslint . --ext .jsx,.ts,.tsx --cache",
18
+ "test": "echo \"Error: no test specified\" && exit 1",
19
+ "postbuild": "npm run build:types"
20
+ },
21
+ "author": "Redocly LLC <team@redocly.com>",
22
+ "license": "SEE LICENSE IN LICENSE",
23
+ "peerDependencies": {
24
+ "@redocly/openapi-core": "^1.0.0-beta.108"
25
+ },
26
+ "devDependencies": {
27
+ "@typescript-eslint/eslint-plugin": "^5.33.1",
28
+ "@typescript-eslint/parser": "^5.33.1",
29
+ "esbuild": "^0.15.0",
30
+ "eslint": "^8.21.0",
31
+ "path-browserify": "^1.0.1",
32
+ "prettier": "2.7.1",
33
+ "typescript": "^4.7.4"
34
+ },
35
+ "dependencies": {
36
+ "@redocly/yaml-language-server-parser": "^0.3.0",
37
+ "vscode-languageserver": "^8.0.2",
38
+ "vscode-languageserver-textdocument": "^1.0.5",
39
+ "vscode-uri": "^3.0.2"
40
+ }
41
+ }