OpenAPITools / OpenAPITools/openapi-generator

[Kotlin][BUG] The path in request config an enum key instead of a value when specifying an enum type for a parameters path field in the specification

Open
#12,662 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

The path in request config an enum key instead of a value when specifying an enum type for a parameters path field in the specification.

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Specification:

/shipment.outboundStatus.{carrier}:
   post:
     operationId: shipmentUpdateStatusCarrier
     description: Send create order result from carrier to xdc by carriers name
     parameters:
       - in: path
         name: carrier
         required: true
         schema:
           type: string
           enum:
             - 'dpd'
             - 'dpd-b2b'
             - 'pick-point'
             - 'pickpoint-itx'
             - '5post-pups'
             - 'ozon'
         description: carrier
     requestBody:
       required: true
       content:
         application/json:
           schema:
             $ref: 'internalSchemas/xdc-to-shipment-api.yaml#/components/schemas/UpdateStatusRequest'
     responses:
       '200':
         description: Success
     tags:
       - shipment

Generated enum:

 enum class Carrier_shipmentUpdateStatusCarrier(val value: kotlin.String) {
         @Json(name = "dpd") dpd("dpd"),
         @Json(name = "dpd-b2b") dpdMinusB2b("dpd-b2b"),
         @Json(name = "pick-point") pickMinusPoint("pick-point"),
         @Json(name = "pickpoint-itx") pickpointMinusItx("pickpoint-itx"),
         @Json(name = "5post-pups") _5postMinusPups("5post-pups"),
         @Json(name = "ozon") ozon("ozon")
     }

Generated method:

fun shipmentUpdateStatusCarrierRequestConfig(carrier: Carrier_shipmentUpdateStatusCarrier, updateStatusRequest: UpdateStatusRequest) : RequestConfig<UpdateStatusRequest> {
        val localVariableBody = updateStatusRequest
        val localVariableQuery: MultiValueMap = mutableMapOf()
        val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
        localVariableHeaders["Content-Type"] = "application/json"
        
        return RequestConfig(
            method = RequestMethod.POST,
            path = "/shipment.outboundStatus.{carrier}".replace("{"+"carrier"+"}", "$carrier"),
            query = localVariableQuery,
            headers = localVariableHeaders,
            body = localVariableBody
        )
    }

For instance the path will be "_5postMinusPups" instead "5post-pups"

openapi-generator version

v6.0.0-beta(latest)

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/12661

Suggest a fix

https://github.com/OpenAPITools/openapi-generator/pull/12661

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the related pull request #12661, then reproduce the issue with the supplied OpenAPI path and enum definition. Inspect the generated Kotlin request method and enum handling; done means the request path uses the enum value such as "5post-pups" rather than the generated enum constant name.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.