Skip to content

Commit

Permalink
feat: openapiPath support remote URL
Browse files Browse the repository at this point in the history
  • Loading branch information
liangskyli committed Apr 21, 2023
1 parent 70603a4 commit 5c3660c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/openapi-gen-ts/src/gen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { genInterfaceFile } from './gen-interface-file';
import { genSchemaDataFile } from './gen-json-schema-file';

export type IGenTsDataOpts = {
openapiPath: string;
openapiPath: string | URL;
genTsDir?: string;
prettierOptions?: IPrettierOptions;
/**
Expand Down Expand Up @@ -49,14 +49,17 @@ const genTsData = async (opts: IGenTsDataOpts) => {

const genTsPath = path.join(genTsDir, 'schema-api');
const genTsAbsolutePath = getAbsolutePath(genTsPath);
const openapiAbsolutePath = getAbsolutePath(openapiPath);
let schema = openapiPath;
if (!fs.existsSync(getAbsolutePath(genTsDir))) {
console.error(colors.red(`genTsDir not exits: ${genTsDir}`));
process.exit(1);
}
if (!fs.existsSync(openapiAbsolutePath)) {
console.error(colors.red(`openapiPath not exits: ${openapiPath}`));
process.exit(1);
if (typeof openapiPath === 'string') {
schema = getAbsolutePath(openapiPath);
if (!fs.existsSync(schema)) {
console.error(colors.red(`openapiPath not exits: ${openapiPath}`));
process.exit(1);
}
}

removeFilesSync(genTsAbsolutePath);
Expand All @@ -65,7 +68,7 @@ const genTsData = async (opts: IGenTsDataOpts) => {
fs.ensureDirSync(genTsAbsolutePath);

// openapi生成TS类型文件
const schemaString = await openapiTS(openapiAbsolutePath, {
const schemaString = await openapiTS(schema, {
commentHeader: `${fileTip}`,
postTransform: (type: string) => {
return type.replace(/\\\\"/gi, '\\"');
Expand Down

0 comments on commit 5c3660c

Please sign in to comment.