Azure / typespec-azure

About TypeSpec Azure Libraries
https://azure.github.io/typespec-azure/
MIT License
15 stars 40 forks source link

[Bug]: Discriminated subtype is missing in models from sdkPackages #1605

Open qiaozha opened 1 month ago

qiaozha commented 1 month ago

Describe the bug

In the following typespec,

    @discriminator("kind")
    model Pet {
      kind: string;
      name: string;
      weight?: float32;
    }
    model Cat extends Pet {
      kind: "cat";
      meow: int32;
    }
    model Dog extends Pet {
      kind: "dog";
      bark: string;
    }
    op read(): { @body body: Cat };

The Dog subtype is not referenced by any operation, sdkPackage is not returning this subtype image

however, inside the Pet's model definition, it still has Dog's type being referred in the discriminatedSubtypes.
image

which is confusing to me, if we generate the serializer/deserializer for Pet, we will have to a Dog serializer for it as it's polymorphic base and the discriminator value has a dog in it. but Dog's definition is missing.

I think we could have two possible solutions for it. Depends on how we want to interpret this.

  1. delete the Dog subtype from Pet's discriminated subtypes.
  2. return the Dog subtype in sdkPackage.models

Reproduction

N/A

Checklist

qiaozha commented 1 month ago

the Dog type we get from from discriminatedSubtypes doesn't have the correct usage flags.

image
qiaozha commented 1 month ago

Summary of conclusion in 2024-09-26 dev office hours meeting:

we should have Dog in models and set the usage the same as in Pet's discriminatedSubtypes. but it should be a low priority thing.