Openapi doc for typescript integration.
When we use typescript to connect restful api, there are many toos to generate the target service code. How to choose, here are some simple comparisons to reference.
example source https://github.com/superwf/ts-gear-example
π Compare
Here are 5 tools && 5 openapi doc => 5x5 results
Swagger pet store openapi v2
Fixture source: https://petstore.swagger.io/v2/swagger.json
-
β
ts-gear
- command:
yarn tsg -p tsGearPetV2
- result position:
src/service/tsGearPetV2/
- command:
Actually, run yarn tsg
without -p
will generate all service code configured in src/tsg.config.ts
-
β
pont
- command:
yarn pont
- result position:
src/service/pont/petV2/
- command:
Actually, run yarn pont
will generate all service code configured in pont-config.json
, in other fixtures case it does not need run again.
π’ The request functions generated by pont do NOTconnect request parameters type nor response data type.
-
β
openapi-generator
- command:
yarn openapiGeneratorPetV2
- result position:
src/service/openapiGeneratorPetV2/
- command:
-
β
swagger-codegen
- command:
yarn swaggerCodegenPetV2
- result position:
src/service/swaggerCodegenPetV2/
- command:
-
β
oazapfts
- command:
yarn oazapftsPetV2
- result position:
src/service/oazapftsPetV2.ts
- command:
β All tools generate result successfully.
Swagger pet store openapi v3
Fixture source: https://petstore3.swagger.io/api/v3/openapi.json
-
β
ts-gear
- command:
yarn tsg -p tsGearPetV3
- result position:
src/service/tsGearPetV3/
- command:
-
β β
pont
- command:
yarn pont
- result position:
src/service/pont/petV3/
- command:
π’ Run OK, but No definition data type generated.
-
β
openapi-generator
- command:
yarn openapiGeneratorPetV3
- result position:
src/service/openapiGeneratorPetV3/
- command:
-
β
swagger-codegen
- command:
yarn swaggerCodegenPetV3
- result position:
src/service/swaggerCodegenPetV3/
- command:
-
β
oazapfts
- command:
yarn oazapftsPetV3
- result position:
src/service/oazapftsPetV3.ts
- command:
β All tools generate result successfully.
Bad defined example 1
Fixture source: https://raw.githubusercontent.com/superwf/ts-gear-example/master/fixture/badDefined1.json
-
β
ts-gear
- command:
yarn tsg -p tsGearBadDefined1
- result position:
src/service/tsGearBadDefined1/
- command:
-
β β
pont
- β
command:
yarn pont
- βresult position:
src/service/pont/badDefined1/
- β
command:
π’ Run OK, but No meaningful code generated.
-
β β
openapi-generator
- command:
yarn openapiGeneratorBadDefined1
- β result:
error Command failed with exit code 1
- command:
the command tell me use --skip-validate-spec
to skip validate, so try again with it.
command:
yarn openapiGeneratorBadDefined1 -- --skip-validate-spec
result position:
src/service/openapiGeneratorBadDefined1/
π’ Run OK, but many data type definition missing.
-
β β
swagger-codegen
- command:
yarn swaggerCodegenBadDefined1
- β result position:
src/service/swaggerCodegenBadDefined1/
- command:
π’ Run OK, but many data type definition missing.
-
β
oazapfts
- command:
yarn oazapftsBadDefined1
- result:
UnhandledPromiseRejectionWarning: MissingPointerError: Token "ReplyVO«PageVO«FieldDefListVO»»" does not exist
- command:
Bad defined example 2
Fixture source: https://raw.githubusercontent.com/superwf/ts-gear-example/master/fixture/badDefined2.json
-
β
ts-gear
- command:
yarn tsg -p tsGearBadDefined2
- result position:
src/service/tsGearBadDefined2/
- command:
-
β β
pont
- command:
yarn pont
- result position:
src/service/pont/badDefined2/
- command:
π’ No meaningful code generated.
-
β β
openapi-generator
- command:
yarn openapiGeneratorBadDefined2
- result:
error Command failed with exit code 1
- command:
the command tell me use --skip-validate-spec
to skip validate, so try again with it.
command:
yarn openapiGeneratorBadDefined2 -- --skip-validate-spec
result position:
src/service/openapiGeneratorBadDefined2/
π’ Run OK, but many data type definition missing.
-
β β
swagger-codegen
- command:
yarn swaggerCodegenBadDefined2
- result position:
src/service/swaggerCodegenBadDefined2/
- command:
π’ Many data type definition missing and type name error.
-
β
oazapfts
- command:
yarn oazapftsBadDefined2
- result:
UnhandledPromiseRejectionWarning: MissingPointerError: Token "ListVO" does not exist
- command:
Bad defined example 3
Fixture source: https://raw.githubusercontent.com/superwf/ts-gear-example/master/fixture/badDefined3.json
-
β
ts-gear
- command:
yarn tsg -p tsGearBadDefined3
- result position:
src/service/tsGearBadDefined3/
- command:
-
β
pont
- command:
yarn pont
- result position:
src/service/pont/badDefined3/
- command:
-
β β
openapi-generator
- β
command:
yarn openapiGeneratorBadDefined3
- β result:
src/service/openapiGeneratorBadDefined3/
- β
command:
π’ Run OK, but result code has syntax error, can not be used directly.
-
β β
swagger-codegen
- command:
yarn swaggerCodegenBadDefined3
- result position:
src/service/swaggerCodegenBadDefined3/
- command:
π’ Run OK, but result code has syntax error, can not be used directly.
-
β
oazapfts
- command:
yarn oazapftsBadDefined3
- result:
UnhandledPromiseRejectionWarning: MissingPointerError: Token "Map" does not exist
- command:
Summary
tool | bad doc compatibleπ | comment output | Generic type | independent request export | more language support | mock data | custom request logic | translate none english | filter api | openapi V2 & V3 |
---|---|---|---|---|---|---|---|---|---|---|
ts-gear | β | β | β π | β | β | β | β | β | β | β |
pont | β β | β | β | β | β | β | β | β | β | β |
openapi-generator | β | β | β π | β | β | β | β | β | β | β |
swagger-codegen | β | β | β π | β | β | β | β | β | β | β |
oazapfts | β | β | β π | β | β | β | β | β | β | β |
Openapi-generator
andSwagger-codegen
are the most common industry general tools, they are powerfull for supportting many program languages and special env.Only
pont
andts-gear
use configuration file, all other tools just use cli arguments.ts-gear
has proved its self the compatibility with bad defined openapi doc.
Generic type π
Whether can generate generic type successfully, depends on the complement of openapi doc definition.
Top comments (0)