kroegerama / openapi-kgen

Generate modern API Clients in Kotlin from OpenAPI specifications. Supports OpenAPI >= 3.0.0.
Apache License 2.0
22 stars 4 forks source link

Support OpenAPI enum extensions #7

Closed ArjixWasTaken closed 1 year ago

ArjixWasTaken commented 1 year ago

Supported Extensions:

ArjixWasTaken commented 1 year ago

Example enum:

{
   "components": {
      "schemas": {
         "Role": {
            "enum": [ 0, 1, 2, 3, 4 ],
            "description": "xOx Enum description xOx",
            "type": "integer",
            "format": "int32",
            "example": 0,
            "x-enum-varnames": [
               "SuperAdmin",
               "Admin",
               "Management",
               "Doctor",
               "Nurse"
            ],
            "x-enum-descriptions": [
               "The super admin.",
               "The local admin.",
               "The management.",
               "A doctor.",
               "A nurse."
            ]
         }
      }
   }
}

Generated code

/**
 * xOx Enum description xOx
 */
public enum class Role {
    /**
     * The super admin.
     */
    @Json(name = "0")
    SuperAdmin,
    /**
     * The local admin.
     */
    @Json(name = "1")
    Admin,
    /**
     * The management.
     */
    @Json(name = "2")
    Management,
    /**
     * A doctor.
     */
    @Json(name = "3")
    Doctor,
    /**
     * A nurse.
     */
    @Json(name = "4")
    Nurse,
}
ArjixWasTaken commented 1 year ago

I am not aware of any other enum spec extensions, if you know any others I'd be glad to include them in the PR.

kroegerama commented 1 year ago

Thanks a lot for your contribution! A great idea to add these extensions. Looks good from a first glance. I will have a detailed look as soon as I find the time.