Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks done
qiaozha opened this issue Sep 25, 2024 · 2 comments
Open
4 tasks done

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

qiaozha opened this issue Sep 25, 2024 · 2 comments
Labels
bug Something isn't working lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@qiaozha
Copy link
Member

qiaozha commented Sep 25, 2024

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

  • Follow our Code of Conduct
  • Check that this issue is about the Azure libraries for typespec. For bug in the typespec language or core libraries file it in the TypeSpec repo
  • Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.
@qiaozha qiaozha added the bug Something isn't working label Sep 25, 2024
@qiaozha
Copy link
Member Author

qiaozha commented Sep 25, 2024

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

@qiaozha
Copy link
Member Author

qiaozha commented Sep 27, 2024

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.

@tadelesh tadelesh added lib:tcgc Issues for @azure-tools/typespec-client-generator-core library and removed needs-area labels Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lib:tcgc Issues for @azure-tools/typespec-client-generator-core library
Projects
None yet
Development

No branches or pull requests

2 participants