-
Notifications
You must be signed in to change notification settings - Fork 20
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
Prevent loading associations in ApiResponse(associations: $var) #537
Comments
So you are wanting a paginated style response (like in your index action) within the same controller but from another action within this controller. Am I understanding what you are trying to achieve? But it seems you are decorating your responses maybe? Hard to know without having the same level of knowledge within your application...
Yes, this will overwrite the schema reference and replace it with what you defined in
Yes, this is how what you are desiring is generally achieved. What is the problem with loading associations? CakePHP ORM is designed around associations and so this plugin enables developers to express those associations in OpenAPI.
Version 2.1 of this library is pretty old. It's on 2.5.8 in the 2.x branch. Are you certain that's the version you are on? If so, please upgrade as I will only support recent releases. Have you considered using events?Next have you considered using Event Listeners to accomplish your task. If you are doing something unique with those injected dependencies and result decorators, then you might need to do some additional processing. Those events give you complete control over the final OpenAPI schema: https://github.com/cnizzardini/cakephp-swagger-bake/blob/master/docs/events.md |
|
Sorry for my mistake, I have installed v2.5.8 and I am using MixerApi v1.1.7 wirh cakephp ^4.5-RC1. |
Okay no problem, just making sure you are not on an ancient version. So if I am understanding correctly, you really only want to display the base model? In otherwords you'd like to do something like this:
And by passing in an empty whiteList the library would not include any associations? |
Exactly, I mean, all the endpoint that returns a collection of data in my system are paginated, so any time I create an endpoint I need the collection key and an array of Model in the response.
like in the index would be enough, but then I realized that this approach only works for the crud endpoints. So yes |
If that is the case I would submit a PR. This seems like an easy change here: https://github.com/cnizzardini/cakephp-swagger-bake/blob/2.x/src/Lib/Operation/OperationResponseAssociation.php#L74 Then add single test case in here https://github.com/cnizzardini/cakephp-swagger-bake/blob/2.x/tests/TestCase/Lib/Operation/OperationResponseAssociationTest.php (I don't mind assisting on this part). Last updating the documentation here: https://github.com/cnizzardini/cakephp-swagger-bake/blob/2.x/docs/attributes.md (also don't mind helping on this one) I don't believe passing an empty array can work though, as it would possibly be a breaking change, instead the following would be non-breaking:
Then in the code you can do a strict |
Awsome, I will do that for sure. Thank you! |
I already created the PR: #538 |
Okay this is released: https://github.com/cnizzardini/cakephp-swagger-bake/releases/tag/v2.5.9 |
Describe the bug
I have this index action in my BethroomsController class:
This automatically generate a response like this one in swagger, wish is exactly what I want:
Then I create this new action in the same controller:
And the response in the swagger is string, which is wrong, I want the same response than the other example due to the response is a list of bethrooms.
I tried using #[OpenApiResponse(schemaType: 'array', ref: '#/components/schemas/Bethroom')]
but this response is an array of Entities without the collection key
I also tried #[OpenApiResponse(schemaType: 'array', associations: ['table' => 'Bethrooms','whiteList' => []])]
and this create a response similar that the one I am expecting but again it force me to load at least one association and I don't want loading any association.
I have cakephp 4.5 and cakephp-swagger-bake 2.1
The text was updated successfully, but these errors were encountered: