papsign / Ktor-OpenAPI-Generator

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

Missing @Example annotation #16

Closed SerVB closed 4 years ago

SerVB commented 4 years ago

In the models section, there is a field called "example". Currently it is equal to null for all fields in all classes:

image

There should be a way to specify this field. Also, I think if the field is not specified, it shouldn't be presented in the models section.

This is an issue extracted from #12.

Wicpar commented 4 years ago

you can specify it per request like this:

get<Unit, Response>(example = Response(...)) {

}

post<Unit, Response, Request>(
    exampleRequest = Request(...),
    exampleResponse = Response(...)
) { params, request ->

}

No mechanism exists yet to provide examples per model globally.

SerVB commented 4 years ago

Yeah, I use examples for methods. I'm not an experienced user of OpenAPI, so I don't know if examples of fields are also usually defined...

If yes, I want an opportunity to define them.

If no, just remove these "example" fields.

Wicpar commented 4 years ago

i will add such a mechanism as it is part of the standard. until then you can use the new branch with the reworked models. null fields are now filtered when you use OpenAPIModel.build() it will generate the appropriate hashmaps and remove empty and null values

Wicpar commented 4 years ago

Added @WithExample in the latest commit. SwagerUI doesn't handle it properly anyway.

        @WithExample
        class C(val l: @Clamp(0, 10) Long) : Base() {
            companion object: ExampleProvider<C> {
                override val example: C? = C(5)
            }
        }

or

        @WithExample(CExampleProvider::class)
        class C(val l: @Clamp(0, 10) Long) : Base()
...
        object CExampleProvider: ExampleProvider<C> {
                override val example: C? = C(5)
        }
Wicpar commented 4 years ago

implementation 'com.github.papsign:Ktor-OpenAPI-Generator:0.2-beta.0-experimental'