Open ArcturusZhang opened 1 week ago
For TypeSpec input, right now MPG convert CodeModel
into InputNamespace
, but still processing with SchemaObjectType
instead of ModelTypeProvider
, will it also cause SerializationFormat
missing?
For TypeSpec input, right now MPG convert
CodeModel
intoInputNamespace
, but still processing withSchemaObjectType
instead ofModelTypeProvider
, will it also causeSerializationFormat
missing?
we lose this information in SchemaObjectType
.
This is how it is done:
In ModelTypeProvider, we construct the properties using this ctor: https://github.com/Azure/autorest.csharp/blob/ac353cafa0e1fb5e9f81aecbd9a9930bee45c1ea/src/AutoRest.CSharp/Common/Output/Models/Types/ObjectTypeProperty.cs#L23
In SchemaObjectType, we construct the properties using this ctor:
https://github.com/Azure/autorest.csharp/blob/ac353cafa0e1fb5e9f81aecbd9a9930bee45c1ea/src/AutoRest.CSharp/Common/Output/Models/Types/ObjectTypeProperty.cs#L38
In the second ctor, there is no input parameter of SerializationFormat
, therefore it is always Default
.
We need the serialization format when writing the sample values, for example we need to know, if the property is date-time, and we have a value 2024-11-21
, how we assign this value to the property. But since the SerializationFormat
is missing in the property, it is tricky to restore it.
This difference leads an ugly workaround on sample generator.
Fixing it here might not be worthy, creating this issue to track the issue.
Issue: In typespec input, models are created by
ModelProvider
class. The properties inside this class will haveSerializationFormat
property properly assigned. But in swagger input, models are created bySchemaObjectType
class. The properties inside this class also have thisSerializationFormat
property, but its value is alwaysDefault
.Since now in the generator, only HLC and mgmt have some project using swagger as input, and HLC does not have a sample generator, this issue only impacts mgmt plane.