You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
It needs to be checked how content is negotiated between client and server, especially in situations where the client/server accepts/offers multiple content types
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 Accept: <content-type> header), the server SHOULD return the response in one of the requested content types, if it can, or else return an appropriate error response, probably 406 Not Acceptable.
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 Accept: <content-type> header or not, we tried running DRS-filer. DRS-filer always sends an application/json response. In the request when Accept: application/zip was sent, the server was not throwing an error and giving a 200 - ok response.
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 foca and override it something like this
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.
@sarthakgupta072: any update on this? Just in case - I have removed the v1.0.0 milestone, as I think we should go forward with releasing that version even if that features doesn't make it in that release. Of course it's still a "nice-to-have" and there's still some time to get it in (writing the documentation and implementing/testing FOCA in at least one or two of the apps that don't currently fully use it will take a bit of time still)
Hi @uniqueg, I was looking into connexion documentation. I found out that in their latest version, they are providing support for various content types which we can use directly to solve this issue.(link)
We need to migrate to Connexion v3 for this.
Also @alohamora let me know when you are done with connexion migration to v3, I will implement this after that, or if you have not started working on migration, even I can start working on that. Do let me know what you prefer :)
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?
Activity
vipulchhabra99 commentedon Jan 31, 2021
Can I take up this issue next?
anuragxxd commentedon Feb 17, 2021
@vipulchhabra99 are you working on this? Or may I please take the issue.
uniqueg commentedon Feb 17, 2021
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
anuragxxd commentedon Feb 17, 2021
I am working on it.:)
vipulchhabra99 commentedon Feb 17, 2021
It's fine @uniqueg, I haven't started working on it.
anuragxxd commentedon Feb 19, 2021
@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.
uniqueg commentedon Feb 19, 2021
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
Accept: <content-type>header), the server SHOULD return the response in one of the requested content types, if it can, or else return an appropriate error response, probably406 Not Acceptable.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.
sarthakgupta072 commentedon Apr 5, 2021
In order to test if the connexion validation works with
Accept: <content-type>header or not, we tried running DRS-filer. DRS-filer always sends anapplication/jsonresponse. In the request whenAccept: application/zipwas sent, the server was not throwing an error and giving a200 - okresponse.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
focaand override it something like thisRef: 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.
2 remaining items
uniqueg commentedon May 2, 2021
@sarthakgupta072: any update on this? Just in case - I have removed the
v1.0.0milestone, as I think we should go forward with releasing that version even if that features doesn't make it in that release. Of course it's still a "nice-to-have" and there's still some time to get it in (writing the documentation and implementing/testing FOCA in at least one or two of the apps that don't currently fully use it will take a bit of time still)Rahuljagwani commentedon Jan 20, 2024
Hi @uniqueg, I was looking into
connexiondocumentation. I found out that in their latest version, they are providing support for various content types which we can use directly to solve this issue.(link)We need to migrate to Connexion v3 for this.
Also @alohamora let me know when you are done with
connexionmigration to v3, I will implement this after that, or if you have not started working on migration, even I can start working on that. Do let me know what you prefer :)uniqueg commentedon Jan 22, 2024
Fantastic - thanks a lot @Rahuljagwani - great find!
Yes, @alohamora, please tell @Rahuljagwani if he should go ahead with Connexion v3 migration.
uniqueg commentedon Jan 22, 2024
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?
uniqueg commentedon Feb 5, 2024
@Rahuljagwani @kushagra189 says it's okay, so please go ahead
uniqueg commentedon May 20, 2024
Currently blocked by #188