-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Open Api fails to generate correct schema type for some properties #61407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
When would a fix for this be a realistic expectation? I know you guys are busy |
Just a FYI about the |
I also hit this problem and was able to make a small reproducible and runnable example. It is a single change 5a705dd on top of the default 9.0.4 generates
Interestingly, if you switch it to 9.0.3, it instead generates
So it seems like nullability and duplication isn't an issue here since in both lists City is non-nullable so no need to duplicate. But maybe some of the nullability/duplication fixes between 9.0.3 and 9.0.4 broke this situation? |
Found the already reported issue in asp.net core dotnet/aspnetcore#61407 for us, it manifests in the NewJobs record with the SimStations and SimStationsForCompleted properties not being generated correctly.
I have made this schema transformer as a workaround until this is fixed: public sealed class FixBrokenReferencesInArraysSchemaTransformer : IOpenApiSchemaTransformer
{
public Task TransformAsync(
OpenApiSchema schema,
OpenApiSchemaTransformerContext context,
CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(schema);
if (schema.Properties is null)
{
return Task.CompletedTask;
}
var propertiesToFix = schema.Properties
.Select(x => x.Value)
.Where(x => x.Type == "array")
.Where(x => x.Items is not null)
.Where(x => !string.IsNullOrEmpty(x.Items.Reference?.Id))
.Where(x => x.Items.Annotations is not null);
foreach (var property in propertiesToFix)
{
if (!property.Items.Annotations.TryGetValue("x-schema-id", out var schemaId))
{
continue;
}
property.Items.Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = schemaId.ToString(),
};
}
return Task.CompletedTask;
}
} |
Is there an existing issue for this?
Describe the bug
generates this schema
Expected Behavior
I would expect this schema
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
9.0.4
Anything else?
No response
The text was updated successfully, but these errors were encountered: