MCPcopy Create free account
hub / github.com/EvilFreelancer/openapi-to-cli / loadSpec

Method loadSpec

src/openapi-loader.ts:26–46  ·  view source on GitHub ↗
(
    profile: Profile,
    options?: {
      refresh?: boolean;
    }
  )

Source from the content-addressed store, hash-verified

24 }
25
26 async loadSpec(
27 profile: Profile,
28 options?: {
29 refresh?: boolean;
30 }
31 ): Promise<unknown> {
32 const cachePath = profile.openapiSpecCache;
33
34 if (!options?.refresh && this.fs.existsSync(cachePath)) {
35 const cached = this.fs.readFileSync(cachePath, "utf-8");
36 return JSON.parse(cached);
37 }
38
39 const spec = await this.loadAndResolveSpec(profile.openapiSpecSource);
40 this.ensureCacheDir(cachePath);
41
42 const serialized = JSON.stringify(spec, null, 2);
43 this.fs.writeFileSync(cachePath, serialized);
44
45 return spec;
46 }
47
48 private async loadAndResolveSpec(source: string): Promise<unknown> {
49 const rawDocCache = new Map<string, unknown>();

Callers 4

runApiCommandFunction · 0.80
runAddProfileFunction · 0.80
runFunction · 0.80

Calls 5

loadAndResolveSpecMethod · 0.95
ensureCacheDirMethod · 0.95
existsSyncMethod · 0.65
readFileSyncMethod · 0.65
writeFileSyncMethod · 0.65

Tested by

no test coverage detected