mtennoe / swagger-typescript-codegen

A Swagger Codegenerator tailored for typescript.
Apache License 2.0
140 stars 52 forks source link

[feature] decoder functions #99

Open scottc opened 4 years ago

scottc commented 4 years ago

In a perfect world, everyone would version their immutable apis and never introduce breaking changes.

But in reality co-workers could introduce breaking api changes.

There could potentially be a mismatch between the actual runtime json response and the static compile time typescript types.

This can cause runtime errors, but could be caught by the typechecker / developer at compile time.

So a good solution is to implement decoder functions at the boundaries of the application, which are run-time type checks, with some static types on top.

If the run-time type check fails, the endpoint could return an error, in the form of a boxed result type.

Some examples and helper libraries:

https://github.com/nvie/decoders https://github.com/swissmanu/spicery https://github.com/gcanti/io-ts https://github.com/fabiandev/ts-runtime

mtennoe commented 4 years ago

This is a great idea! Would definitely add an extra layer of protection. Some things we should ensure (imo):