OpenAPITools / OpenAPITools/openapi-generator
[REQ][typescript-angular] new config option to generate all model properties as readonly
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
The current typescript-angular generator somehow misinterprets the meaning of the OAS readOnly field of a property definition in a schema object. Please, see the actual definition of this attribute from the OAS 3.0.3 spec.
| Field Name | Type | Description |
|---|---|---|
| readOnly | boolean | Relevant only for Schema "properties" definitions. Declares the property as “read only”. This means that it MAY be sent as part of a response but SHOULD NOT be sent as part of the request. If the property is marked as readOnly being true and is in the required list, the required will take effect on the response only. A property MUST NOT be marked as both readOnly and writeOnly being true. Default value is false. |
Instead, the generator treats schema object properties marked with readOnly: true field as readonly marked typescript properties, which makes those properties immutable (please, see Typescript offical doc).
The following code is an excerpt from the current generator template, which implements the described behavior:
The OpenAPI spec doesn't tell anything about immutability, it just speaks about the property presence in the DTO. As a matter of fact, the immutability of a property is a desired behavior in request DTOs too.
My proposal is to add a new config option for the angular-typescript generator which instructs the generation process to mark all the properties of the DTOs as readonly, whether they are "read" or "write" DTOs in the OpenAPI spec, and ignore the readOnly OAS field altogether.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/openapi-generator/src/main/resources/typescript-angular/modelGeneric.mustache and compare its handling of the OAS readOnly field with the requested behavior. Trace how typescript-angular generator options are declared, then verify that the new option makes every generated DTO property readonly while ignoring readOnly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100