papsign / Ktor-OpenAPI-Generator

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

use parameter not once #51

Closed y9san9 closed 4 years ago

y9san9 commented 4 years ago

image I have this models and I am using auth param in almost every request (there can be other parameter, not only auth). Can I somehow create data class with this param and then use it in other classes. My vision of it is in screenshot

y9san9 commented 4 years ago

I'm copy & pasting same parameters every time and it makes my code worse

Wicpar commented 4 years ago

Right now there is no way around it, if kotlin had vararg templates it would be fine, but the best shot at solving this is #10 and it would be quite a big change for the library.

Wicpar commented 4 years ago

Also if you use authentication you should rather use authenticated routes and the auth provider, it allows you to share logic on the endpoints to get the authenticated principal object directly

y9san9 commented 4 years ago

Okey, thanks for your reply. Waiting for #10

y9san9 commented 4 years ago

I have suggestion how to implement this

route<GetTasksParams>("/tasks"){ params ->
    route<AuthParams>("/auth"){ otherParams ->
       get<AnotherParams, ...> { anotherParams ->

       }
    }
    post<SomeOtherParams, ...> { someOtherParams ->

    }
}

I dont know about possibility to do this, but this syntax would be nice

Wicpar commented 4 years ago

that is not possible directly, sadly, but something like this would be possible

route<GetTasksParams>("/tasks"){ params ->
    route<AuthParams>("/auth"){ otherParams ->
       get<AnotherParams, ...> { anotherParams ->
           val paramsInstance = this.getParams(params) // needs to be resolved explicitly
           val otherParamsInstance = this.getParams(otherParams)
       }
    }
}
y9san9 commented 4 years ago

Oke, I understand. Can you implement this ?

Wicpar commented 4 years ago

not any time soon sadly, i'm quite busy at the moment and can only spare an hour here an there... If you think you can implement it feel free to open a pull request.

y9san9 commented 4 years ago

Okey, I will think more about it later and if I find better solution I'll implement it