### Execute Spec-Toolkit CLI (Bash) Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/website/docs/docs/getting-started.md Command to execute the spec-toolkit CLI tool using a specified configuration file. This command generates markdown documentation and JSON Schema files. ```bash npx @open-resource-discovery/spec-toolkit -c ./spec-toolkit.config.json ``` -------------------------------- ### Spec-Toolkit Configuration (JSONC) Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/website/docs/docs/getting-started.md Configuration file for the spec-toolkit CLI. It specifies the output path for generated files and defines the documentation generation process, including main specs and optional extensions. ```jsonc { "$schema": "https://open-resource-discovery.github.io/spec-toolkit/spec-v1/spec-toolkit-config.schema.json#", "outputPath": "src/generated/spec-v1", "docsConfig": [ { "type": "spec", "id": "spec-bookstore", "sourceFilePath": "./spec/v1/bookstore.schema.yaml", "mdFrontmatter": { "title": "Bookstore", "description": "Describes the technical interface / schema for the Bookstore." } }, // highlight-start // Optional part (can be omitted for a simple use case): // specify how to merge the _extension_ JSON Schema into the _main_ JSON Schema and generate the documentation { "type": "specExtension", "id": "spec-author", "sourceFilePath": "./spec/v1/author.schema.yaml", "mdFrontmatter": { "title": "Author", "description": "Describes the technical interface / schema for the Author." } } // highlight-end ] } ``` -------------------------------- ### Run spec-toolkit CLI Commands Source: https://context7.com/open-resource-discovery/spec-toolkit/llms.txt Demonstrates how to execute the spec-toolkit CLI using default or custom configuration files, and how to install it globally. ```bash # Default configuration file (./spec-toolkit.config.json) npx spec-toolkit # Custom configuration file npx spec-toolkit -c path/to/config.json # Using installed package npm install -g @open-resource-discovery/spec-toolkit spec-toolkit --config ./my-config.json ``` -------------------------------- ### Plugin Configuration Example (JavaScript) Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/website/docs/docs/spec-toolkit-config.md Examples of how to configure plugins for the spec-toolkit. This includes specifying the package name and optional configuration options. ```javascript { "packageName": "./node_modules/@open-resource-discovery/spec-toolkit/dist/plugin/tabular/index.js" } ``` ```javascript { "packageName": "./node_modules/@open-resource-discovery/spec-toolkit/dist/plugin/mermaidDiagram/index.js" } ``` ```javascript { "packageName": "./node_modules/@open-resource-discovery/spec-toolkit/dist/plugin/ums/index.js", "options": { "metadataPath": "/sap/core/ucl/metadata/ord/v1", "overrides": [ "./document.ums.yaml" ] } } ``` ```javascript { "packageName": "@yourNamespace/yourNpmSpecToolkitPluginPackageName" } ``` -------------------------------- ### Install Spec-Toolkit CLI with npm Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/spec/v1/spec-toolkit-config.intro.md Installs the Spec-Toolkit CLI tool globally on your local machine using npm. This command requires Node.js and npm to be installed and available in your system's PATH. ```bash npm install -g @open-resource-discovery/spec-toolkit ``` -------------------------------- ### JSON Schema for Bookstore (YAML) Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/website/docs/docs/getting-started.md Defines the main JSON Schema for a Bookstore document, including properties for schema ID, title, and a list of books. It also defines nested structures for Book and Genre. ```yaml $schema: "https://open-resource-discovery.github.io/spec-toolkit/spec-v1/spec.schema.json#" title: Bookstore Document description: |- This is the interface description of a Bookstore v1. Its purpose is to describe all properties allowed to be maintained for a Bookstore document. type: object properties: $schema: type: string format: uri-reference description: | Link to the JSON Schema for this Bookstore document. Adding this helps with automatic validation and code intelligence in some editors / IDEs. $id: type: string format: uri-reference description: | Optional URI for this document, that can acts as an ID or as location to retrieve the document. title: type: string description: Descriptive title for the Bookstore. books: type: array description: Book items for the Bookstore. items: $ref: "#/definitions/Book" minItems: 1 required: - books additionalProperties: false definitions: Book: type: object properties: author: type: string description: The book author full name. genre: $ref: "#/definitions/Genre" Genre: type: object description: Definition of book genre. properties: type: type: string enum: - "drama" - "comedy" - "action" description: |- The book item genre type. It's value is been used as a _discriminator_ to distinguish the matching book genre. required: - type ``` -------------------------------- ### Define Interface with Method Signature in TypeScript Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/website/docs/docs/getting-started.md Shows how to define an interface that includes method signatures in TypeScript. This is useful for defining contracts for classes or objects that need to implement specific behaviors. ```typescript interface Shape { kind: "circle" | "square"; radius?: number; sideLength?: number; getArea(): number; } const circle: Shape = { kind: "circle", radius: 5, getArea: function() { return Math.PI * this.radius! ** 2; } }; console.log(circle.getArea()); ``` -------------------------------- ### JSON Schema Extension for Author (YAML) Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/website/docs/docs/getting-started.md An optional JSON Schema extension for Author details, intended to be merged into the main schema. It defines properties like name, birthDate, bankAccount, and contract. ```yaml $schema: "http://json-schema.org/draft-07/schema#" title: Author Document description: This is the interface description of Author. type: object definitions: Author: type: object description: The definition defines how an author object shall be constructed. properties: name: type: string birthDate: type: date bankAccount: type: string contract: type: string enum: - "freelancer" - "employee" required: - name x-extension-targets: - Book ``` -------------------------------- ### Example JSON Schema with Toolkit Extensions Source: https://context7.com/open-resource-discovery/spec-toolkit/llms.txt A basic JSON Schema example demonstrating the use of toolkit-specific extensions (e.g., x-recommended, x-introduced-in-version, x-deprecated-in-version, x-feature-status) for enhanced documentation and metadata. ```yaml $schema: "http://json-schema.org/draft-07/schema#" $id: "https://example.com/api/v1/api.schema.json#" title: API Document description: Root document for the API specification type: object properties: apiVersion: type: string description: Version of the API specification pattern: "^v[0-9]+$" examples: - "v1" - "v2" resources: type: array description: List of API resources items: $ref: "#/definitions/Resource" required: - apiVersion x-recommended: - resources definitions: Resource: title: API Resource description: Represents a single API resource endpoint type: object properties: name: type: string description: Unique resource identifier pattern: "^[a-z][a-z0-9-]*$" minLength: 3 maxLength: 50 method: type: string description: HTTP method for this resource oneOf: - const: "GET" description: Retrieve data from the server - const: "POST" description: Create new resources x-introduced-in-version: "v1" - const: "PUT" description: Update existing resources - const: "DELETE" description: Remove resources x-deprecated-in-version: "v2" authenticated: type: boolean description: Whether authentication is required default: true x-feature-status: "beta" required: - name - method examples: - name: "users" method: "GET" authenticated: true ``` -------------------------------- ### Spec-Toolkit CLI Configuration (JSON) Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/spec/v1/spec-toolkit-config.outro.md This JSON configuration defines the output path for generated specifications and lists multiple documentation configurations. Each configuration specifies the type of specification ('spec' or 'specExtension'), its unique ID, source file paths for the schema and introduction, and optional frontmatter for generating Markdown documentation. ```json { "outputPath": "src/generated/spec-v1", "docsConfig": [ { "type": "spec", "id": "csn-interop-effective", "sourceFilePath": "./spec/v1/CSN-Interop-Effective.schema.yaml", "sourceIntroFilePath": "./spec/v1/CSN-Interop-Effective.schema.md", "examplesFolderPath": "./spec/v1/examples", "mdFrontmatter": { "title": "Interface Documentation", "sidebar_position": "1", "description": "Describes the technical interface / schema for CSN Interop Effective.", "toc_max_heading_level": "4" } }, { "type": "specExtension", "id": "aggregation", "sourceFilePath": "./spec/v1/annotations/aggregation.yaml", "sourceIntroFilePath": "./spec/v1/annotations/aggregation.md", "targetDocumentId": "csn-interop-effective", "mdFrontmatter": { "title": "@Aggregation", "sidebar_position": "2", "description": "@Aggregation annotations." } }, { "type": "specExtension", "id": "analytics-details", "sourceFilePath": "./spec/v1/annotations/analytics-details.yaml", "sourceIntroFilePath": "./spec/v1/annotations/analytics-details.md", "targetDocumentId": "csn-interop-effective", "mdFrontmatter": { "title": "@AnalyticsDetails", "sidebar_position": "3", "description": "@AnalyticsDetails for data analytics use cases." } }, { "type": "specExtension", "id": "consumption", "sourceFilePath": "./spec/v1/annotations/consumption.yaml", "sourceIntroFilePath": "./spec/v1/annotations/consumption.md", "targetDocumentId": "csn-interop-effective", "mdFrontmatter": { "title": "@Consumption", "sidebar_position": "4", "description": "@Consumption annotations." } }, { "type": "specExtension", "id": "end-user-text", "sourceFilePath": "./spec/v1/annotations/end-user-text.yaml", "sourceIntroFilePath": "./spec/v1/annotations/end-user-text.md", "targetDocumentId": "csn-interop-effective", "mdFrontmatter": { "title": "@EndUserText", "sidebar_position": "5", "description": "@EndUserText annotations for end user UIs." } }, { "type": "specExtension", "id": "entity-relationship", "sourceFilePath": "./spec/v1/annotations/entity-relationship.yaml", "sourceIntroFilePath": "./spec/v1/annotations/entity-relationship.md", "sourceOutroFilePath": "./spec/v1/annotations/entity-relationship.outro.md", "targetDocumentId": "csn-interop-effective", "mdFrontmatter": { "title": "@EntityRelationship", "sidebar_position": "6", "description": "@EntityRelationship annotations for cross boundary Entity-Relationship IDs and associations." } }, { "type": "specExtension", "id": "object-model", "sourceFilePath": "./spec/v1/annotations/object-model.yaml", "sourceIntroFilePath": "./spec/v1/annotations/object-model.md", "targetDocumentId": "csn-interop-effective", "mdFrontmatter": { "title": "@ObjectModel", "sidebar_position": "7", "description": "@ObjectModel annotations." } }, { "type": "specExtension", "id": "odm", "sourceFilePath": "./spec/v1/annotations/odm.yaml", "sourceIntroFilePath": "./spec/v1/annotations/odm.md", "targetDocumentId": "csn-interop-effective", "mdFrontmatter": { "title": "@ODM", "sidebar_position": "8", "description": "@ODM for One Domain Model (ODM) related annotations." } }, { "type": "specExtension", "id": "personal-data", "sourceFilePath": "./spec/v1/annotations/personal-data.yaml", "sourceIntroFilePath": "./spec/v1/annotations/personal-data.md", "targetDocumentId": "csn-interop-effective", "mdFrontmatter": { "title": "@PersonalData", "sidebar_position": "9", "description": "@PersonalData to annotate DPP relevant information." } }, { "type": "specExtension", "id": "semantics", "sourceFilePath": "./spec/v1/annotations/semantics.yaml", "sourceIntroFilePath": "./spec/v1/annotations/semantics.md", "targetDocumentId": "csn-interop-effective", "mdFrontmatter": { "title": "@Semantics", "sidebar_position": "10", "description": "@Semantics annotations." } } ] } ``` -------------------------------- ### Define Interface for User Object in TypeScript Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/website/docs/docs/getting-started.md Demonstrates how to define an interface for a user object in TypeScript. Interfaces are used to define the shape of an object, specifying the names and types of its properties. This helps in catching errors early during development. ```typescript interface User { id: number; name: string; email?: string; // Optional property } const user: User = { id: 1, name: "John Doe" }; console.log(user.name); ``` -------------------------------- ### Create Type Alias for Union Type in TypeScript Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/website/docs/docs/getting-started.md Illustrates creating a type alias for a union type in TypeScript. Union types allow a variable to hold values of different types. Type aliases provide a name for these complex types, improving readability and maintainability. ```typescript type StringOrNumber = string | number; let value: StringOrNumber; value = "hello"; console.log(typeof value); value = 123; console.log(typeof value); ``` -------------------------------- ### Generate Markdown Text Safely with TypeScript Source: https://context7.com/open-resource-discovery/spec-toolkit/llms.txt This snippet demonstrates using utility functions from '@open-resource-discovery/spec-toolkit/util/markdownTextHelper' to safely generate markdown for documentation. It includes escaping HTML characters, markdown within table cells, creating anchor links from titles, and converting JSON Schema $ref to markdown links. Ensure the toolkit is installed as a dependency. ```typescript import { escapeHtmlChars, escapeMdInTable, getAnchorLinkFromTitle, getMdLinkFromRef } from "@open-resource-discovery/spec-toolkit/util/markdownTextHelper"; // Generate safe markdown for documentation const propertyName = "resource"; const escaped = escapeHtmlChars(propertyName); // Output: "resource<T>" // Escape markdown for table cells const description = "This uses `backticks` and |pipes|"; const tableCell = escapeMdInTable(description); // Output: "This uses \`backticks\` and \|pipes\|" // Generate anchor links for navigation const title = "API Resource Configuration"; const anchor = getAnchorLinkFromTitle(title); // Output: "#api-resource-configuration" // Convert JSON Schema $ref to markdown link import { SpecJsonSchemaRoot } from "@open-resource-discovery/spec-toolkit"; const schema: SpecJsonSchemaRoot = { definitions: { User: { title: "User Object", type: "object", properties: {} } } }; const property = { $ref: "#/definitions/User" }; const mdLink = getMdLinkFromRef("#/definitions/User", property, schema); // Output: "[User Object](#user-object)" ``` -------------------------------- ### Run Spec-Toolkit CLI using npx Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/spec/v1/spec-toolkit-config.intro.md Executes the Spec-Toolkit CLI using npx. By default, it searches for a './spec-toolkit.config.json' file in the current working directory. An alternative configuration file can be specified using the '-c' flag. ```bash # By default it will look for a `./spec-toolkit.config.json` config file in the CWD npx @open-resource-discovery/spec-toolkit # Possible to pass a configuration file by file path npx @open-resource-discovery/spec-toolkit -c ./spec-toolkit.config.json ``` -------------------------------- ### spec-toolkit Configuration File Structure Source: https://context7.com/open-resource-discovery/spec-toolkit/llms.txt Illustrates the structure of the JSON configuration file for spec-toolkit, including output paths, general configurations, documentation specific settings, and plugin configurations. ```json { "$schema": "https://open-resource-discovery.github.io/spec-toolkit/spec-v1/spec-toolkit-config.schema.json#", "outputPath": "src/generated/my-spec/v1", "generalConfig": { "tsTypeExportExcludeJsFileExtension": true }, "docsConfig": [ { "type": "spec", "id": "my-api-spec", "sourceFilePath": "./spec/v1/my-api.schema.yaml", "sourceIntroFilePath": "./spec/v1/intro.md", "sourceOutroFilePath": "./spec/v1/outro.md", "examplesFolderPath": "./spec/v1/examples", "mdFrontmatter": { "title": "My API Specification", "sidebar_position": "1", "description": "Complete API interface documentation" } } ], "plugins": [ { "packageName": "./src/plugin/mermaidDiagram/index.js", "options": {} } ] } ``` -------------------------------- ### Generate Custom Build Scripts with Spec Toolkit Source: https://context7.com/open-resource-discovery/spec-toolkit/llms.txt This code snippet demonstrates how to use the `generate` function from the spec-toolkit to create custom build artifacts like documentation, types, and schemas. It loads configuration from `spec-toolkit.config.json`, initializes a plugin manager, and then triggers the generation process. The output includes Markdown docs, TypeScript types, JSON Schemas, and plugin-specific outputs. ```typescript import { generate } from "@open-resource-discovery/spec-toolkit"; import { SpecToolkitConfigurationDocument } from "@open-resource-discovery/spec-toolkit"; import PluginManager from "@open-resource-discovery/spec-toolkit/plugin/pluginManager"; import fs from "fs-extra"; // Load configuration const configData: SpecToolkitConfigurationDocument = JSON.parse( fs.readFileSync("./spec-toolkit.config.json", "utf-8") ); // Initialize plugin manager const pluginManager = new PluginManager(); for (const plugin of configData.plugins || []) { await pluginManager.registerPlugin(plugin); } // Generate documentation and artifacts await generate(configData, pluginManager); // Output: // - Markdown documentation in outputPath/docs/ // - TypeScript types in outputPath/types/ // - JSON Schema in outputPath/schemas/ // - Plugin outputs in outputPath/plugin/ ``` -------------------------------- ### Develop Custom Plugins for Spec Toolkit Source: https://context7.com/open-resource-discovery/spec-toolkit/llms.txt This TypeScript code defines a custom plugin for the spec-toolkit, inheriting from `SpecToolkitPlugin`. It demonstrates how to declare custom `x-properties` and implement the `generate` method to process specification files, extract custom metadata, and produce a sorted output file in either JSON or YAML format. This allows for extending the toolkit's functionality with tailored processing logic. ```typescript import SpecToolkitPlugin from "@open-resource-discovery/spec-toolkit/plugin/specToolkitPlugin"; import fs from "fs-extra"; import yaml from "js-yaml"; export default class CustomExportPlugin extends SpecToolkitPlugin { constructor() { super("CustomExportPlugin"); } // Declare custom x-properties this plugin uses get xProperties(): string[] { return ["x-custom-metadata", "x-export-priority"]; } // Generate custom output from spec files async generate( mainSpecSourceFilePaths: string[], outputPath: string, pluginOptions?: { format?: "yaml" | "json" } ): Promise { const format = pluginOptions?.format || "json"; const results = []; for (const specPath of mainSpecSourceFilePaths) { const specContent = fs.readFileSync(specPath, "utf-8"); const spec = yaml.load(specContent); // Extract custom metadata for (const [name, definition] of Object.entries(spec.definitions || {})) { if (definition["x-custom-metadata"]) { results.push({ name, metadata: definition["x-custom-metadata"], priority: definition["x-export-priority"] || 0 }); } } } // Sort by priority and output results.sort((a, b) => b.priority - a.priority); const outputFile = `${outputPath}/custom-export.${format}`; if (format === "yaml") { fs.outputFileSync(outputFile, yaml.dump(results)); } else { fs.outputFileSync(outputFile, JSON.stringify(results, null, 2)); } } } ``` -------------------------------- ### Control Documentation Output with YAML X-Properties Source: https://context7.com/open-resource-discovery/spec-toolkit/llms.txt This YAML snippet shows how to use custom X-properties for documentation control within a JSON Schema. `x-abstract` prevents a definition from being documented, `x-hide-properties` hides the property table for a definition, and `x-hide-property` hides individual properties. These are useful for managing what information is exposed in generated documentation. ```yaml definitions: InternalConfig: title: Internal Configuration x-abstract: true # Exclude from documentation x-hide-properties: true # Don't show property table type: object properties: secret: type: string x-hide-property: true # Hide individual property ``` -------------------------------- ### SpecExtensionConfig Source: https://github.com/open-resource-discovery/spec-toolkit/blob/main/src/generated/spec-toolkit-config/spec-v1/docs/spec-toolkit-config.md Configuration for a JSON Schema extension specification. ```APIDOC ## SpecExtensionConfig ### Description This is the configuration for a JSON Schema extension specification. ### Properties #### Type: Object - **type** (string) - MANDATORY - Type is used to identify the type of the configuration. Constant Value: `specExtension` - **id** (string) - MANDATORY - The ID of the specification. This is used to identify the specification in the generated documentation. - **sourceFilePath** (string) - MANDATORY - The path to the source file of the specification. This is used to generate the documentation for the specification. - **sourceIntroFilePath** (string) - OPTIONAL - The path to the source intro file of the specification. This is used to generate the documentation for the specification and will be appended at the beginning. - **sourceOutroFilePath** (string) - OPTIONAL - The path to the source outro file of the specification. This is used to generate the documentation for the specification and will be appended at the end. - **targetDocumentId** (string) - MANDATORY - The ID of the target document. This is used to identify the target document in the generated documentation. - **mdFrontmatter** ([MdFrontmatter](#mdfrontmatter)) - OPTIONAL - Frontmatter for the generated documentation. This is used to generate the markdown frontmatter for the documentation page. ``` -------------------------------- ### Define Schema Extension Points with YAML Source: https://context7.com/open-resource-discovery/spec-toolkit/llms.txt This YAML snippet demonstrates how to define extension points and targets within a JSON Schema using custom X-properties. `x-extension-points` allows a schema to define areas where other specifications can extend its functionality, while `x-extension-targets` indicates which extension points a specific schema or definition is intended to extend. This facilitates modularity and interoperability. ```yaml definitions: Extensible: title: Extensible Object type: object x-extension-points: - "custom:extensions" # Allow other specs to extend here properties: type: type: string MyExtension: title: My Extension type: object x-extension-targets: - "custom:extensions" # This extends the point above properties: customField: type: string ``` -------------------------------- ### Utilize Validation Utilities in Spec Toolkit Source: https://context7.com/open-resource-discovery/spec-toolkit/llms.txt This TypeScript code demonstrates how to use the validation utilities provided by the spec-toolkit. It shows how to validate a specification file's structure against its schema using `validateSpecJsonSchema` and how to create a reusable validator instance with `getJsonSchemaValidator` to check specific data objects against the schema. Error handling is included for validation failures. ```typescript import { validateSpecJsonSchema } from "@open-resource-discovery/spec-toolkit/util/validation"; import { getJsonSchemaValidator } from "@open-resource-discovery/spec-toolkit/util/validation"; import { SpecJsonSchemaRoot } from "@open-resource-discovery/spec-toolkit"; import yaml from "js-yaml"; import fs from "fs-extra"; // Validate a spec file structure const specFile = yaml.load( fs.readFileSync("./my-spec.schema.yaml", "utf-8") ) as SpecJsonSchemaRoot; try { validateSpecJsonSchema(specFile, "./my-spec.schema.yaml"); console.log("✓ Spec structure is valid"); } catch (error) { console.error("✗ Validation failed:", error); process.exit(1); } // Validate examples against schema const validator = getJsonSchemaValidator(specFile); const exampleData = { apiVersion: "v1", resources: [ { name: "users", method: "GET", authenticated: true } ] }; const isValid = validator(exampleData); if (!isValid) { console.error("Example validation errors:", validator.errors); } else { console.log("✓ Example is valid"); } ``` -------------------------------- ### Define Schema Status and Versioning with YAML Source: https://context7.com/open-resource-discovery/spec-toolkit/llms.txt This YAML snippet illustrates how to use custom X-properties in JSON Schema to denote feature status and versioning. It includes `x-feature-status` (beta, experimental, deprecated), `x-introduced-in-version`, `x-deprecated-in-version`, and `x-deprecation-text` for property-level deprecation notices. This helps in tracking the lifecycle of schema elements. ```yaml definitions: BetaFeature: title: Beta Feature description: This feature is in beta testing type: object x-feature-status: "beta" # Values: beta, experimental, deprecated x-introduced-in-version: "v1.2" x-deprecated-in-version: "v2.0" properties: enabled: type: boolean x-deprecation-text: "Use the new 'active' property instead" ``` -------------------------------- ### Customize TypeScript Generation with YAML X-Properties Source: https://context7.com/open-resource-discovery/spec-toolkit/llms.txt This YAML snippet shows how to customize TypeScript type generation from a JSON Schema using X-properties. `x-custom-typescript-types` allows defining custom type names and values, and `x-typescript-type` can be used on properties or `patternProperties` to specify a custom generated TypeScript type, enabling advanced type mapping. ```yaml $schema: "http://json-schema.org/draft-07/schema#" title: Advanced Schema type: object x-custom-typescript-types: - typeName: "ResourceId" typeValue: "string & { __brand: 'ResourceId' }" description: "Branded type for resource identifiers" properties: data: type: object patternProperties: "^[a-z]+$": type: string x-typescript-type: "replaceKeyType_{ResourceId}" # Use custom type for keys ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.