forked from Onlineberatung/onlineBeratung-frontend
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate types from openapi service yaml urls
- Loading branch information
Johannes Becker
committed
Dec 22, 2020
1 parent
daa5a20
commit 5480c3c
Showing
11 changed files
with
1,821 additions
and
3 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
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,80 @@ | ||
import { promises as fs } from 'fs'; | ||
import path from 'path'; | ||
import dtsgenerator, { readSchemaFromUrl } from 'dtsgenerator'; | ||
import prettier from 'prettier'; | ||
|
||
const rawOrgUrl = 'https://raw.githubusercontent.com/CaritasDeutschland'; | ||
const services = [ | ||
{ | ||
path: 'caritas-onlineBeratung-userService/develop/api/userservice.yaml', | ||
namespace: 'UserService', | ||
out: 'userservice.d.ts' | ||
}, | ||
{ | ||
path: | ||
'caritas-onlineBeratung-agencyService/develop/api/agencyservice.yaml', | ||
namespace: 'AgencyService', | ||
out: 'agencyservice.d.ts' | ||
}, | ||
{ | ||
path: | ||
'caritas-onlineBeratung-uploadService/develop/api/uploadservice.yaml', | ||
namespace: 'UploadService', | ||
out: 'uploadservice.d.ts' | ||
}, | ||
{ | ||
path: | ||
'caritas-onlineBeratung-messageService/develop/api/messageservice.yaml', | ||
namespace: 'MessageService', | ||
out: 'messageservice.d.ts' | ||
}, | ||
{ | ||
path: 'caritas-onlineBeratung-mailService/develop/api/mailservice.yaml', | ||
namespace: 'MailService', | ||
out: 'mailservice.d.ts' | ||
}, | ||
{ | ||
path: 'caritas-onlineBeratung-liveService/develop/api/liveservice.yaml', | ||
namespace: 'LiveService', | ||
out: 'liveservice.d.ts' | ||
} | ||
]; | ||
|
||
(async () => { | ||
try { | ||
const prettierConfigFile = await prettier.resolveConfigFile(); | ||
const prettierConfig = await prettier.resolveConfig(prettierConfigFile); | ||
|
||
for (const service of services) { | ||
const schema = await readSchemaFromUrl( | ||
`${rawOrgUrl}/${service.path}` | ||
); | ||
const content = await dtsgenerator({ | ||
contents: [schema], | ||
config: { | ||
plugins: { | ||
'@dtsgenerator/replace-namespace': { | ||
map: [ | ||
{ | ||
from: ['Components', 'Schema'], | ||
to: [service.namespace] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}); | ||
|
||
await fs.writeFile( | ||
path.join('src', 'generated', service.out), | ||
prettier.format(content, { | ||
parser: 'typescript', | ||
...prettierConfig | ||
}) | ||
); | ||
} | ||
} catch (err) { | ||
console.error(`Something went wrong: ${err}`); | ||
process.exit(1); | ||
} | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.