dotnet / dotnet/aspnetcore

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

Open
#64,266 2 comments 0 reactions 0 assignees View on GitHub
area-minimal feature-openapi
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [x] 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 https://github.com/desjoerd/OptionalValues/pull/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 https://github.com/desjoerd/OptionalValues/pull/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! 😊

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.