SpecLynx Language Service

Library

Intelligent editing for API specifications

SpecLynx ApiDOM Language Service (@speclynx/apidom-ls) is a language service library that provides intelligent editing capabilities for API description languages.

View on npm

Note: This is a language service library, not a language server. It implements features aligned with the Language Server Protocol (LSP) without being an LSP server itself. It can be wrapped by an LSP server to integrate with any editor or IDE.

Key Capabilities

13 core features for API specification editing:

✓ Validation
✓ Completion
✓ Hover Documentation
✓ Go to Definition
✓ Find References
✓ Document Symbols
✓ Semantic Tokens
✓ Code Actions
✓ Document Links
✓ Formatting
✓ Dereferencing
✓ Format Conversion
✓ Color Support

Supported Languages

Full support for major API specification formats in both JSON and YAML.

Language Versions Formats
OpenAPI 2.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.1.0, 3.1.1, 3.1.2 JSON, YAML
AsyncAPI 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 JSON, YAML
Arazzo 1.0.0, 1.0.1 JSON, YAML
JSON Schema Draft 4/5, 6, 7, 2019-09, 2020-12 JSON, YAML

Features

Validation

Detects syntax and semantic issues with detailed diagnostic reporting. Returns errors and warnings per specification rules.

const diagnostics = await languageService.doValidation(document);
// Returns: Diagnostic[] with severity, message, range

Completion

Delivers context-sensitive suggestions during editing. Includes reference completion for $ref values with path suggestions.

const completions = await languageService.doCompletion(document, position);
// Returns: CompletionList with context-aware suggestions

Hover

Shows documentation and type details when hovering over symbols. Provides markdown-formatted content from the specification.

const hover = await languageService.doHover(document, position);
// Returns: Hover with markdown documentation

Document Symbols

Generates outlines and breadcrumbs for document navigation. Provides a hierarchical view of the specification structure.

const symbols = await languageService.doProvideDocumentSymbols(document);
// Returns: DocumentSymbol[] hierarchy

Semantic Tokens

Provides advanced syntax highlighting through semantic token computation. Enables context-aware coloring of API specification elements.

const tokens = await languageService.computeSemanticTokens(document);
// Returns: SemanticTokens for enhanced highlighting

Code Actions

Offers quick fixes and refactoring options based on diagnostics and cursor position.

const actions = await languageService.doCodeActions(document, params);
// Returns: CodeAction[] with quick fixes

Formatting

Standardizes document structure with consistent indentation and formatting.

const edits = await languageService.doFormat(document, options);
// Returns: TextEdit[] to apply formatting

Format Conversion

Switches between JSON and YAML formats while preserving the specification structure.

const converted = await languageService.doConvertFormat(document, targetFormat);
// Returns: Converted document content

Dereferencing

Expands all $ref references, replacing them with actual definitions.

const dereferenced = await languageService.doDeref(document);
// Returns: Fully dereferenced document

Installation

npm install @speclynx/apidom-ls

Quick Start

import { getLanguageService } from '@speclynx/apidom-ls';
import { TextDocument } from 'vscode-languageserver-textdocument';

// Create the language service
const languageService = getLanguageService({});

// Create a document from your API specification
const spec = `
openapi: "3.1.0"
info:
  title: My API
  version: 1.0.0
paths: {}
`;

const document = TextDocument.create(
  'file:///api.yaml',
  'yaml',
  0,
  spec
);

// Get validation diagnostics
const diagnostics = await languageService.doValidation(document);

// Get completions at a position
const completions = await languageService.doCompletion(document, { line: 4, character: 0 });

// Always terminate when done
languageService.terminate();

Configuration

The language service accepts configuration options for customization:

import { getLanguageService, LogLevel } from '@speclynx/apidom-ls';

const languageService = getLanguageService({
  logLevel: LogLevel.WARN,
  // Custom providers
  validatorProviders: [...],
  completionProviders: [...],
  hoverProviders: [...],
  // Link following in hover
  hoverFollowLinks: true,
});

Configuration Options

Option Description
logLevel Logging verbosity (LogLevel enum)
validatorProviders Custom validation rule providers
completionProviders Custom completion providers
hoverProviders Custom hover documentation providers
hoverFollowLinks Enable link following in hover tooltips

Architecture

The Language Service sits between your application and the ApiDOM parsing layer:

Your Application

IDE, Editor, CLI, etc.

LSP Server Wrapper

Optional - implements LSP protocol

SpecLynx Language Service

@speclynx/apidom-ls

SpecLynx ApiDOM

Parsing, data model, traversal

Support

Enterprise support is available for organizations requiring dedicated assistance.

Contact us at info@speclynx.com →

License

Licensed under Apache 2.0.

Frequently Asked Questions

What is SpecLynx Language Service?

SpecLynx Language Service is an LSP-compatible library that provides intelligent editing features for API specifications. It powers validation, autocompletion, hover documentation, go-to-definition, and other editor features for OpenAPI, AsyncAPI, Arazzo, and JSON Schema files.

Can I use Language Service outside of VSCode?

Yes. Language Service is a standalone npm package (@speclynx/apidom-ls) that implements the Language Server Protocol. You can integrate it into any editor or tool that supports LSP, or use it programmatically in your own applications.

What LSP features are supported?

The library supports over 12 LSP features including validation diagnostics, completion, hover, go-to-definition, find references, document symbols, semantic tokens, code actions, formatting, and format conversion between JSON and YAML.

What API specifications are supported?

Language Service supports OpenAPI 2.0 (Swagger), OpenAPI 3.0.x, OpenAPI 3.1.x, AsyncAPI 2.x, Arazzo 1.x, and JSON Schema. All features work across these specifications in both JSON and YAML formats.