UNPKG

@apistudio/apim-cli

Version:

CLI for API Management Products

215 lines (152 loc) 5.22 kB
# WebMethods Gateway Runtime Inventory This library provides functionality for working with WebMethods Gateway schema definitions through the `WMGWRuntimeInventory` class. ## Installation ```bash npm install @apic/wmgw-smith-inventory@latest ``` ## Overview The `WMGWRuntimeInventory` class extends the base `RuntimeInventory` class from `@apic/smith-inventory` and provides specialized functionality for WebMethods Gateway schemas. It includes: - Pre-configured schema definitions for WebMethods Gateway components - Default version mappings for various policy types - Master content configuration for the WebMethods Gateway environment ## Usage ### Basic Usage ```typescript import { WMGWRuntimeInventory } from '@apic/wmgw-smith-inventory'; // Create an instance of the runtime inventory const inventory = new WMGWRuntimeInventory(); // Now you can use the inventory to access schemas and other functionality ``` ### Reading Schemas The primary purpose of this library is to provide access to schema definitions for WebMethods Gateway components. Here's how to access schemas: ```typescript import { WMGWRuntimeInventory } from '@apic/wmgw-smith-inventory'; const inventory = new WMGWRuntimeInventory(); // Get a schema for a specific kind and version const invokeSchema = inventory.getSchema('Invoke', 'wm_1.0.0'); const loadBalancerSchema = inventory.getSchema('LoadBalancer', 'wm_1.0.0'); // If you don't specify a version, it will use the default version for that kind const iamSchema = inventory.getSchema('IAM'); // Uses default version // You can also use the API version format const validateSchema = inventory.getSchema('ValidateAPISpecification', 'api.ibm.com-v1'); ``` ### Available Schema Kinds The library includes schemas for the following kinds: - `InvokeAWSLambda` - `ValidateAPISpecification` - `LoadBalancer` - `Invoke` - `IAM` - `RateLimit` - `RateLimitDef` - and others too And many more as defined in the master content configuration. ### Policy Sequence Types You can retrieve the policy sequence types supported by the WebMethods Gateway: ```typescript const sequenceTypes = inventory.getPolicySequenceType(); console.log(sequenceTypes); // { "sequenceTypes": ["freeflow"] } ``` ### Schema Structure Each schema follows the JSON Schema format and includes: - `kind`: The type of component (e.g., "Invoke", "LoadBalancer") - `apiVersion`: The API version (e.g., "api.ibm.com/v1") - `metadata`: Information about the component (name, version, etc.) - `spec`: The actual configuration for the component Example schema structure: ```json { "type": "object", "required": ["kind", "apiVersion", "metadata", "spec"], "properties": { "kind": { "enum": ["Invoke"], "type": "string" }, "apiVersion": { "type": "string", "default": "api.ibm.com/v1" }, "metadata": { "type": "object", "required": ["name", "version"], "properties": { "name": { "type": "string" }, "version": { "type": "string" }, // ...other metadata properties } }, "spec": { "type": "object", "properties": { // Component-specific properties } } } } ``` ## Advanced Usage ### Extending the Inventory If you need to extend the inventory with additional schemas or functionality: ```typescript import { WMGWRuntimeInventory } from '@apic/wmgw-smith-inventory'; class CustomInventory extends WMGWRuntimeInventory { constructor() { super(); // Add additional schema definitions this.extendSchemaDefinitions({ 'custom_1.0.0_mycomponent.json': { // Your custom schema definition } }); // Add custom default versions this.extendDefaultVersions({ 'MyComponent': 'custom_1.0.0' }); } // Add custom methods as needed } ``` ### Working with Schema Validation You can use the schemas for validation with libraries like Ajv: ```typescript import Ajv from 'ajv'; import { WMGWRuntimeInventory } from '@apic/wmgw-smith-inventory'; const inventory = new WMGWRuntimeInventory(); const schema = inventory.getSchema('Invoke', 'wm_1.0.0'); const ajv = new Ajv(); const validate = ajv.compile(schema); const data = { kind: 'Invoke', apiVersion: 'api.ibm.com/v1', metadata: { name: 'my-invoke', version: '1.0.0' }, spec: { // Component-specific configuration } }; const valid = validate(data); if (!valid) { console.error('Validation errors:', validate.errors); } ``` ## API Reference ### `WMGWRuntimeInventory` #### Constructor ```typescript constructor() ``` Creates a new instance of the WebMethods Gateway Runtime Inventory. #### Methods ##### `getSchema(kind: string, version?: string): object` Gets the schema for the specified kind and version. - `kind`: The kind of component (e.g., "Invoke", "LoadBalancer") - `version`: (Optional) The version of the schema. If not provided, uses the default version for the kind. Returns: The JSON Schema object for the specified kind and version. ##### `getPolicySequenceType(): object` Gets the policy sequence types supported by the WebMethods Gateway. Returns: An object containing the sequence types. ## License ISC