Comments (4)
Turns out the change is minimal, i'm on it, ETC: 1h.
from ktor-openapi-generator.
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.
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.
Awesome, thank you very much! We'll try it out ASAP! :-)
from ktor-openapi-generator.
Related Issues (20)
- Problem with authentication HOT 11
- Reusable enums
- Enum parser is okay with wrong values HOT 3
- Deserialisation of List<UUID> in body fails during runtime HOT 1
- Can't set name of token parameter or cookie name in SecurityScheme
- Add response header to a route
- Default values on @QueryParam HOT 4
- Overriding a primitive converter (UUID) HOT 5
- Serializing collections of different element types is not yet supported HOT 4
- API route with Any must be a data class. HOT 4
- File upload HOT 10
- @Description annotation doesn't work HOT 3
- Is there a simple way to split the endpoints of an application in two different openapi-files? HOT 1
- @HeaderParam is adding header to request body instead of request header
- Support for Ktor 2.0.0 HOT 13
- Enum classes are generated for each usage instead of a schema that can be reused
- How to properly indicate a application/x-www-form-urlencoded response HOT 1
- @Hidden annotation for fields in request / response body HOT 2
- Suggestion for conditional validation HOT 1
- Description for response HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ktor-openapi-generator.