Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing @Example annotation #16

Closed
SerVB opened this issue Mar 13, 2020 · 5 comments
Closed

Missing @Example annotation #16

SerVB opened this issue Mar 13, 2020 · 5 comments

Comments

@SerVB
Copy link
Contributor

SerVB commented Mar 13, 2020

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
Copy link
Collaborator

Wicpar commented Mar 13, 2020

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
Copy link
Contributor Author

SerVB commented Mar 13, 2020

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
Copy link
Collaborator

Wicpar commented Mar 13, 2020

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
Copy link
Collaborator

Wicpar commented Mar 17, 2020

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 Wicpar closed this as completed Mar 17, 2020
@Wicpar
Copy link
Collaborator

Wicpar commented Mar 17, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants