Exclude sealed marker types from TypeScript output#1128
Open
almarzn wants to merge 1 commit intovojtechhabarta:mainfrom
Open
Exclude sealed marker types from TypeScript output#1128almarzn wants to merge 1 commit intovojtechhabarta:mainfrom
almarzn wants to merge 1 commit intovojtechhabarta:mainfrom
Conversation
Sealed interfaces/classes without @JsonSubTypes are considered 'markers'
that just group related types. These should not appear in the generated
TypeScript output.
For example, with this hierarchy:
@JsonTypeInfo sealed interface Quantity
sealed interface DecimalAmount extends Quantity
record Gram implements DecimalAmount
record Kilogram implements DecimalAmount
record Unspecified implements Quantity
Before:
interface Gram extends DecimalAmount
interface DecimalAmount extends Quantity
type QuantityUnion = Gram | Kilogram | ... | DecimalAmount
After:
interface Gram extends Quantity
type QuantityUnion = Gram | Kilogram | ... | Unspecified
Changes:
- Add excludeSealedMarkerTypes() in ModelCompiler
- Add isSealedMarker() to detect sealed types without Jackson annotations
- Add getSealedPermittedSubclasses() to expand nested sealed markers
- Add findNonSealedParent() to skip markers in inheritance chain
- Add withParent() method to TsBeanModel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for excluding sealed interface/class markers from generated TypeScript output.
Problem
When using sealed interfaces to organize a type hierarchy, intermediate sealed types that don't have
@JsonSubTypeswere being generated as TypeScript interfaces and included in unions, even though they serve only as grouping markers.Example:
Before this change:
After this change:
Solution
Added
excludeSealedMarkerTypes()transformation in ModelCompiler that:@JsonSubTypesor@JsonTypeInfoas markersChanges
ModelCompiler.java: AddedexcludeSealedMarkerTypes(),isSealedMarker(),getSealedPermittedSubclasses(),findNonSealedParent()TsBeanModel.java: AddedwithParent()methodSealedInterfaceTest.java: Added test for sealed marker exclusionTesting
SealedInterfaceTest.testSealedInterfaceMarkerExcluded()passes