Skip to content
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

[BUG] [kotlin-spring] defaultValue for RequestHeader is not generated #20504

Open
ablil opened this issue Jan 19, 2025 · 0 comments
Open

[BUG] [kotlin-spring] defaultValue for RequestHeader is not generated #20504

ablil opened this issue Jan 19, 2025 · 0 comments

Comments

@ablil
Copy link

ablil commented Jan 19, 2025

Description

Given an optional request header with a default value, the current version of generator does NOT set a defaultValue on RequestHeader annotation, and does NOT set the generated type to an optional type (eg String? instead of String).

I've check the current mustache template, and the logic is indeed missing please check suggested fix below

openapi-generator version

7.10.0 through Gradle plugin

OpenAPI declaration file content or url
// ...

paths:
  /v1/configurations:
    get:
      summary: list all enabled configurations
      tags: ['configuration']
      operationId: getAllConfigurations
      parameters:
        - $ref: '#/components/parameters/Page'
        - $ref: '#/components/parameters/PageSize'
        - in: header
          name: x-tenant
          schema:
            type: string
            enum: ['de', 'at']
            default: 'de'
      responses:
        200:
          description: list all enabled configurations
          content:
            application/json:
              schema:
              // ...
Generation Details

The current generator version, generate the followign Kotlin code

    @Operation(
        tags = ["configuration"],
        summary = "list all enabled configurations",
        operationId = "getAllConfigurations",
        description = """""",
        responses = [
            ApiResponse(
                responseCode = "200",
                description = "list all enabled configurations",
                content = [Content(schema = Schema(implementation = GetAllConfigurations200ResponseDto::class))]
            )
        ]
    )
    @RequestMapping(
        method = [RequestMethod.GET],
        value = ["/v1/configurations"],
        produces = ["application/json"]
    )
    fun getAllConfigurations(
        @Parameter(
            description = "page number",
            schema = Schema(defaultValue = "1")
        ) @Valid @RequestParam(value = "page", required = false, defaultValue = "1") page: kotlin.Int,
        @Max(200) @Parameter(
            description = "page size",
            schema = Schema(defaultValue = "100")
        ) @Valid @RequestParam(
            value = "size",
            required = false,
            defaultValue = "100"
        ) size: kotlin.Int,
        @Parameter(
            description = "",
            `in` = ParameterIn.HEADER,
            schema = Schema(allowableValues = ["de", "at"], defaultValue = "de")
        ) @RequestHeader(value = "x-tenant", required = false) xTenant: kotlin.String
    ): ResponseEntity<GetAllConfigurations200ResponseDto>

Notice the generatd RequestHeader is missing a default value and type is not set to String?

@RequestHeader(value = "x-tenant", required = false) xTenant: kotlin.String
Suggest a fix

The current Java spring generator already has this logic, it need to be copied also for the Kotlin generator

Java mustache template file: modules/openapi-generator/src/main/resources/JavaSpring/headerParams.mustache

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

No branches or pull requests

1 participant