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

try-to-fix-the-non-required-default-value #26920

Closed

Conversation

qiaozha
Copy link
Member

@qiaozha qiaozha commented Aug 24, 2023

Packages impacted by this PR

Issues associated with this PR

Describe the problem that is addressed by this PR

What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?

Are there test cases added in this PR? (If not, why?)

Provide a list of related PRs (if any)

Command used to generate this PR:**(Applicable only to SDK release request PRs)

Checklists

  • Added impacted package name to the issue description
  • Does this PR needs any fixes in the SDK Generator?** (If so, create an Issue in the Autorest/typescript repository and link it here)
  • Added a changelog (if necessary)

@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.

Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one feels a little risky to me. Perhaps it would be easier to create a swagger transform to remove the default value for the affected SDK?

},
};

const serialized = Serializer.serialize(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a deserialize test rather than a serialize one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out :)
silly me 😂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a little bit to notice as well 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found if I change the serialize into deserialize and revert all the other changes back, the test will fail, it seems like we have some issues when handling flatten? Sorry I haven't get time to look into the details yet.
Also, as flatten will also need special serialization / deserialization in Modular, and I heard other language DPGs are using TypeSpec alias to do the flatten, I might need to investigate it a little first.

@@ -239,7 +239,7 @@ class SerializerImpl implements Serializer {
responseBody = [];
}
// specifically check for undefined as default value can be a falsey value `0, "", false, null`
if (mapper.defaultValue !== undefined) {
if (mapper.required && mapper.defaultValue !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is a pretty big change in runtime behavior. To ensure we didn't break we'd have to audit every use of defaultValue in a mapper for all SDKs we've shipped.

@qiaozha
Copy link
Member Author

qiaozha commented Aug 25, 2023

@xirzec I didn't mean to fix this issue either, I was going to create a draft PR just to see the impact of if we choose to fix it, then I had a wrong click when creating this PR :(

Actually I am wondering if we should keep this deserialize logic for default value in our Modular. Previously, I have this PR Azure/autorest.typescript#1977 to remove the default value logic because of the reasons in this comment Azure/autorest.typescript#1975 (comment). now we only add default value for constant type in Modular.

But if we have the deserialization in the current core-client, it will be another breaking when we switch from HLC to Modular, especially for mgmt plane ?

@xirzec
Copy link
Member

xirzec commented Aug 25, 2023

Actually I am wondering if we should keep this deserialize logic for default value in our Modular. Previously, I have this PR Azure/autorest.typescript#1977 to remove the default value logic because of the reasons in this comment Azure/autorest.typescript#1975 (comment). now we only add default value for constant type in Modular.

I think it's okay to do something different in the new codegen since it won't affect previously shipped clients.

But if we have the deserialization in the current core-client, it will be another breaking when we switch from HLC to Modular, especially for mgmt plane ?

This is a good question, but perhaps part of the conversion process can be us searching for any non-constant usage of defaultValue and evaluating if it matters or not. If we find there are cases where it is important to include the default value, we could potentially add an emitter option to make the behavior opt-in on a per SDK basis.

Does that sound like a reasonable approach to you?

@qiaozha
Copy link
Member Author

qiaozha commented Sep 4, 2023

close it as no need to fix it in the current core.

@qiaozha qiaozha closed this Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants