Skip to content

InvalidOperationException when using GetOrCreateSchemaAsync with inner references #64252

@lauraneto

Description

@lauraneto

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

While trying to use context.GetOrCreateSchemaAsync() I'm running into the following exception:

InvalidOperationException: The input schema must be an OpenApiSchema or OpenApiSchemaReference.
Microsoft.AspNetCore.OpenApi.OpenApiSchemaService.UnwrapOpenApiSchema(IOpenApiSchema sourceSchema)

This happens because it's trying to get the Target of a schema reference, but that returns null.
After some debugging I found that the target was null because OpenApiWorkspace._IOpenApiReferenceableRegistry had part of the schemas stored with keys with the base uri concatenated twice, for example: https://openapi.net/fa86ef4d-6f86-4937-9dee-98962f2eb26b#/components/schemas/https://openapi.net/fa86ef4d-6f86-4937-9dee-98962f2eb26b/components/schemas/SchemaX.

The issue appears to have been introduced with the following change: aa38ac3#diff-b3dad275078842738dacaa138dfd61e465a90ef85b68650304c791e0d487347cL26 , where RegisterComponent supported the full location while RegisterComponentForDocument only expects the component id.

Expected Behavior

Open API document is generated correctly without errors.

Steps To Reproduce

Unfortunately (or fortunately) I am having a hard time reproducing this in a minimal project, but I think looking at the code the issue is clear.

Exceptions (if any)

InvalidOperationException: The input schema must be an OpenApiSchema or OpenApiSchemaReference.
Microsoft.AspNetCore.OpenApi.OpenApiSchemaService.UnwrapOpenApiSchema(IOpenApiSchema sourceSchema)

.NET Version

10.0.100-rc.2.25502.107

Anything else?

Microsoft.AspNetCore.OpenApi 10.0.0-rc.2.25502.107

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions