-
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
feb34b9
commit ae15ce9
Showing
5 changed files
with
421 additions
and
370 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { readFileSync, writeFileSync } from 'fs' | ||
|
||
const s = JSON.parse(readFileSync('./test.json')) | ||
|
||
const { definitions: { RepositoryItem: { properties: RepositoryItem }, Configuration: { properties: Config } } } = s | ||
let content = 'export interface IRepositoryItem {' | ||
|
||
for(const [k, v] of Object.entries(RepositoryItem)) { | ||
content += ` ${k} : ${(() => { | ||
if(v?.$ref?.endsWith('ConfigurationReference')) return 'IRepositoryConfiguration' | ||
if(v?.type == 'boolean') return 'boolean' | ||
if(v?.type == 'integer') return 'number' | ||
if(v?.type == 'string') return 'string' | ||
if(v?.type == 'number') return 'number | Float' | ||
if(v?.type == 'array') { | ||
let type = v.items?.type | ||
if(!type) { | ||
console.log('failed', k) | ||
return 'ERROR' | ||
} | ||
if(type == 'integer') return '(number | Float)[]' | ||
return `${type}[]` | ||
} | ||
console.log('unknown type', k, v) | ||
})()} | Raw\n` | ||
} | ||
content += '}' | ||
content += 'export interface IRepositoryConfiguration {' | ||
for(const [k, v] of Object.entries(Config)) { | ||
content += ` ${k} : ${(() => { | ||
if(v?.type == 'boolean') return 'boolean' | ||
if(v?.type == 'integer') return 'number | Float' | ||
if(v?.type == 'string') return 'string' | ||
if(v?.type == 'number') return 'number' | ||
if(v?.type == 'array') { | ||
let type = v.items?.type | ||
if(!type) { | ||
console.log('failed', k) | ||
return 'ERROR' | ||
} | ||
if(type == 'integer') return '(number | Float)[]' | ||
return `${type}[]` | ||
} | ||
console.log('unknown type', k, v) | ||
})()} | Raw\n` | ||
} | ||
content += '}' | ||
writeFileSync('./test.types.ts', content) |
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.