Skip to content

OpenAPI: Context.GetOrCreateSchemaAsync does not take CircularReferences into count. #64266

@desjoerd

Description

@desjoerd

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When you write a SchemaTransformer which unwraps an object (e.g. OptionalValues) the first thing someone would use is Context.GetOrCreateSchemaAsync with the underlying type as it generates the schema for you and will give a schema which will be either inlined or nested depending on it's metadata. The inner schema which is genrated also goes to it's transformers. This is the cause of this issue.

A references B
B references A

What will happen with Circular references

  • Transformer transforms A which wraps B
    • Context.GetOrCreateSchemaAsync(B)
      • B has a property of type A
        • Transformer transforms A which wraps B
          • Context.GetOrCreateSchemaAsync(B)
            • B has a property of type A
              • Transformer transforms A which wraps B
                • etc

See for a repro/workaround desjoerd/OptionalValues#22

Expected Behavior

It should track that it's generating or transforming a type. And give a reference to it instead of going for the "Unresolved" schema.

Steps To Reproduce

See desjoerd/OptionalValues#22

It's hard to create a explainable reproduce.

Exceptions (if any)

No response

.NET Version

.NET 10 RC2

Anything else?

I would like to have a design session around Unresolved Schemas, resolved schemas and schema reference handling if possible, to squash this once and for all! 😊

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