-
Notifications
You must be signed in to change notification settings - Fork 264
Remove IDictionary implementation, remove OpenApiElement and add IOpenApiSerializable #94
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
Conversation
…tionary - We implement this by creating a new EqualityComparer and use that in the dictionary constructor. - Equality only considers Reference.Id since that's what the final document actually cares about. If there are two SecurityScheme with same Reference.Id, they should not both be added to the Schemes dictionary since that will at the end yield the same display string and violate the spec. We also don't need to worry about equality of other downstream objects in the SecurityScheme object. - Unit tests for this equality/dictionary implementation in in SecuirtyRequirementTests. Also, note that the FullDocumentReaderTests now can compare objects directly.
…his is an OpenAPI-related object. - The objects in the spec (that are serializable with WriteAsV2 and WriteAsV3) are marked as IOpenApiSerializable. This allows us to still indicate IOpenApiAny as IOpenApiElement but we will not have to implement WriteAsV2 and WriteAsV3 for them. - Using IOpenApiElement allows us to inherit the dictionary-like objects (Paths, Responses, and SecurityRequirement) directly from the .NET Dictionary<T1, T2> class without having to resort to IDictionary and having to re-implment all the dictionary functionalities. Because of this, OpenApiDictionary is no longer needed.
@PerthCharern, |
{ | ||
return streamReader.ReadToEnd(); | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm starting to think these Serializer methods can be made a functionality exposed to customers instead of just for testing.
That way, if a customer simply wants to get string representation of the doc (without having to worry about creating a Stream), it would be just a one method call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -59,7 +59,7 @@ public void AddPathItem(RuntimeExpression expression, OpenApiPathItem pathItem) | |||
/// <summary> | |||
/// Serialize <see cref="OpenApiCallback"/> to Open Api v3.0 | |||
/// </summary> | |||
internal override void WriteAsV3(IOpenApiWriter writer) | |||
public void WriteAsV3(IOpenApiWriter writer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally, we discussed it with @darrelmiller to keep these two methods as internal?
Is there any reason we should make them as public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
These methods should be useful for our customers to serialize inner objects (not just documents). I don’t see any disadvantages of exposing them.
-
Talked to Darrel yesterday and he didn’t mind.
-
IIRC, the reason we made them internal was solely because we didn’t know how to name these properly. If that’s the only concern, we can have a discussion regarding naming later. I don’t think we should decide on their access level for this reason alone.
-
Regardless, I can take a look at these whole Serailize stuff again along with adding the Searialize as string extensions to the model in the next PR.
public static string SerializeAsJson<T>(this T element, | ||
OpenApiSpecVersion version = OpenApiSpecVersion.OpenApi3_0) | ||
where T : OpenApiElement | ||
public static string SerializeAsJson<T>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Let us take more consideration about making things public. Once it's public, it's hard to change in the later version, because we should avoid introducing any breaking changes in the later version. Besides, what do we want our customers to use these "WriteV2(3)" method? |
Thanks for pointing this out. I was a little confused with how we allow our customers to serialize our contracts. I forgot they could already use the Serialize methods to serialize any IOpenApiSerializable. I will try to revert this, but that means I might need to make a few more tweaks, given the limitation of interfaces. In reply to: 345372185 [](ancestors = 345372185) |
…element. - WriteAsVX is changed to SerializeAsVX. The cutoff point between Write and Serialize is decided on what is being transformed and by whom: - If the whole object is translated into a stream or string, we use Serialize terminology. If the writer (TextWriter) is just adding letters, then that's a Write action. - Serialize methods (to string) in the Test projects are moved to Core.
@scott-lin and I just spent some time discussing this, and here's what makes sense in our point of view:
In reply to: 345374504 [](ancestors = 345374504,345372185) |
Aright,please go ahead and let's think it more. |
Remove OpenApiElement abstract class. Use IOpenApiElement interface throughout to indicate this is an OpenAPI-related object.
Using IOpenApiElement allows us to inherit the dictionary-like objects (Paths, Responses, and SecurityRequirement) directly from the Dictionary<T1, T2> class without having to use IDictionary and re-implment all the dictionary functionalities. Because of this, OpenApiDictionary is no longer needed.
The objects in the spec (which are serializable with WriteAsV2 and WriteAsV3) are marked as IOpenApiSerializable. This allows us to still indicate IOpenApiAny as IOpenApiElement but we will not have to implement WriteAsV2 and WriteAsV3 for IOpenApiAny.