-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): generate an sdk with spec from npm
- Loading branch information
Showing
26 changed files
with
324 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env node | ||
|
||
/* | ||
* Update the OpenAPI spec from an NPM package | ||
*/ | ||
|
||
import type { OpenApiToolsConfiguration, OpenApiToolsGenerator } from '@ama-sdk/core'; | ||
import { existsSync } from 'node:fs'; | ||
import { copyFile, readFile } from 'node:fs/promises'; | ||
|
||
void (async () => { | ||
const packageName = process.argv[2]; | ||
const packagePath = process.argv[3]; | ||
|
||
if (!packageName || !packagePath) { | ||
console.error('Need to provide packageName and packagePath\nUsage: amasdk-update-spec-from-npm <package-name> <package-path>'); | ||
process.exit(-1); | ||
} | ||
|
||
const specSourcePath = require.resolve(`${packageName}/${packagePath}`); | ||
const openApiConfigPath = './openapitools.json'; | ||
let specDestinationPath = './openapi.yml'; | ||
if (existsSync(openApiConfigPath)) { | ||
const openApiConfig = JSON.parse(await readFile(openApiConfigPath, {encoding: 'utf8'})) as OpenApiToolsConfiguration; | ||
const generators = Object.values(openApiConfig['generator-cli']?.generators ?? {}); | ||
specDestinationPath = generators.find((generatorConfig: OpenApiToolsGenerator) => generatorConfig.inputSpec)?.inputSpec || specDestinationPath; | ||
} | ||
|
||
await copyFile(specSourcePath, specDestinationPath); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/@ama-sdk/core/src/fwk/open-api-tools-configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export interface OpenApiToolsGenerator { | ||
/** Location of the OpenAPI spec, as URL or file */ | ||
inputSpec: string; | ||
/** Output path for the generated SDK */ | ||
output: string; | ||
/** Generator to use */ | ||
generatorName: string; | ||
/** Path to configuration file. It can be JSON or YAML */ | ||
config?: string; | ||
/** Sets specified global properties */ | ||
globalProperty?: string | Record<string, any>; | ||
} | ||
|
||
export interface OpenApiToolsGeneratorObject { | ||
[generatorName: string]: OpenApiToolsGenerator; | ||
} | ||
|
||
export interface OpenApiToolsGeneratorCli { | ||
version: string; | ||
storageDir?: string; | ||
generators: OpenApiToolsGeneratorObject; | ||
} | ||
|
||
export interface OpenApiToolsConfiguration { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
'generator-cli': OpenApiToolsGeneratorCli; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.