@apistudio/apim-cli
Version:
CLI for API Management Products
58 lines (47 loc) • 2.08 kB
text/typescript
import {MasterContent, RuntimeInventory} from "@apic/smith-inventory";
import { getMasterContent } from "../resources/nano-smith-master.js";
import { getCombinedSource } from "../resources/nano-smith-schemas-json.js";
import { getDefaultVersions } from "../resources/nano-smith-defaultVersion.js";
import { getCombinedRuleset } from "../resources/nano-smith-ruleset.js";
export class LWGWRuntimeInventory extends RuntimeInventory {
public nanoMasterContent: MasterContent;
public nanoSchemaDefinitions: Record<string, any>;
public nanoDefaultVersionMap: Record<string, string>;
private nanoRulesetDefinitions: Record<string, any>;
constructor() {
super();
this.extendDefaultVersions(getDefaultVersions(),true);
this.extendRulesetDefinitions(getCombinedRuleset(),true);
this.extendSchemaDefinitions(getCombinedSource(),true);
try{
// Add custom master content
this.nanoMasterContent=getMasterContent();
// Add custom schema definitions
this.nanoSchemaDefinitions=getCombinedSource();
// Add custom default versions
this.nanoDefaultVersionMap=getDefaultVersions();
this.nanoRulesetDefinitions=getCombinedRuleset();
} catch (error) {
this.nanoSchemaDefinitions = {};
this.nanoRulesetDefinitions = {};
this.nanoDefaultVersionMap = {};
this.nanoMasterContent = {};
}
}
/**
* Hook method for subclasses to populate their extensions before schema retrieval
* This is called automatically by getSchema() before looking up the schema
* @param key - The kind name and version requested being requested
*/
public getOverriddenSchema(key: string): any {
return this.nanoSchemaDefinitions[key];
}
/**
* Hook method for subclasses to populate their extensions before schema retrieval
* This is called automatically by getSchema() before looking up the schema
* @param key - The kind name and version requested being requested
*/
public getOverriddenRule(key: string): any {
return this.nanoRulesetDefinitions[key]
}
}