npm package that allows you to generate TypeScript declaration files from JSON Schema metadata supplied by Spring Data REST endpoints.
npm install spring-data-rest-json-schema-to-typescript-definitions --save-dev
Add a script named generate-model to your project's package.json, e.g.:
{
...
"scripts": {
...
"generate-model": "node node_modules/spring-data-rest-json-schema-to-typescript-definitions/dist/index.js http://localhost:8080 ./src/app/generated-model"
...
},
...
}
The main index.js takes two arguments:
- The root URL of the API (http://localhost:8080 in the example above; the script automatically appends the /profile part to the URL) generated by Spring Data REST (see https://docs.spring.io/spring-data/rest/docs/current/reference/html/#metadata.json-schema for more information).
- The directory to which the TypeScript declaration files will be written (./src/app/generated-model in the example above).
Now you can generate TypeScript declaration files from your Spring Data REST endpoints by using this command from your project's root directory:
npm run generate-model
Thanks to Boris Cherny whose json-schema-to-typescript package I could draw upon for creating this package.