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

Support nested @body #2029

Merged
merged 2 commits into from
Jun 15, 2023
Merged

Support nested @body #2029

merged 2 commits into from
Jun 15, 2023

Conversation

nguerrera
Copy link
Contributor

Fix #1141

This was originally intended to be supported and got broken during development when we added automatic body for unannotated properties at the same time. This is why the error message is hard to understand. This makes it work. The issue is still tagged design, but I consider it a bug fix.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 7, 2023

Changes in this PR will be published to the following url to try(check status of TypeSpec Pull Request Try It pipeline for publish status):
Playground: https://cadlplayground.z22.web.core.windows.net/prs/2029/

Website: https://cadlwebsite.z1.web.core.windows.net/prs/2029/

@nguerrera nguerrera force-pushed the nested-body-allow branch 2 times, most recently from 8178a9a to ca2ae0f Compare June 8, 2023 00:34
Copy link
Member

Choose a reason for hiding this comment

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

I see it ignores other properties in the nested model, is it expected
https://cadlplayground.z22.web.core.windows.net/prs/2029/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7Cgp1c2luZyBUeXBlU3BlYy5IdHRwOwoKLy8gQHJvdXRlKCJpbXBsaWNpdCIpIG9wIMgOKGE6IHN0cmluZywgYsgLKTogdm9pZM5AZmFpbC0xxj7EDDHMO0Bib2R530HFQTLKQTIoxB4gIMpHxhBiOiB7xgogx1hjyCI7yBhkzxJ9xAfKds1zM8pzMygKx2DVXc9axFfJVA%3D%3D

in the playground you can uncomment the other fail operation and those fail as expected but not if you have

 op fail3(
  b: {
    @body c: string;
    d: string;
  }
): void;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, FWIW, I think @body has had the impact already of dropping other unannotated properties on the response.

https://cadlplayground.z22.web.core.windows.net/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7Cgp1c2luZyBUeXBlU3BlYy5IdHRwOwoKQHJvdXRlKCJ0ZXN0IikKb3AgxAooKTogewogIGE6IHN0cmluZzsKICBAYm9keSBiyhN9Ow%3D%3D

We only consider top-level parameters unannotated. We could perhaps make this an error, but it feels like then we should do the same on response.

Copy link
Member

Choose a reason for hiding this comment

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

hhm yeah feels like the response here should be consistent

Copy link
Member

Choose a reason for hiding this comment

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

I think this should be an error (or at least a warning) some of the data is being lost here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to figure out how far back that response behavior goes, I think to the inception of @body

Copy link
Member

Choose a reason for hiding this comment

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

This already being inconsistent maybe we don't need to do that in this PR though and can file an issue about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

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

This looked good I think just need a new issue to talk about what should we do if there is extra unannoted properties and @body for the nested case and in response

@nguerrera nguerrera merged commit 87d39f9 into microsoft:main Jun 15, 2023
@nguerrera nguerrera deleted the nested-body-allow branch June 15, 2023 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should nested @body be allowed
2 participants