-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4619118
commit 7ee8be6
Showing
5 changed files
with
76 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,48 @@ | ||
import {DefaultCodeGenerator} from '@oas3/codegen/ts/generator'; | ||
const fs = require('fs'); | ||
|
||
export function generate() { | ||
const filePath = './oasTestSpecs.json'; | ||
const dataStr = fs.readFileSync(filePath, 'utf-8').toString(); | ||
const data = JSON.parse(dataStr); | ||
const codeGenerator = new DefaultCodeGenerator(data); | ||
codeGenerator.generate({ | ||
targetFolderPath: './generated-files', | ||
predefinedFolderPaths: [['booking', 'core']], | ||
type OutputPath = string[]; | ||
|
||
export type GenerateConfig = { | ||
type: 'oas3'; | ||
getSpecification: () => Promise<object>; | ||
outputFolderPath: string; | ||
importRootAlias?: string; | ||
predefinedFolderOutputPaths?: OutputPath[]; | ||
}; | ||
|
||
export function generate(config: GenerateConfig) { | ||
switch (config.type) { | ||
case 'oas3': | ||
// eslint-disable-next-line no-case-declarations | ||
config.getSpecification().then(data => { | ||
const codeGenerator = new DefaultCodeGenerator(data); | ||
codeGenerator.generate({ | ||
outputFolderPath: config.outputFolderPath, | ||
predefinedFolderOutputPaths: config.predefinedFolderOutputPaths, | ||
}); | ||
}); | ||
break; | ||
default: | ||
console.error(''); | ||
} | ||
} | ||
|
||
// todo: move this code to the outside of the package | ||
export function usePackage() { | ||
generate({ | ||
type: 'oas3', | ||
getSpecification: () => { | ||
return new Promise<object>(resolve => { | ||
const filePath = './oasTestSpecs.json'; | ||
const dataStr = fs.readFileSync(filePath, 'utf-8').toString(); | ||
const data = JSON.parse(dataStr); | ||
resolve(data); | ||
}); | ||
}, | ||
outputFolderPath: './generated-files', | ||
predefinedFolderOutputPaths: [['booking', 'core']], | ||
}); | ||
} | ||
|
||
generate(); | ||
usePackage(); |
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