SchemaType is set incorrectly for Simple Enum - SealedChoice vs Choice
See original GitHub issueDescribe the bug Use the following JSON Snippet to generate SDK (I used Typescript SDK. But it does not matter. You can use any language)
{
"PrintInfo": {
"title": "PrintInfo",
"type": "object",
"properties": {
"pngData": {
"type": "string",
"format": "byte"
},
"printMediaType": {
"type": "string",
"enum": [
"ENDLOS",
"MEHRFAHRTENKARTE"
]
}
}
}
}
Expected behavior With the above JSON, I have checked the code model received by the SDK Generator. The SchemaType of ‘printMediaType’ is set to ‘SchemaType.Choice’. It should have been ‘SchemaType.SealedChoice’ (Since this enum is not extensible).
Additional context Basically, a Sealed Choice means (as the name) suggests it is sealed/fixed i.e not extensible. As you mentioned, if you define an enum, then add an x-ms-enum with modelAsString set to false, then it is sealed/fixed (SchemaType.SealedChoice). Autorest Core handles this correctly.
Next scenario is if you define an enum, then add an x-ms-enum with modelAsString set to true, then it is extensible (SchemaType.Choice). Autorest COre handles this scenario also correctly.
The problem is with the last scenario. If you merely define an enum value (with no x-ms-enum property) then it means the enum value is fixed/sealed. The autorest must consider it as SchemaType.SealedChoice. But, it is not doing so. It is considering it as SchemaType.Choice making in extensible. This is the scenario I am trying to get fixed.
@daviwil @timotheeguerin FYI…
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top GitHub Comments
Thank you, the
$path
got it working for us.For anyone interested in this issue, I got it working using this method for the name generation:
The
$path
is an array which contains the keys of the document down to the enum. To generate unique and descriptive names the name of the schema is combined with the name of the property. If we have an enum outside of an object we only take the schema since the property isn’t defined in this case. In our example this would generate the sealed union typeexport type PrintInfoPrintMediaType = "ENDLOS" | "MEHRFAHRTENKARTE";
@JonasMa do you mean the name of the schema? You have access to more context in the transform See here for the available variables.
You could use
$path
to retrieve the name of the key if that’s what you are looking for.