Skip to content

Kotlin Serialization Configurations Not Reflected in OpenAPI Specification #2269

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

Open
m4rcingsxr opened this issue May 16, 2025 · 0 comments

Comments

@m4rcingsxr
Copy link

m4rcingsxr commented May 16, 2025

Issue Description

Currently, changes made to Kotlin serialization configurations, such as setting a naming strategy to snake_case (e.g., via JsonNamingStrategy.SnakeCase), are not reflected in the generated OpenAPI specification when using SmallRye OpenAPI. This contrasts with Jackson configurations, where naming strategy changes (e.g., PropertyNamingStrategy.SNAKE_CASE) do propagate to the OpenAPI spec. For projects avoiding Jackson in favor of Kotlin serialization, this lack of support creates inconsistencies and fails to meet certain validation requirements, such as those enforced by the IBM API validator.

Main Goals

To ensure compatibility with Kotlin serialization and compliance with validators like IBM's, we need the following features:

  1. Kotlin Serialization Reflection in OpenAPI: Annotations (e.g., @SerialName) and custom serializers (e.g., for enums) defined in Kotlin serialization should be reflected in the generated OpenAPI specification.
  2. Global Naming Strategy Support: Setting a global naming strategy (e.g., snake_case) in Quarkus configuration (e.g., quarkus.kotlinx.serialization.naming-strategy=SnakeCase) should apply to the OpenAPI spec for properties and enums.

Current Behavior

  • When using Kotlin serialization with Json { namingStrategy = JsonNamingStrategy.SnakeCase }, the OpenAPI spec still uses camelCase for property names.
  • Explicit annotations like @SerialName("snake_case") or custom serializers for enums are not honored in the OpenAPI output.
  • Jackson-based configurations (e.g., ObjectMapper with PropertyNamingStrategy.SNAKE_CASE) correctly influence the OpenAPI spec, but we aim to avoid Jackson dependencies.
  • This results in validation failures with tools like the IBM API validator, which require snake_case for properties and enums.

Expected Behavior

  • Kotlin serialization configurations, including JsonNamingStrategy.SnakeCase and annotations like @SerialName, should be respected in the generated OpenAPI spec.
  • A global configuration option (e.g., in Quarkus) should allow setting a naming strategy (e.g., snake_case) that applies to all schemas in the OpenAPI output.
  • Enums and properties serialized with snake_case (via naming strategy) should appear as snake_case in the OpenAPI spec to ensure compliance with validators like IBM's.

small reproducer

Issues Identified with IBM API Validator

Rule ID: ibm-integer-attributes

Description: Integer schemas (e.g., for query parameters like id) must define minimum and maximum properties. For example, the annotation @Size(min = 1, max = 100) @QueryParam("id") ids: List<@Min(0) @Max(Long.MAX_VALUE) Long> does not generate items.minimum or items.maximum in the OpenAPI

Rule ID: ibm-accept-and-return-models

Description: Request and response bodies must define properties (i.e., be objects). Returning Unit (e.g., in DELETE endpoints) generates an empty schema, which violates this rule.

Rule ID: ibm-use-date-based-format

Description: The @Schema(format = "date-time") annotation on OffsetDateTime fields is not correctly reflected in the generated OpenAPI spec. As a result, the OpenAPI output omits the expected format: date-time

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

No branches or pull requests

1 participant