Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
140 stars 160 forks source link

[Dpg][Bug] Support type narrow down #4096

Open ArcturusZhang opened 6 months ago

ArcturusZhang commented 6 months ago

Describe the issue or request

For instance we could have this in tsp:

model Foo {
    p: int64;
}

model Bar extends Foo {
    p: int32;
}

in which the model Bar extends Foo and narrows down the type of property p inherited from Foo.

We currently are not supporting this properly (the generator throws key already added exception).

ArcturusZhang commented 6 months ago

Narrow down could also happen with union types, such as:

model Foo {
    p: string | int32;
}

model Bar extends Foo {
    p: string;
}

or with literal unions

model Foo {
    p: "a" | "b";
}

model Bar extends Foo {
    p: "b";
}
ArcturusZhang commented 6 months ago

Even this could compile as a tsp:

model Foo {
  p: string;
}

model Bar extends Foo {
  p?: string;
}

or vice versa

model Foo {
  p?: string;
}

model Bar extends Foo {
  p: string;
}