oatyp
v1.0.0-alpha.33
Published
Build Typescript typings from OpenAPI definitions
Downloads
14
Readme
This tools is inspired from openapi-generator, the purpose is to be able to generate Typescript typings from openapi definitions
We're using ts-morph and axios under the hood.
Why
Openapi generator is a great tool and it's working fine for simple typescript typings, which I think are the principal use case, It's used by many developers and It's maintained.
BUT, this tool is handling dozen of languages, generating client and server codes via OpenAPI, so obviously some generators are broken or have some annoying bugs (openapi-generator#6332, openapi-generator#7886, openapi-generator#4190, openapi-generator#7887). Some of this bugs are preventing us from using the tool.
I'm not really familiar with Java, and I really need something that works well with Typescript quickly. That's why I've created this package, the ambition is not to support multiple language, supporting Typescript seems fine. And generating code with ts-morph is something pretty easy.
Features
- Generate typings for each operation's body and response
- Generate class and methods for each operation, scoped by tags, named after operationId
- Exposing axios client
- Handling readonly and writeonly properties
- Removing prefixes from operationId (
role-create
→create
, which giveRole.create
if tag isRole
)
How to use
yarn global add oatyp
oatyp -s example/openapi.yaml -d example
It will use the example/openapi.yaml
file to ouput generated typescript in the example/
directory.
The --removeTagFromOperationId
option
The generated class is scoped by tags, it means that if you have multiple operations with the same tag they all will be available under this tag namespace (e.g. apiInstance.MyTag.myOperationId
).
But having the tag name in the operation id (as operation id must be unique across tags) can be redundant, that's why you can enable the --removeTagFromOperationId
option that will remove the tag name from the operation id.