swagger-typescript-codegen
swagger-typescript-codegen copied to clipboard
[feature] immutable data structures
Generated mutable types:
interface Thing {
name: string;
children: Array<Thing>;
}
type x = ResponseWithBody<200, Array<Thing>>;
Could be immutable types:
interface ReadonlyThing {
readonly name: string;
readonly children: ReadonlyArray<Thing>;
}
type x = ReadonlyResponseWithBody<200, ReadonlyArray<ReadonlyThing>>;
This would be a breaking change, so maybe mutable types by default and opt-in to immutable types, by configuration flag.
Although my personal preference would be immutable by default.
Reason being is that I'm using functional programming paradigm, where immutable data-structures are preferred, to avoid accidental state mutation as a safety feature.
+1 on this! My expectation in my projects as well. I think to support backwardscompatibility we should make it an opt-in feature.
A bit of a side track - this brings up the good question on how we want to handle backwards compatibility overall. I.e. when do we want to say its ok to break something, and when do we want to keep backwards compatibility? I don't see a clear rule for this myself. @scottc, @Markionium - thoughts?
IMHO, hide it behind a config flag, to opt-in as an early adopter.
And later when there is a major release, change the defaults, to opt-in by default. If there is consensus among the community.
Can have an open issue to gather community feedback and votes, for a period of time. Before making a final decision.
Like it, sounds like a reasonable approach (and what many other projects do)
👍