OpenAPI.NET.OData icon indicating copy to clipboard operation
OpenAPI.NET.OData copied to clipboard

OpenAPIReference objects are not created correctly

Open darrelmiller opened this issue 3 years ago • 2 comments

When creating OpenAPI model objects that are just references to another model object they need to be marked as unresolved so that reference resolution can replace them with the resolved object.

When an object is created and assigned an OpenApiReference like this,

 OpenApiSchema derivedTypeSchema = new()
				{
                    Reference = new OpenApiReference
                    {
                        Type = ReferenceType.Schema,
                        Id = derivedType.FullName()
                    }
                };

there needs to be an assignment to the UnresolvedReference property.

 OpenApiSchema derivedTypeSchema = new()
				{
                    UnresolvedReference = true,
                    Reference = new OpenApiReference
                    {
                        Type = ReferenceType.Schema,
                        Id = derivedType.FullName()
                    }
                };

Without this flag set, client code will assume that the object is just an empty model object. The presence of an OpenApiReference object is not sufficient to identify a reference as model objects that are targeted by the reference will also have the OpenApiReference set.

darrelmiller avatar Feb 04 '22 20:02 darrelmiller

This still seems to be an issue and is blocking this https://github.com/microsoftgraph/microsoft-graph-devx-api/issues/1144

darrelmiller avatar Aug 18 '22 15:08 darrelmiller

@millicentachieng See this issue https://github.com/microsoft/OpenAPI.NET/issues/1025

darrelmiller avatar Sep 29 '22 14:09 darrelmiller

@millicentachieng OpenAPI.NET 1.4.4-preview1 is now out. Could you try the code that runs the OpenApiReferenceResolver after creating the OpenAPIDocument so that it is valid when returned? This will allow DevX API to stop cloning the document.

darrelmiller avatar Oct 27 '22 14:10 darrelmiller

Resolving references is not the solution we are looking for. The OpenApiReferenceResolver replaces a reference with its populated object equivalent.

More details here.

millicentachieng avatar Feb 06 '23 06:02 millicentachieng