swagger-editor icon indicating copy to clipboard operation
swagger-editor copied to clipboard

Set moshi json fields with kotlin client generator

Open NunoAntunes5 opened this issue 9 months ago • 0 comments

Content & configuration

Swagger/OpenAPI definition:

 Objective:
   type: object
   properties:
     objective_id:
       type: string
     objective_name:
       type: string
     objective_start:
       type: string
     objective_end:
       type: string
     reason:
       type: string

Swagger-Editor configuration options: Using the online demo at editor.swagger.io

Is your feature request related to a problem?

If my json is objective_id, the variable generated for kotlin by swagger will be objectiveId, so the request won't happen.

Describe the solution you'd like

what I'd like to happen is for swager's codegen to define moshi's json fields

What happens

/**
 * 
 * @param objectiveId 
 * @param objectiveName 
 * @param objectiveStart 
 * @param objectiveEnd 
 * @param reason
 */
data class Objective (
    val objectiveId: kotlin.String? = null,
    val objectiveName: kotlin.String? = null,
    val objectiveStart: kotlin.String? = null,
    val objectiveEnd: kotlin.String? = null,
    val reason: kotlin.String? = null,
) {

}

Possible Solution

/**
 * 
 * @param objectiveId 
 * @param objectiveName 
 * @param objectiveStart 
 * @param objectiveEnd 
 * @param reason
 */
@JsonClass(generateAdapter = true)
data class CompletedSession(
    @Json(name = "objective_id") @field:Json(name = "objective_id") var objectiveId: String? = null,
    @Json(name = "objective_name") @field:Json(name = "objective_name") var objectiveName: String? = null,
    @Json(name = "objective_start") @field:Json(name = "objective_start") var objectiveStart: String? = null,
    @Json(name = "objective_end") @field:Json(name = "objective_end") var objectiveEnd: String? = null,
    @Json(name = "reason") @field:Json(name = "reason") var reason: String? = null
)

NunoAntunes5 avatar Nov 21 '23 12:11 NunoAntunes5