-
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
25 changed files
with
332 additions
and
61 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
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 { existsSync } from 'node:fs'; | ||
import { copyFile, readFile } from 'node:fs/promises'; | ||
import type { OpenApiToolsConfiguration, OpenApiToolsGenerator } from '../src/fwk/open-api-tools-configuration'; | ||
|
||
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
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
import type { JsonObject, JsonValue } from 'type-fest'; | ||
|
||
/** Configuration of an Open API generator */ | ||
export interface OpenApiToolsGenerator extends JsonObject { | ||
/** 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 | null; | ||
/** Sets specified global properties */ | ||
globalProperty: string | Record<string, JsonValue> | null; | ||
} | ||
|
||
/** Global configuration of Open API generators */ | ||
export interface OpenApiToolsGeneratorCli extends JsonObject { | ||
version: string; | ||
storageDir: string | null; | ||
generators: Record<string, OpenApiToolsGenerator>; | ||
} | ||
|
||
/** Global configuration of Open API Tools */ | ||
export interface OpenApiToolsConfiguration extends JsonObject { | ||
// 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.