Skip to content

InvalidOperationException when using GetOrCreateSchemaAsync with inner references #64252

Closed as duplicate

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

Activity

  1. added
    needs-area-label
    on Nov 5, 2025
  2. added
    area-minimal
    and removed
    needs-area-label
    on Nov 5, 2025
  3. lauraneto commented on Nov 6, 2025

    @lauraneto
    Author

    It looks like this is actually a duplicate of #63598 , which I hadn't found while creating this.
    I will therefore close this and add more details to that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalfeature-openapi

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions