Skip to content

Commit

Permalink
PR review fix
Browse files Browse the repository at this point in the history
Check for: Context.Settings.EnableDerivedTypesReferencesForResponses
  • Loading branch information
irvinesunday committed Jun 26, 2024
1 parent 9bafba9 commit 33ffc43
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,23 @@ protected override void SetExtensions(OpenApiOperation operation)
protected override void SetResponses(OpenApiOperation operation)
{
if (ComplexPropertySegment.Property.Type.IsCollection())
{
SetCollectionResponse(operation, ComplexPropertySegment.ComplexType.FullName());
}
else
SetSingleResponse(operation, ComplexPropertySegment.ComplexType.FullName());
{
OpenApiSchema schema = new()
{
UnresolvedReference = true,
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = ComplexPropertySegment.ComplexType.FullName()
}
};

SetSingleResponse(operation, schema);
}

operation.AddErrorResponses(Context.Settings, false);
base.SetResponses(operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,33 @@ protected override void SetBasicInfo(OpenApiOperation operation)
protected override void SetResponses(OpenApiOperation operation)
{
if (IsSingleElement)
SetSingleResponse(operation, TargetSchemaElement.FullName());
{
OpenApiSchema schema = null;

if (Context.Settings.EnableDerivedTypesReferencesForResponses)
{
schema = EdmModelHelper.GetDerivedTypesReferenceSchema(targetStructuredType, Context.Model);
}

if (schema == null)
{
schema = new OpenApiSchema
{
UnresolvedReference = true,
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = TargetSchemaElement.FullName()
}
};
}

SetSingleResponse(operation, schema);
}
else
SetCollectionResponse(operation, TargetSchemaElement.FullName());
{
SetCollectionResponse(operation, TargetSchemaElement.FullName());
}

operation.AddErrorResponses(Context.Settings, false);

Expand Down
16 changes: 3 additions & 13 deletions src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,11 @@ internal void SetCollectionResponse(OpenApiOperation operation, string targetEle
};
}

internal void SetSingleResponse(OpenApiOperation operation, string targetElementFullName)
internal void SetSingleResponse(OpenApiOperation operation, OpenApiSchema schema)
{
Utils.CheckArgumentNull(operation, nameof(operation));
Utils.CheckArgumentNullOrEmpty(targetElementFullName, nameof(targetElementFullName));

var schema = new OpenApiSchema
{
UnresolvedReference = true,
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = targetElementFullName
}
};

Utils.CheckArgumentNull(schema, nameof(schema));

operation.Responses = new OpenApiResponses
{
{
Expand Down

0 comments on commit 33ffc43

Please sign in to comment.