-
Notifications
You must be signed in to change notification settings - Fork 264
OpenAPI Workspace Document Fragments #520
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
OpenAPI Workspace Document Fragments #520
Conversation
In general this PR looks really good. I have avoided creating a base class for OpenAPIElements to date. I tend to try and avoid implementation inheritance where possible. I was wondering if I we could use an extension method on IOpenApiElement, but there that would mean adding ResolveReferencedProperty to IOpenApiElement. |
public void ElementsWhichCannotBeReferencedShouldThrow(IOpenApiElement element) | ||
{ | ||
// Arrange & Act | ||
Action resolveReference = () => element.ResolveReference(new JsonPointer("/")); |
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.
Rather than adding ResolveReference to IOpenApiElement but then checking to make sure that any non-referenceable element just throws, could we instead move ResolveReference into IOpenApiReferencable?
|
||
namespace Microsoft.OpenApi.Models | ||
{ | ||
public class OpenApiElementBase : IOpenApiElement |
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.
Can we add XML document blocks for public methods?
@@ -280,5 +281,45 @@ public void SerializeAsV2(IOpenApiWriter writer) | |||
{ | |||
// Components object does not exist in V2. | |||
} | |||
|
|||
public override IOpenApiReferenceable ResolveReference(JsonPointer pointer, JsonPointer pointerFromRoot = null) |
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.
This shouldn't be supported. The components object is not allowed to be the target of a reference. If someone wants a document that contains just components then they can create an external OpenApiDocument and just add the info element as well as a components element.
So, I played around a bit and I was able to move the ResolveReference into the IOpenApiReferenceable interface. This allows us to remove it from IOpenApiElement. This guarantees that external fragments can only be referenceable components. The spec isn't very clear on this but here http://spec.openapis.org/oas/v3.0.3#reference-object it says:
This is implicitly saying you can only point to to something externally if you can also point to it internally. e.g. a component. The ability to point into a component that lives within a component is debatable. I'm not sure there is a strong use case for doing that. The risk of allowing it is we create re-usable things that are not explicitly identified as re-usable things. It would certainly make fragments easier if we didn't have to support referencing anything other than the top level element in a fragment document. I know there are some tools that take a much more liberal approach to referencing. They allow pointing to any valid structure within a document or externally. We limited this ability in OpenAPI 3 by saying that references could only point to components. |
Apologies for the slow reply to this, I've been on holiday for the last two weeks. I'll get back to you on the above points over the next few days. |
…ter to themselves
…nced on OpenApiParameter
…lacing multiple existing tests
… referencing document fragments
…nPointer class rather than a string for the JSON pointer argument
…hat are externally referencable, i.e. implement IOpenApiReferenceable
101180b
to
62b7e63
Compare
Darrel, I've re-worked my initial PR, making the following key changes:
Questions:
Do these changes better align with what you had in mind for document fragments? |
@simon-pearson I think it is a reasonable assertion to say that ReadFragment can only return things that are referenceable. I imagine there might be a few edge use cases where someone might want to construct an OpenAPIDocument from pre-existing fragments of JSON that are not necessarily referenceable, but it feels like a reasonable trade off to lose that ability for the simplicity it brings us. Also, enabling users to have whole new way of having tooling based re-use seems like bad thing thing to encourage. If you really want to do reuse outside of the boundaries of OpenAPI semantics, then I would suggest using some kind of text pre-processor. I'm going to try and finish reviewing this PR today. |
I just realized that this PR is against my OpenApiWorkspace branch, so I'm going to merge that in and get the OpenAPIWorkspace branch updated so it can merge into 1.3 milestone. |
IOpenApiReferenceable ResolveReference(JsonPointer pointer, JsonPointer pointerFromRoot = null);
method toIOpenApiElement
interface.OpenApiElementBase
class which containing an implementation of theResolveReference
method used by many of the classes which implementIOpenApiElement
.OpenApiWorkspace.ResolveReference
method to support referencing document fragments.