{"library":"openapi-server-url-templating","title":"OpenAPI Server URL Templating","description":"The `openapi-server-url-templating` library provides a robust, specification-compliant mechanism for parsing, validating, and performing substitutions on server URLs as defined within the OpenAPI Specification. It comprehensively supports server URL templating features, including Server Variables, across various OpenAPI versions from 3.0.0 through 3.1.1. The current stable version is 1.3.0, released in December 2024, indicating an active development and maintenance cadence. A key differentiator is its foundational role in establishing the official ABNF grammar for Server URL Templating within the OpenAPI Specification itself, which ensures a high degree of fidelity and accuracy to the standard. The library leverages `apg-lite` for its underlying parsing and validation capabilities, offering a reliable tool for developers working with OpenAPI definitions.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install openapi-server-url-templating"],"cli":null},"imports":["import { parse } from 'openapi-server-url-templating';","import { validate } from 'openapi-server-url-templating';","import { substitute } from 'openapi-server-url-templating';","import type { Grammar } from 'openapi-server-url-templating';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { parse, validate, substitute } from 'openapi-server-url-templating';\n\nconst urlTemplate = 'https://{username}.gigantic-server.com:{port}/{basePath}';\n\n// 1. Parse the URL template\nconst parseResult = parse(urlTemplate);\nconsole.log('Parse Success:', parseResult.result.success);\n\n// 2. Define server variables for validation and substitution\nconst serverVariables = {\n  username: { default: 'demo', enum: ['demo', 'admin'] },\n  port: { default: '8443', enum: ['8443', '443'] },\n  basePath: { default: 'v2', enum: ['v1', 'v2'] }\n};\n\n// 3. Validate the URL template with variables\nconst validationResult = validate(urlTemplate, serverVariables);\nconsole.log('Validation Success:', validationResult.result.success);\n\n// 4. Substitute variables to get the final URL\nconst values = { username: 'admin', port: '443', basePath: 'v1' };\nconst substitutedUrl = substitute(urlTemplate, serverVariables, values);\nconsole.log('Substituted URL:', substitutedUrl); // Expected: https://admin.gigantic-server.com:443/v1\n\n// Example with default values\nconst substitutedUrlWithDefaults = substitute(urlTemplate, serverVariables, {});\nconsole.log('Substituted URL (defaults):', substitutedUrlWithDefaults); // Expected: https://demo.gigantic-server.com:8443/v2","lang":"typescript","description":"Demonstrates parsing, validating, and substituting an OpenAPI server URL template using defined server variables and supplied values, including usage of default values.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}