SMILEY4 / ktor-swagger-ui

Kotlin Ktor plugin to generate OpenAPI and provide Swagger UI
Apache License 2.0
150 stars 25 forks source link

3.0 example serialization #106

Closed waltkb closed 1 month ago

waltkb commented 2 months ago

An example like this:

example("E-mail + password") {
    value = buildJsonObject {
        put("type", JsonPrimitive("email"))
        put("email", JsonPrimitive("user@email.com"))
        put("password", JsonPrimitive("password"))
    }
}

Does not come out as a simple JSON like this:

{
  "type": "email",
  "email": "user@email.com",
  "password": "password"
}

But instead produces this example:

{
  "type": {
    "content": "email",
    "string": true
  },
  "email": {
    "content": "user@email.com",
    "string": true
  },
  "password": {
    "content": "password",
    "string": true
  }
}

screenshot_20240613_145119

waltkb commented 2 months ago

Could probably be fixed with #107

SMILEY4 commented 2 months ago

Hi, i'm not quite sure where buildJsonObject comes from or what type it exactly returns, but you should be able to provide the example as an json string here.

example("E-mail + password") {
    value = buildJsonObject {
        put("type", JsonPrimitive("email"))
        put("email", JsonPrimitive("user@email.com"))
        put("password", JsonPrimitive("password"))
    }.toJsonString() // ... or something that turns the result of buildJsonObject into a json-string
}

I think this could then be done automatically with the config provided with https://github.com/SMILEY4/ktor-swagger-ui/pull/107 so you dont need to convert to string for every individual example.