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

fix: side effects in tag references #2032

Merged
merged 4 commits into from
Jan 15, 2025
Merged

fix: side effects in tag references #2032

merged 4 commits into from
Jan 15, 2025

Conversation

baywet
Copy link
Member

@baywet baywet commented Dec 31, 2024

This fixes multiple issues:

  • tag references are not like other component references. The tag in the operation is just a string. We had a lot of special casing, etc...
  • lot of side effects where we were impacting the source tag by assigning things to the reference. As discussed in v2 - security - correct the proxy design implementation #1998
  • fixes references not being resolvable in a lot of contexts due to a missing document reference.

We should still break the inheritance, and use a base abstract class as well.

Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
@darrelmiller
Copy link
Member

I'm not sure I agree with this. Tag references are very similar to using $id to reference a Schema, where the target object is implicitly created. I agree that it was a bit of a stretch when $refs could only use locators, but now that we need to support $refs as identifiers, I think there is a strong parallel.

@baywet
Copy link
Member Author

baywet commented Dec 31, 2024

The previous model results in tons of side effects.
I get the fact that we want to facilitate the readers life, but anybody making changes and not paying attention to the underlying specification is in for troubles.

A simple example:

  • parse a description with tags
  • on an operation, grab a tag
  • add an extension to it
  • you've now updated that tag for the whole document.

Same goes for the description, the tag name etc...

@baywet baywet added this to the v2 - preview5 milestone Jan 8, 2025
Copy link

sonarqubecloud bot commented Jan 9, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
75.9% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@darrelmiller
Copy link
Member

A simple example:

parse a description with tags
on an operation, grab a tag
add an extension to it
you've now updated that tag for the whole document.
Same goes for the description, the tag name etc..

Isn't that the expected behaviour?

@baywet
Copy link
Member Author

baywet commented Jan 15, 2025

A simple example:
parse a description with tags
on an operation, grab a tag
add an extension to it
you've now updated that tag for the whole document.
Same goes for the description, the tag name etc..

Isn't that the expected behaviour?

From a proxy design pattern, sure. But from a functional point of view, I'd say it's pretty confusing/could lead to nasty production bug since the object model is the same, and the behaviour was different. The message I'm trying to convey here is that we're in control of what properties (or operations) can be proxied, IMHO we should allow reads, and then ask people to go through the Target property for writes. That of course leaves a big question for collections.

@@ -10,21 +12,24 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Tag Object Reference
/// </summary>
public class OpenApiTagReference : OpenApiTag
public class OpenApiTagReference : OpenApiTag, IOpenApiReferenceable
Copy link
Member

Choose a reason for hiding this comment

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

Why does this need to implement IOpenApiReferenceable? None of the other proxy objects do.

Copy link
Member

Choose a reason for hiding this comment

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

Apparently it is a bug in every other reference class because the walker expects all references to implement IOpenApiReferencable /cc @MaggieKimani1

@darrelmiller
Copy link
Member

Sorry, I was being slow. I agree that editing the reference should not edit the target. I agree with your changes.

@baywet baywet merged commit 717deb0 into dev Jan 15, 2025
11 of 12 checks passed
@baywet baywet deleted the fix/tag-references branch January 15, 2025 21:46
@baywet
Copy link
Member Author

baywet commented Jan 15, 2025

Sorry, I was being slow. I agree that editing the reference should not edit the target. I agree with your changes.

That just means the vacations were good!

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.

2 participants