-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for content types accepted by client #81
Comments
Can I take up this issue next? |
@vipulchhabra99 are you working on this? Or may I please take the issue. |
Oh, I didn't see @vipulchhabra99's comment, sorry about that. From my side it's okay for either of you to take up that issue |
I am working on it.:) |
It's fine @uniqueg, I haven't started working on it. |
@uniqueg In this we have to take user input for each specific route or the whole app. I think it's for the whole app. |
I'm not sure I understand your question, but the goal here would be to create a generic solution for a relatively common problem - content negotiation between client and server. If the client requests the response to be of one or more specified content types (via the To implement that, I had thought of defining a decorator that handles the content negotation and that could be added to the controllers of every specific route. But I can see that at least in most cases (I currently can't think of examples that would not want to have content negotation activated, but cannot rule out that there are not) it would be useful to have this for all routes. But I'm not sure how to implement that, given that FOCA doesn't have direct access to the routes. If you find a way (e.g., via Connexion) to do that globally, for the entire app, that would be awesome! In that case, I think we should go for such a solution and only implement a route-based solution if anybody actually asks for that. As a starting point, please have a look at the issues linked in the issue description to find out what Connexion already has supported, what the limitations are etc. There may be other relevant issues in Connexion as well. Please post any findings, with relevant links (ideally to definite information such as code, specs etc) in this issue so that we can review them together before deciding on an implementation strategy. |
In order to test if the connexion validation works with Thus connexion validation is not working as expected. This class is the place where response validation happens in connexion. One solution is to create a similar class in
Ref: https://connexion.readthedocs.io/en/latest/response.html#custom-validator This will ensure validation at an app-level rather than on an individual API endpoint level. Had some trouble understanding the code in the class, but if this is the right approach, we will dig deeper into this. |
Thanks @sarthakgupta072. I think content negotiation/validation should always be performed, so it's fine to implement it at an app level. But to see how (or rather where) to best implement it, I tnink a couple more tests would be useful to decide how to proceed: For requests to a test endpoint, please set up those test cases:
The second set of tests are also for requests, but only if the request actually sends some data along (e.g., in a For responses from a test endpoint, please set up those test cases (note that any errors here are the developer's fault, not the client's):
Some more considerations:
These tests also pretty much dictate how to implement content negotiation (and in which order):
If we have all of these tests in place, we know if and to what extent Connexion itself is handling any kind of content negotation / validation, and, based on that, we can decide whether we prefer to patch existing Connexion code or just write the FOCA code on top of Connexion. We can then also use those tests for test-driven development of the actual logic (which should actually be rather simple compared to coming up with all those tests). What's important eventually is that a list of content types accepted by the client and supported by the endpoint specs are passed to the endpoint so that the developer can decide which content type to deliver. The order of the content types in the Does this approach make sense to you? |
@uniqueg we actually tried only the basic test case. This approach definitely seems like worth trying. We'll get back to you with our further findings by the earliest. |
@sarthakgupta072: any update on this? Just in case - I have removed the |
Hi @uniqueg, I was looking into Also @alohamora let me know when you are done with |
Fantastic - thanks a lot @Rahuljagwani - great find! Yes, @alohamora, please tell @Rahuljagwani if he should go ahead with Connexion v3 migration. |
Also, @kushagra189 - please have a look here as well, as Connexion v3 migration also came up in our discussion. Might make sense to migrate first and then you could implement the type stuff from #144, #201 and #200? And @Rahuljagwani could take care of this one. What do you think? |
@Rahuljagwani @kushagra189 says it's okay, so please go ahead |
Currently blocked by #188 |
API endpoints can serve different content types, e.g.,
application/json
,text/plain
etc. Clients can ask a service to respond with one or more specific accepted content types.It would be nice if FOCA implemented a solution (e.g., a decorator) that compares the client's desired content type(s) against the ones that the service offers for the respective endpoint (as defined in the API specs). An appropriate error response should be returned if a client requests a content type that the endpoint cannot deliver. If the client does not explicitly ask for a specific content type (i.e., if the
Accept: <content-type>
header is missing), the default response should be given.Other important points to think about:
Accept
headers to some extent; on the other hand, it may also be the case that Connexion will complain if JSON-incompatible content types are to be returnedThe text was updated successfully, but these errors were encountered: