Skip to content

Swagger generation maps int value objects to JsonSchemaType.Number instead of JsonSchemaType.Integer #968

Description

@angelofb

Describe the bug

When Swagger mappings are generated for a value object backed by int, Vogen emits JsonSchemaType.Number.

Given:

  [ValueObject<int>]
  public readonly partial record struct MyCustomId;

The generated mapping is:

  global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions
      .MapType<global::MyCustomId>(
          o,
          () => new global::Microsoft.OpenApi.OpenApiSchema
          {
              Type = global::Microsoft.OpenApi.JsonSchemaType.Number,
              Format = "int32"
          });

However, an int-backed value object should be represented as an OpenAPI integer:

  global::Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions
      .MapType<global::MyCustomId>(
          o,
          () => new global::Microsoft.OpenApi.OpenApiSchema
          {
              Type = global::Microsoft.OpenApi.JsonSchemaType.Integer,
              Format = "int32"
          });

Impact

The resulting OpenAPI schema does not correctly describe the underlying value. Client generators may treat the value as a generic numeric or floating-point type instead of an integer.

Environment

  • Vogen: 8.0.7
  • Target framework: .NET 10

Steps to reproduce

just enable openApiSchemaCustomizations: OpenApiSchemaCustomizations.GenerateSwashbuckleMappingExtensionMethod

Expected behaviour

Value objects backed by integral types should use JsonSchemaType.Integer, with the appropriate format such as int32 or int64.

Activity

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions