History

TypeSchema has evolved while developing a new Swagger/OpenAPI code generator. During this development process we have noticed many problems which a code generator needs to solve in order to generate clean code. We have tried to solve those problems and over time TypeSchema has evolved into a separate specification which describes JSON payloads and is optimized for code generation.

Type-safe programming languages

If we look at the history of programming languages we see a trend towards type-safety. Besides strongly typed programming languages like Java, C# and Go which are automatically type-safe also weakly typed languages have added support for more type-safety, like i.e. PHP, Python and even Ruby which have all improved and added support for type-hints, for JavaScript Microsoft has even developed TypeScript which adds type-safety to JavaScript.

A big reason for this trend is that type-safe applications make it easier to find or prevent bugs. Since at you code you always have explicit properties which you can access and in case the schema changes your will directly get an error, that the property no longer exist.

TypeSchema can help you to build those type-safe applications by automatically generating clean DTOs to represent JSON payload.

Thought model

TypeSchema has a specific thought model which fits perfectly with classical OOP languages like Java, C#, PHP or TypeScript. But it supports also languages like Go, which have a different approach. In this case the generator will try to apply these concepts on generation so that you can still use them at the specification. For example Go does not support inheritance, in this case the code generator copies all inherited properties into the structure.

What is the difference to JSON Schema?

JSON Schema is a constraint system which is designed to validate JSON data. Such a constraint system is not great for code generation, with TypeSchema our focus is to model data to be able to generate high quality code.

For code generators it is difficult to work with JSON Schema since it is designed to validate JSON data. In JSON Schema you dont need to provide any keywords i.e. {} is a valid JSON Schema which basically allows every value and the defined keywords are applied based on the actual data. This means you can interpret a schema only if you have also the actual data. A code generator on the other hand needs to determine a concrete type of a schema without the actual data.

JSON Schema has many keywords which contain logic like dependencies, not, if/then/else which are basically not needed for code generators and really complicates building them.

TypeSchema does not work with JSON pointer. In TypeSchema you reference every type simply by the name i.e. Student. In JSON Schema you need to provide the path i.e. #/definitions/Student to the schema. In TypeSchema you can also reference only local types. If you want to import a remote schema you need to explicit declare it via import.

I have a problem with the generated code?

In case there are problems with the generated code you can always create an issue at our repository.

I have a question regarding the project?

You can contact us directly in case you have a question regarding the project, or you can also take a look at our repository.

Edit this page