papsign / Ktor-OpenAPI-Generator

Ktor OpenAPI/Swagger 3 Generator
Apache License 2.0
241 stars 42 forks source link

Add StringExample for easier examples of String properties #54

Closed bherbst closed 4 years ago

bherbst commented 4 years ago

This PR adds support for simple string examples on string properties. This is currently possible via @WithExample, but that approach requires creating an ExampleProvider for each property that returns the example string.

Sample code:

@Response("A Response for header param example")
data class NameGreetingResponse(
    @StringExample("Hello John") val str: String
)

Generated JSON:

      "NameGreetingResponse" : {
        "nullable" : false,
        "properties" : {
          "str" : {
            "example" : "Hi, John!",
            "nullable" : false,
            "type" : "string"
          }
        },
        "required" : [ "str" ],
        "type" : "object"
      },

Swagger UI:

Screen Shot 2020-05-21 at 1 40 54 PM