@@ -14,6 +14,7 @@ import type {
1414 ComponentsObject ,
1515 IPriorityRule ,
1616 IReactQueryMode ,
17+ MutuallyExclusive ,
1718 OpenAPIObject ,
1819 OperationObject ,
1920 ReferenceObject ,
@@ -29,11 +30,7 @@ import {
2930
3031export * from './generator/patchSchema' ;
3132
32- export type GenerateServiceProps = {
33- /**
34- * Swagger2/OpenAPI3 地址
35- */
36- schemaPath : string ;
33+ export type GenerateServicePropsBase = {
3734 /**
3835 * 生成的文件夹的路径
3936 */
@@ -141,10 +138,6 @@ export type GenerateServiceProps = {
141138 * 文档权限凭证
142139 */
143140 authorization ?: string ;
144- /**
145- * apifox 配置
146- */
147- apifoxConfig ?: GetSchemaByApifoxProps ;
148141 /**
149142 * 默认为false,true时使用null代替可选值
150143 */
@@ -365,6 +358,21 @@ export type GenerateServiceProps = {
365358 } ;
366359} ;
367360
361+ /**
362+ * Swagger2/OpenAPI3 地址或 Apifox 配置,两者必须填写一个
363+ */
364+ export type GenerateServiceProps = GenerateServicePropsBase &
365+ MutuallyExclusive < {
366+ /**
367+ * Swagger2/OpenAPI3 地址
368+ */
369+ schemaPath : string ;
370+ /**
371+ * apifox 配置
372+ */
373+ apifoxConfig : GetSchemaByApifoxProps ;
374+ } > ;
375+
368376export async function generateService ( {
369377 requestLibPath,
370378 schemaPath,
@@ -382,7 +390,15 @@ export async function generateService({
382390 ...rest
383391} : GenerateServiceProps ) {
384392 if ( ! schemaPath && ! apifoxConfig ) {
385- return ;
393+ throw new Error (
394+ 'Either schemaPath or apifoxConfig must be provided. Please provide at least one configuration option.'
395+ ) ;
396+ }
397+
398+ if ( schemaPath && apifoxConfig ) {
399+ throw new Error (
400+ 'schemaPath and apifoxConfig cannot be provided at the same time. Please provide only one configuration option.'
401+ ) ;
386402 }
387403
388404 let openAPI : OpenAPIObject | null = null ;
@@ -415,7 +431,7 @@ export async function generateService({
415431 const requestImportStatement = getImportStatement ( requestLibPath ) ;
416432 const serviceGenerator = new ServiceGenerator (
417433 {
418- schemaPath,
434+ ... ( schemaPath ? { schemaPath } : { apifoxConfig } ) ,
419435 serversPath : './src/apis' ,
420436 requestImportStatement,
421437 enableLogging : false ,
@@ -447,7 +463,7 @@ export async function generateService({
447463 isSupportParseEnumDesc : false ,
448464 full : true ,
449465 ...rest ,
450- } ,
466+ } as GenerateServiceProps ,
451467 openAPI
452468 ) ;
453469 serviceGenerator . genFile ( ) ;
0 commit comments