Giter VIP home page Giter VIP logo

Comments (4)

Wicpar avatar Wicpar commented on May 18, 2024 4

Turns out the change is minimal, i'm on it, ETC: 1h.

from ktor-openapi-generator.

Wicpar avatar Wicpar commented on May 18, 2024 1

0.2-beta.8 is out.
I also changed the Module provider behaviour to guarantee insertion order in order to be usable as a stack as well, and changed KClass to KTypes to allow for generic specialisation. It might break some code, i explained how to fix it in the release notes.

                route("status/codes") {
                    route("201").status(201) {
                        // all endpoints in this block respond a 201 status code unless specified otherwise

                        get<StringParam, StringResponse>(
                            info("201 String Param Endpoint", "This is a String Param Endpoint that has a 201 status code"),
                            example = StringResponse("Hi")
                        ) { params ->
                            respond(StringResponse(params.a))
                        }

                        route("reset").get<StringParam, StringResponse>(
                            info("String Param Endpoint with @response based status code", "This is a String Param Endpoint that resets the status code back to the one provided by @Response"),
                            responseAnnotationStatus(),
                            example = StringResponse("Hi")
                        ) { params ->
                            respond(StringResponse(params.a))
                        }
                    }

                    route("202").get<StringParam, StringResponse>(
                        info("String Param Endpoint with inline 202 response", "This is a String Param Endpoint that has a 202 response code"),
                        status(HttpStatusCode.Accepted),
                        example = StringResponse("Hi")
                    ) { params ->
                        respond(StringResponse(params.a))
                    }
                }

from ktor-openapi-generator.

Wicpar avatar Wicpar commented on May 18, 2024

Indeed it is sub-optimal as the status code can only be changed through the annotation.
You have two options for a "quick" fix:

  • Handle the responses through an exception handler (which is quite a sacrilege I must admit)
  • Implement your custom post/get/put, etc... with an edited pre-handle function that injects your custom ResponseHandlerModule that gets the status code from a module.

If I were to implement this i would do option 2, and have the annotation provided status code modules as default module, overridden by any other module specified in the module provider.
If you wish to contribute that by implementing this behaviour in the current ResponseHandlerModule it would be great, else I can get to it in a few days.

from ktor-openapi-generator.

sigmanil avatar sigmanil commented on May 18, 2024

Awesome, thank you very much! We'll try it out ASAP! :-)

from ktor-openapi-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.