Skip to content

Add support to include JsonPolymorph metadata in generated types #302

@atrauzzi

Description

@atrauzzi

System.Text.Json includes support for defining polymorphic types, along with a customizable discriminator field and value:

[JsonPolymorphic(TypeDiscriminatorPropertyName = "?")]
[JsonDerivedType(typeof(Subtype), "subtype")]
public interface MyType
{
    // ...
}

public class Subtype : MyType
{
    // ...
}

When outputting the type, this information is not included:

export interface MyType
{
    // ...
}

export interface Subtype extends MyType
{
    // ...
}

What would be nice, is if it was! 🎊

// ...

export interface Subtype extends MyType
{
    "?": "subtype";
    // ...
}

It's extremely valuable and important to support this because any system that is sending out types like this will need those discriminator keys and values populated. Failure to include them will result in parse errors, or create additional toil/manual overhead or bloat to communicate type information outside of the serialization pipeline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions