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

Set moshi json fields with kotlin client generator #4610

Open
NunoAntunes5 opened this issue Nov 21, 2023 · 0 comments
Open

Set moshi json fields with kotlin client generator #4610

NunoAntunes5 opened this issue Nov 21, 2023 · 0 comments

Comments

@NunoAntunes5
Copy link

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
)
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