File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import fs from 'fs'
55import { default as optimizeTypesUtil } from './optimizeTypes'
66import onCreateRoute from './onCreateRoute'
77
8- export type Config = {
8+ type SingleConfig = {
99 /**
1010 * Http address of JSON OpenAPI schema to your API
1111 * @required
@@ -54,7 +54,17 @@ export type Config = {
5454 typeWhitelist ?: string [ ]
5555}
5656
57- export const generateFromConfig = ( {
57+ export type Config = SingleConfig | SingleConfig [ ]
58+
59+ export const generateFromConfig = ( config : Config ) => {
60+ if ( Array . isArray ( config ) )
61+ return Promise . all (
62+ config ?. map ( configuration => generateSingleApi ( configuration ) )
63+ )
64+ return generateSingleApi ( config )
65+ }
66+
67+ const generateSingleApi = ( {
5868 url,
5969 filePath,
6070 outDir = './service/' ,
@@ -63,7 +73,7 @@ export const generateFromConfig = ({
6373 include = [ ] ,
6474 optimizeTypes = true ,
6575 typeWhitelist = [ ]
66- } : Config ) => {
76+ } : SingleConfig ) => {
6777 const OUTPUT_PATH = path . resolve ( process . cwd ( ) , outDir )
6878 const TEMPLATES_PATH = path . resolve ( __dirname , '../templates/' )
6979
Original file line number Diff line number Diff line change @@ -20,10 +20,14 @@ async function main() {
2020 const config = ( await import ( pathToFileURL ( CONFIG_PATH ) . href ) )
2121 . default as Config
2222
23- if ( ! config . url ) {
23+ const isUrlMissing = Array . isArray ( config )
24+ ? ! config . every ( item => item . url )
25+ : ! config . url
26+
27+ if ( isUrlMissing ) {
2428 console . log (
2529 chalk . yellow (
26- '"url" property in sparing-open-api.config.js is not defined. Service creation aborted!'
30+ '"url" property is not defined. Service creation aborted!'
2731 )
2832 )
2933 return
You can’t perform that action at this time.
0 commit comments