@apistudio/apim-cli
Version:
CLI for API Management Products
1,139 lines (1,138 loc) • 308 kB
JavaScript
// Import the JSON files directly as embedded objects
// This avoids dynamic imports while still providing the same functionality
// defaultVersion.json - Updated based on kind and apiVersion from schema definitions
const defaultVersions = {
// Common assets
"API": "api.ibm.com/v1",
"CORS": "api.ibm.com/v1",
"Plan": "api.ibm.com/v1",
"Product": "api.ibm.com/v1",
"Properties": "api.ibm.com/v1",
"Quota": "api.ibm.com/v1",
"Scope": "api.ibm.com/v1",
"URISchemes": "api.ibm.com/v1",
// Policy assets
"AuthorizeUser": "api.ibm.com/v1",
"CacheServiceResult": "api.ibm.com/v1",
"DataMasking": "api.ibm.com/v1",
"ErrorProcessing": "api.ibm.com/v1",
"GlobalPolicy": "api.ibm.com/v1",
"HTTPEndpoint": "api.ibm.com/v1",
"HTTPInvoke": "api.ibm.com/v1",
"IAM": "api.ibm.com/v1",
"InboundBulkHead": "api.ibm.com/v1",
"InboundMessaging": "api.ibm.com/v1",
"Invoke": "api.ibm.com/v1",
"InvokeAWSLambda": "api.ibm.com/v1",
"InvokeMessagingExtension": "api.ibm.com/v1",
"LoadBalancer": "api.ibm.com/v1",
"Log": "api.ibm.com/v1",
"MessageConfig": "api.ibm.com/v1",
"MockEndpoint": "api.ibm.com/v1",
"MockResponse": "api.ibm.com/v1",
"MonitorTraffic": "api.ibm.com/v1",
"OutboundAlias": "api.ibm.com/v1",
"OutboundAnonymous": "api.ibm.com/v1",
"Project": "api.ibm.com/v1",
"RateLimit": "api.ibm.com/v1",
"RateLimitDef": "api.ibm.com/v1",
"Route": "api.ibm.com/v1",
"Set": "api.ibm.com/v1",
"SetAuthorization": "api.ibm.com/v1",
"SetContextVariable": "api.ibm.com/v1",
"SetMediaType": "api.ibm.com/v1",
"StagedPolicySequence": "api.ibm.com/v1",
"Telemetry": "api.ibm.com/v1",
"TransformRequest": "api.ibm.com/v1",
"TransformResponse": "api.ibm.com/v1",
"ValidateAPISpecification": "api.ibm.com/v1",
"WebMethodsISService": "api.ibm.com/v1"
};
// master.json
const masterJson = {
"extension-key": "webm-gateway",
"policy-sequences": {
"staged": [
{
"key": "transport",
"label": "Transport",
"assets": [
{
"kind": "Transport",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "InboundBulkHead",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "InboundMessaging",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "SetMediaType",
"defautlVersion": "api.ibm.com/v1"
}
]
},
{
"key": "identity_authorize",
"label": "Identity and Authorize",
"assets": [
{
"kind": "IdentifyAndAuthorize",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "AuthorizeUser",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "SetContextVariable",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "WebMethodsISService",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "InvokeAWSLambdaFunction",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "InvokeMessagingExtension",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "HTTPEndpoint",
"defautlVersion": "api.ibm.com/v1"
}
]
},
{
"key": "monitoring",
"label": "Traffic Monitoring",
"assets": [
{
"kind": "Log",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "RateLimiter",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "MonitorTraffic",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "CacheServiceResult",
"defautlVersion": "api.ibm.com/v1"
}
]
},
{
"key": "routing",
"label": "Routing",
"assets": [
{
"kind": "Route",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "MessageConfig",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "SetContextVariable",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "WebMethodsISService",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "InvokeAWSLambdaFunction",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "InvokeMessagingExtension",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "HTTPEndpoint",
"defautlVersion": "api.ibm.com/v1"
}
]
},
{
"key": "reqProcessing",
"label": "Request Processing",
"assets": [
{
"kind": "TransformRequest",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "ValidateAPISpecification",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "DataMasking",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "SetContextVariable",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "WebMethodsISService",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "InvokeAWSLambdaFunction",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "InvokeMessagingExtension",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "HTTPEndpoint",
"defautlVersion": "api.ibm.com/v1"
}
]
},
{
"key": "resProcessing",
"label": "Response Processing",
"assets": [
{
"kind": "TransformResponse",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "ValidateAPISpecification",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "DataMasking",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "CORS",
"defautlVersion": "api.ibm.com/v1"
}
]
},
{
"key": "error_handlinf",
"label": "Error Handling",
"assets": [
{
"kind": "ErrorProcessing",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "DataMasking",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "SetContextVariable",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "WebMethodsISService",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "InvokeAWSLambdaFunction",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "InvokeMessagingExtension",
"defautlVersion": "api.ibm.com/v1"
},
{
"kind": "HTTPEndpoint",
"defautlVersion": "api.ibm.com/v1"
}
]
}
]
},
"assetProperties": {
"api.ibm.com_v1_HTTPEndpoint": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_Transport": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_InboundBulkHead": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_InboundMessaging": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_SetMediaType": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_IdentifyAndAuthorize": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_AuthorizeUser": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_SetContextVariable": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_WebMethodsISService": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_InvokeAWSLambdaFunction": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_InvokeMessagingExtension": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_Log": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_RateLimiter": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_MonitorTraffic": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_CacheServiceResult": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_Route": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_MessageConfig": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_TransformRequest": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_ValidateAPISpecification": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_DataMasking": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_TransformResponse": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_CORS": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
},
"api.ibm.com_v1_ErrorProcessing": {
"isDepricated": false,
"isMandatory": true,
"isCustomComponent": true
}
}
};
// combined-source.json
// Since this file is very large, we'll create a function that returns the schema definitions
// This keeps the code more maintainable while still embedding the data
function getCombinedSource() {
return {
"api.ibm.com-v1_api.json": {
"type": "object",
"required": [
"kind",
"apiVersion",
"metadata",
"spec"
],
"additionalProperties": false,
"properties": {
"kind": {
"enum": [
"API"
],
"type": "string"
},
"apiVersion": {
"type": "string",
"default": "api.ibm.com/v1"
},
"metadata": {
"description": "Defines a message named Metadata",
"type": "object",
"required": [
"name",
"version"
],
"additionalProperties": false,
"properties": {
"description": {
"type": "string"
},
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"tags": {
"items": {
"type": "string"
},
"type": "array"
},
"type": {
"enum": [
"REST",
"SWAGGER",
"SOAP",
"GRAPHQL",
"ODATA"
],
"type": "string"
},
"version": {
"type": "string"
},
"labels": {
"type": "object",
"additionalProperties": true,
"properties": {}
}
}
},
"spec": {
"type": "object",
"required": [
"api-spec",
"policy-sequence"
],
"additionalProperties": false,
"properties": {
"api-spec": {
"type": "object",
"required": [
"$path"
],
"additionalProperties": false,
"properties": {
"$path": {
"description": "Field 'path' with JSON name '$path' accepts the value of either 'path' or '$path' from the YAML file.\nIf both 'path' and '$path' are specified, the value of '$path' takes priority.",
"type": "string"
}
}
},
"uriSchemes": {
"type": "object",
"required": [
"$ref"
],
"additionalProperties": false,
"properties": {
"$ref": {
"description": "Field 'ref' with JSON name '$ref' accepts the value of either 'ref' or '$ref' from the YAML file.\nIf both 'ref' and '$ref' are specified, the value of '$ref' takes priority.",
"type": "string"
}
}
},
"properties": {
"type": "object",
"required": [
"$ref"
],
"additionalProperties": false,
"properties": {
"$ref": {
"description": "Field 'ref' with JSON name '$ref' accepts the value of either 'ref' or '$ref' from the YAML file.\nIf both 'ref' and '$ref' are specified, the value of '$ref' takes priority.",
"type": "string"
}
}
},
"cors": {
"type": "object",
"required": [
"$ref"
],
"additionalProperties": false,
"properties": {
"$ref": {
"description": "Field 'ref' with JSON name '$ref' accepts the value of either 'ref' or '$ref' from the YAML file.\nIf both 'ref' and '$ref' are specified, the value of '$ref' takes priority.",
"type": "string"
}
}
},
"scopes": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": [
"$ref"
],
"additionalProperties": false,
"properties": {
"$ref": {
"description": "Field 'ref' with JSON name '$ref' accepts the value of either 'ref' or '$ref' from the YAML file.\nIf both 'ref' and '$ref' are specified, the value of '$ref' takes priority.",
"type": "string"
}
}
}
},
"policy-sequence": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": [
"$ref"
],
"additionalProperties": false,
"properties": {
"$ref": {
"description": "Field 'ref' with JSON name '$ref' accepts the value of either 'ref' or '$ref' from the YAML file.\nIf both 'ref' and '$ref' are specified, the value of '$ref' takes priority.",
"type": "string"
}
}
}
}
}
}
}
},
"api.ibm.com-v1_cors.json": {
"description": "The CORS related information is captured in the message CORS",
"type": "object",
"required": [
"kind",
"apiVersion",
"metadata",
"spec"
],
"additionalProperties": false,
"properties": {
"kind": {
"enum": [
"CORS"
],
"type": "string"
},
"apiVersion": {
"type": "string",
"default": "api.ibm.com/v1"
},
"metadata": {
"description": "Defines a message named Metadata",
"type": "object",
"required": [
"name",
"version"
],
"additionalProperties": false,
"properties": {
"description": {
"type": "string"
},
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"tags": {
"items": {
"type": "string"
},
"type": "array"
},
"type": {
"enum": [
"REST",
"SWAGGER",
"SOAP",
"GRAPHQL",
"ODATA"
],
"type": "string"
},
"version": {
"type": "string"
},
"labels": {
"type": "object",
"additionalProperties": true,
"properties": {}
}
}
},
"spec": {
"type": "object",
"additionalProperties": false,
"required": [
"rules"
],
"properties": {
"rules": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": [
"action",
"originList"
],
"additionalProperties": false,
"properties": {
"action": {
"type": "string",
"enum": [
"allow",
"deny"
]
},
"originList": {
"description": "Multiple instances of allowed origins can be given",
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
},
"allowCredentials": {
"description": "Credential can be allowed or not allowed",
"type": "boolean"
},
"allowMethods": {
"description": "Multiple instances allowed methods can be given",
"type": "array",
"minItems": 1,
"items": {
"type": "string"
},
"uniqueItems": true
},
"allowHeaders": {
"description": "Multiple instances of allowed headers can be given",
"minItems": 1,
"items": {
"type": "string"
},
"type": "array"
},
"maxAge": {
"description": "Single instance of maximum age can be given",
"maximum": 4294967295,
"minimum": 0,
"type": "integer"
},
"exposeHeaders": {
"type": "object",
"additionalProperties": false,
"properties": {
"predefined": {
"type": "boolean"
},
"custom": {
"type": "string"
},
"backend": {
"type": "boolean"
}
}
}
}
}
}
}
}
}
},
"api.ibm.com-v1_plan.json": {
"type": "object",
"properties": {
"apiVersion": {
"type": "string",
"default": "api.ibm.com/v1"
},
"kind": {
"enum": [
"Plan"
],
"type": "string"
},
"metadata": {
"description": "Defines a message named Metadata",
"type": "object",
"required": [
"name",
"version"
],
"additionalProperties": false,
"properties": {
"description": {
"type": "string"
},
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"tags": {
"items": {
"type": "string"
},
"type": "array"
},
"type": {
"enum": [
"REST",
"SWAGGER",
"SOAP",
"GRAPHQL",
"ODATA"
],
"type": "string"
},
"version": {
"type": "string"
},
"labels": {
"type": "object",
"additionalProperties": true,
"properties": {}
}
}
},
"spec": {
"type": "object",
"properties": {
"pricing": {
"type": "object",
"properties": {
"value": {
"type": "integer"
},
"currency": {
"type": "string"
}
}
},
"isApprovalRequired": {
"type": "boolean"
},
"qos": {
"type": "object",
"properties": {
"withQuota": {
"type": "array",
"items": {
"type": "object",
"oneOf": [
{
"required": [
"$ref"
],
"properties": {
"$ref": {
"type": "string"
}
},
"additionalProperties": false
},
{
"required": [
"unlimited"
],
"properties": {
"unlimited": {
"type": "object"
}
},
"additionalProperties": false
}
]
}
},
"withRateLimit": {
"type": "array",
"items": {
"type": "object",
"properties": {
"maxRequest": {
"type": "integer"
},
"interval": {
"type": "string"
},
"alertConfiguration": {
"type": "string",
"enum": [
"once",
"always"
]
},
"alertMessage": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
}
},
"x-datapower-config": {
"type": "object",
"properties": {
"withAssemblyCountLimit": {
"type": "array",
"items": {
"type": "object",
"properties": {
"maxRequest": {
"type": "string"
},
"hard-limit": {
"type": "boolean"
},
"cache-only": {
"type": "boolean"
},
"is-client": {
"type": "boolean"
},
"use-api-name": {
"type": "boolean"
},
"use-app-id": {
"type": "boolean"
},
"use-client-id": {
"type": "boolean"
},
"dynamic-value": {
"type": "integer"
},
"weight": {
"type": "integer"
},
"auto-decrement": {
"type": "boolean"
},
"name": {
"type": "string"
}
}
}
},
"withAssemblyRateLimit": {
"type": "array",
"items": {
"type": "object",
"properties": {
"maxRequest": {
"type": "integer"
},
"interval": {
"type": "string"
},
"cache-only": {
"type": "boolean"
},
"is-client": {
"type": "boolean"
},
"use-api-name": {
"type": "boolean"
},
"use-app-id": {
"type": "boolean"
},
"use-client-id": {
"type": "boolean"
},
"dynamic-value": {
"type": "integer"
},
"weight": {
"type": "integer"
},
"name": {
"type": "string"
}
}
}
},
"withAssemblyQuotaLimit": {
"type": "array",
"items": {
"type": "object",
"properties": {
"maxRequest": {
"type": "integer"
},
"interval": {
"type": "string"
},
"hard-limit": {
"type": "boolean"
},
"cache-only": {
"type": "boolean"
},
"is-client": {
"type": "boolean"
},
"use-api-name": {
"type": "boolean"
},
"use-app-id": {
"type": "boolean"
},
"use-client-id": {
"type": "boolean"
},
"dynamic-value": {
"type": "integer"
},
"weight": {
"type": "integer"
},
"name": {
"type": "string"
}
}
}
},
"apis": {
"type": "array",
"items": {
"type": "object",
"properties": {
"$ref": {
"type": "string"
},
"operations": {
"type": "array",
"items": {
"type": "object",
"required": [
"path",
"method"
],
"properties": {
"operationId": {
"type": "string"
},
"path": {
"type": "string"
},
"method": {
"type": "string"
},
"withQuota": {
"type": "array",
"items": {
"oneOf": [
{
"type": "object",
"required": [
"unlimited"
],
"additionalProperties": false,
"properties": {
"unlimited": {
"type": "object",
"additionalProperties": false,
"properties": {}
}
}
},
{
"type": "object",
"required": [
"name",
"maxRequest",
"interval"
],
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
},
"onLimitReach": {
"type": "string",
"enum": [
"block",
"allow"
]
},
"maxRequest": {
"type": "integer"
},
"interval": {
"type": "string"
}
}
}
]
}
}
}
}
}
}
}
}
}
}
}
}
},
"required": [
"kind",
"apiVersion",
"metadata",
"spec"
]
},
"api.ibm.com-v1_product.json": {
"type": "object",
"properties": {
"apiVersion": {
"type": "string",
"default": "api.ibm.com/v1"
},
"kind": {
"enum": [
"Product"
],
"type": "string"
},
"metadata": {
"description": "Defines a message named Metadata",
"type": "object",
"required": [
"name",
"version"
],
"additionalProperties": false,
"properties": {
"description": {
"type": "string"
},
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"tags": {
"items": {
"type": "string"
},
"type": "array"
},
"type": {
"enum": [
"REST",
"SWAGGER",
"SOAP",
"GRAPHQL",
"ODATA"
],
"type": "string"
},
"version": {
"type": "string"
},
"labels": {
"type": "object",
"additionalProperties": true,
"properties": {}
}
}
},
"spec": {
"type": "object",
"properties": {
"info": {
"type": "object",
"properties": {
"categories": {
"type": "array",
"items": {
"type": "string"
}
},
"contact": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"url": {
"type": "string"
}
}
},
"license": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"url": {
"type": "string"
}