Open kailaisi opened 1 year ago
there's a PR to improve kotlin enum implementation. would that meet your requirement?
https://github.com/OpenAPITools/openapi-generator/pull/16333
@wing328 no,the pr is not my requirement 。 for the swagger.json like :
openapi: "3.0.2"
info:
version: "1.0.0"
title: Testing Kotlin generation
# We only care about schemas, but this prevents codegen error: "attribute paths is missing"
paths:
/dummy:
get:
responses:
'200':
description: OK
components:
schemas:
StatusColorEnum:
description: >
RGB.
type: string
enum:
- RED
- YELLOW
- GREEN
I user my own templment to generate the value:
{{#gson}}
@SerializedName(value = {{#lambda.doublequote}}{{{-index}}}{{/lambda.doublequote}})
{{/gson}}
enum class StatusColorEnum(val value: kotlin.String) {
@SerializedName(value = "1")
RED("RED"),
@SerializedName(value = "2")
YELLOW("YELLOW"),
@SerializedName(value = "3")
GREEN("GREEN");
enum class StatusColorEnum(val value: kotlin.String) {
@SerializedName(value = "0")
RED("RED"),
@SerializedName(value = "1")
YELLOW("YELLOW"),
@SerializedName(value = "2")
GREEN("GREEN");
what should i do if i want the value is from 0 but not 1.
I want use my own templement to generate kotin enum class: {{#gson}} @SerializedName(value = {{#lambda.doublequote}}{{{@index}}}{{/lambda.doublequote}}) {{/gson}}
I want the SerializedName value to be an increasing string starting from 0。But the @index not work。 In the doc:https://openapi-generator.tech/docs/templating . I find that : If you'd like a 1-based index in your array traversal, you can use {{-index}}。 But what should i do if i want a 0-based index?