feat(openapi): provide default 400 responses in docs#1153
Conversation
|
Thanks! And sorry for the delay. We definitely needs something like this :) Couple of questions/ideas:
|
|
cc @matwojcik Yes, you could generate a nice representation of the validator for a schema. See the |
|
No problem, thanks for the response. 🙂
I think adding a field of type
Sure, I'll add a test for it.
Makes sense. Users have the option to use |
Or more generally
That's a different axis - even for infallibleEndpoints, you can get a decode failure, in decoding an input fails. |
fa3b02f to
acfe383
Compare
It seems that a schema format is rarely defined, at least in the tests, so it might not be a good "predictor" of possible parsing/decoding failures. For now, I pushed a version where a 400 response is added for any basic input other than |
|
Thanks for the updates :) I'm still thinking of what would be a good way to decide whether to include the error output. But I can't think of anything. I don't really like the current way - it's too broad and gives imprecise information. Maybe then we should extend the But these changes would be quite far-reaching. We would need new |
| schemaName: SObjectInfo => String = defaultSchemaName, | ||
| referenceEnums: SObjectInfo => Boolean = _ => false | ||
| referenceEnums: SObjectInfo => Boolean = _ => false, | ||
| default400Output: EndpointOutput[_] = stringBody.description("Input validation failed.") |
There was a problem hiding this comment.
I think I'd still make this optional. Maybe defaultDecodeFailureOutput would be a better name. Or maybe we could move the logic here, having a EndpointInput => Option[ValuedEndpointOuput[_]] function in the options. The default implementation would contain partially what's now in inputToDefaultErrorResponses. WDYT?
The logic would be nicely pluggable then, providing a way to implement the decision logic in an app-specific way.
But then, maybe that's not a place where you need the flexibility?
There was a problem hiding this comment.
Yeah, I'll make this optional in case users don't like or need the functionality. I think this could be an EndpointInput[_] => Option[EndpointOutput[_]], potentially implemented using DefaultDecodeFailureHandler.FailureMessages.failureSourceMessage. And yes, I think I'll move some logic from inputToDefaultErrorResponses.
(I think we don't need to return ValuedEndpointOutput, because we don't need the value returned by the endpoint to generate the docs, is that correct?)
96598dc to
89ae962
Compare
|
I made some changes to the logic (here). It's now a bit better at detecting potential failures and gives a bit more detailed descriptions, e.g.
Is it ok to add a method to a trait that's used in so many places? What if it turns out later that it was not a good idea, would it be easy to change its signature or move the method somewhere else? If so, I could give it a try. Also, do you plan any deadline for introducing breaking changes? I think extending |
|
I was just reading the code :) I would be reluctant to add new methods to The current heuristics looks much better. Let's try it and we'll see what the feedback is. The only missing piece is I think adding some mention in the docs on how to configure this feature. |
If decoding of an endpoint's input may fail, the endpoint may respond with a 400 status code. Provide a default 400 response for each such endpoint in OpenAPI docs to make them more consistent with the actual endpoint behavior. * feat(openapi): add default 400 output to OpenAPIDocsOptions * wip: make default 400 a func input => Option[output] * wip: use FailureMessages.failureSourceMessage * wip: refactor * wip: rename to defaultDecodeFailureOutput * wip: enhance fallible input detection * wip: fix json and security tests * wip: fix yaml coproduct test * wip: fix all tests * wip: refactor * wip: extract tests * wip: check for required inputs * refactor: extract EndpointInputToDecodeFailureOutput * wip: exclude auth headers * wip: add test for no response * docs: add info about defaultDecodeFailureOutput
213df2f to
dc3dd44
Compare
|
I refactored the code and added a short explanation to the docs, let me know if this works. |
If endpoint input is validated, the endpoint may respond with a 400 status code. Provide a default 400 response in OpenAPI docs to make them more consistent with the actual endpoint behavior.
Partly resolves #1053.