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

Swagger input generator is handling SerializationFormat on properties differently from the typespec generator #5158

Open
ArcturusZhang opened this issue Nov 11, 2024 · 2 comments
Labels
Mgmt This issue is related to a management-plane library.

Comments

@ArcturusZhang
Copy link
Member

ArcturusZhang commented Nov 11, 2024

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 have SerializationFormat property properly assigned.
But in swagger input, models are created by SchemaObjectType class. The properties inside this class also have this SerializationFormat property, but its value is always Default.

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.

@ArcturusZhang ArcturusZhang added the Mgmt This issue is related to a management-plane library. label Nov 11, 2024
@live1206
Copy link
Member

For TypeSpec input, right now MPG convert CodeModel into InputNamespace, but still processing with SchemaObjectType instead of ModelTypeProvider, will it also cause SerializationFormat missing?

@ArcturusZhang
Copy link
Member Author

For TypeSpec input, right now MPG convert CodeModel into InputNamespace, but still processing with SchemaObjectType instead of ModelTypeProvider, will it also cause SerializationFormat missing?

we lose this information in SchemaObjectType.
This is how it is done:
In ModelTypeProvider, we construct the properties using this ctor:

public ObjectTypeProperty(FieldDeclaration field, InputModelProperty? inputModelProperty)

In SchemaObjectType, we construct the properties using this ctor:
public ObjectTypeProperty(MemberDeclarationOptions declaration, string parameterDescription, bool isReadOnly, InputModelProperty? inputModelProperty, CSharpType? valueType = null, bool optionalViaNullability = false)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mgmt This issue is related to a management-plane library.
Projects
None yet
Development

No branches or pull requests

2 participants