swagger-typescript-api
swagger-typescript-api copied to clipboard
Support for readOnly properties
May I suggest a small improvement. When swagger defines a property with "readOnly":true, then the generated property should also be marked as readonly. This will help type-checking what is passed to an api, when the same type is used for input and response.
Hello @kompasbank-niels !
Yes, that will be a good idea, but this feature should work only with specific cli option like --add-read-only
While you are at it,
Don't use `object` as a type. The `object` type is currently hard to use ([see this issue](https://github.com/microsoft/TypeScript/issues/21732)).
Consider using `Record<string, unknown>` instead, as it allows you to more easily inspect and use the keys
Currently my eslinter is able to fix the readonly problem. As a build step, you can run prettier \"src/**/**.ts\" --write
to add the readonly. I also had to add
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"object": {
"message": "Use Record<string, unknown> instead",
"fixWith": "Record<string, unknown>"
},
"Object": {
"message": "Use Record<string, unknown> instead",
"fixWith": "Record<string, unknown>"
}
}
}
]
to .eslintrc so it would be able to fix the object to its own liking.