Repository navigation
Replies: 1 comment
|
I think this is so much needed :) As far as I know, currently I cannot override the default 200 status code of response JSON any other way than through e.g. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Background
I have been deep diving in this crate for the past 3 weeks working on a PR to automatically document my API for a server project I am working on. Currently my project 6 endpoints with plans to grow that in the future.
Across the 6 endpoints I am using the following http features:
application/octet-streamresponse typesWith this crate I am hoping to accomplish:
Some things I'm seeing as I go along:
OperationOutputandOperationInputtraits seem to have an O(n) maintenance overhead. Every new endpoint requires the entire endpoint be documented and each request/response type haveOperationInputandOperationOutputdefined.axum::Json<T>assumes that I want the status code of that response to be 200?What I Have Done
Helper Trait / Wrapper Struct Pairing
Tip
Here are the recipes
JSON Response Types
Octet Streams are less clean because we can't leverage
schemarsfor this one:Octet Stream Response Types
This pattern works pretty good, and can be extended to each class of responses rather than each individual response type, making maintenance O(log n)
Suggestions
Enum Derives
This pattern falls apart when I want the ability to use multiple success / failure response types (enums) in my handlers. Even with the wrappers shown above, I still have to write the following any enum type that I want to return:
I think @tamasfe 's great suggestion here would alleviate that boilerplate. He rightly points out the problem that all of the underlying types in the enum may or may not be JSON (which is the case for me). But if all of the variant types already implement
OperationOutputthen you don't have to care.Content-TypeSpecific DerivesI'm imagining something that looks like this:
Or a mega derive that takes content type as a macro attribute and handles it accordingly.
My Own Knowledge Gaps
I'll admit that I still don't know the difference between
operation_response()andinferred_responses()in theOperationOutputtrait.I've only written one proc macro, I know they are difficult so I know this is not a trivial ask.
All reactions