Skip to content

Conversation

@Peter-B-
Copy link
Contributor

This PR fixes #856.

Microsoft.OpenApi 2.0 introduced some breaking changes and while #844 addressed them in GenerateCodeForAspNetCoreOpenApiSchema, this PR adapts GenerateCodeForOpenApiSchemaCustomization.

I moved OpenApiVersionBeingUsed and OpenApiSchemaUtils to top level and adapted the generation code.

It works with both OpenApi 1.x

global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType<global::WebApplication.Shared.SharedStruct>(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = false });
global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType<global::System.Nullable<global::WebApplication.Shared.SharedStruct>>(o, () => new global::Microsoft.OpenApi.Models.OpenApiSchema { Type = "integer", Format = "int32", Nullable = true });

and OpenApi 2.x

global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType<global::WebApplication.Shared.SharedStruct>(o, () => new global::Microsoft.OpenApi.OpenApiSchema { Type = global::Microsoft.OpenApi.JsonSchemaType.Number, Format = "int32" });
global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType<global::System.Nullable<global::WebApplication.Shared.SharedStruct>>(o, () => new global::Microsoft.OpenApi.OpenApiSchema { Type = global::Microsoft.OpenApi.JsonSchemaType.Number | global::Microsoft.OpenApi.JsonSchemaType.Null, Format = "int32" });

I added a new OpenApiMode to the Consumers WebApplication and WebApplication.Shared projects. They support MicrosoftAndScalar, Swashbuckle-net8, and Swashbuckle-net10. I'm not sure about the naming, though.

Please review this PR carefully, since I do not have a comprehensive understanding of Vogen or Source Generators in general :-)

@SteveDunn
Copy link
Owner

Thank you for the PR! I'm working in this area at the moment, but won't be able to finish for a while, but I'll get around to this PR as soon as possible. Thanks again, much appreciated!

@Peter-B-
Copy link
Contributor Author

Thanks for the feedback. If I should adapt anything, please let me know.

Take your time - it's your free time after all.

Thanks for investing it in this project!

# Conflicts:
#	samples/WebApplication/Program.cs
#	src/Vogen/GenerateCodeForAspNetCoreOpenApiSchema.cs
#	src/Vogen/GenerateCodeForOpenApiSchemaCustomization.cs
OpenApiOptions did not work for Swashbuckle with OpenApi 1
…enced

Check both OpenApi version and reference to OpenApiOptions / JsonSchemaType
@Peter-B- Peter-B- force-pushed the fix/856-openapi-2.0 branch from 8d8bd42 to 41b97a2 Compare December 1, 2025 07:53
@Peter-B-
Copy link
Contributor Author

Peter-B- commented Dec 1, 2025

Hi @SteveDunn,

I tried to rebase on your latest changes, but I broke it and cannot figure out why. I get build errors:

Vogen.ValueObjectGenerator\_MapVogenTypesInOpenApiMarkers_g.cs(30,140): error CS0234: The type or namespace name 'OpenApiOptions' does not exist in the namespace 'Microsoft.AspNetCore.OpenApi' (are you missing an assembly reference?)

I don't understand what is happening and I didn't manage to find the generated file. I think I need some support here.

@Peter-B-
Copy link
Contributor Author

Peter-B- commented Dec 8, 2025

I took another look at the issue and managed to fix it.
Please let meknow, if you see any issues. Otherwise, I can update the Snapshots.

@SteveDunn
Copy link
Owner

Thank you! I should have time to look at it over the weekend.
Thanks again for your contribution!

@SteveDunn SteveDunn merged commit 7d873f8 into SteveDunn:main Dec 13, 2025
5 of 6 checks passed
@SteveDunn
Copy link
Owner

LGTM! Thanks for the great work! I've merged this and will rebase the snapshots in the next commit.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swashbuckle schema customization broken with OpenApi 2.0

2 participants