Skip to content
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

_COLLECTION changes from api-tools-content-validation not working #31

Open
Lokilein opened this issue Jun 16, 2023 · 0 comments
Open

_COLLECTION changes from api-tools-content-validation not working #31

Lokilein opened this issue Jun 16, 2023 · 0 comments
Labels
Bug Something isn't working

Comments

@Lokilein
Copy link

Lokilein commented Jun 16, 2023

Bug Report

When using content validation with the new options for 'POST_COLLECTION' 'GET_COLLECTION' etc., the documentation does not show the field-list.

Q A
laminas-api-tools/api-tools-content-validation 1.11.0
laminas-api-tools/api-tools-documentation 1.5.0

Summary

In version 1.5.0 of the content-validation module, the option to define validations for collections and entities separately got included. In version 1.3.0 of the same module, adding validation to the GET-resource was included (with 1.6.0, DELETE as well).
This means, that you can now define a validation for any kind of request.

This changes seems to be no part of the documentation module, which uses the content-validation data to show a list of fields in the Request part of the documentation.
Defining a validation for "POST_COLLECTION" does work on the fetchAll method, but it is not shown in the documentation. Using "POST" does work, but means it includes in both, Entity and Collection.
A better example for this is the GET: We are using parameter like page, page_size, order_by etc. in the GET-parameter for the list, though they make no sense for a sinlge entity. Using just "GET" would show these parameter to both transactions.

Current behavior

No Field list is shown when using "POST_COLLECTION", "PUT_COLLECTION" etc.

How to reproduce

  1. Create a default API with collection GET, POST and, for comparison, entities with GET, POST. This must not implement anything, just be there and be working.
  2. Install the current (today 1.11.0) laminas-api-tools/api-tools-content-validation extention
  3. Implement a configuration like this:
    'api-tools-content-validation' => [ 'MyAPI' => [ 'POST_COLLECTION' => 'MySpecs', ], ], 'input_filter_specs' => [ 'MySpecs' => [[ 'name' => 'page', 'required' => false, 'field_type' => 'int', 'filters' => [[ 'name' => 'Laminas\Filter\ToInt', 'options' => [], ],], 'validators' => [], 'description' => 'Page of the collection.', 'allow_empty' => true, 'continue_if_empty' => true, ], ]

As you can see, the validator should only work on the collection, but not on the entity.
4. Call the documentation for the API
5. => No field list is visible
6. Call your api with page=somestringvalue
7. => You receive a 400/422 error, as the filter does apply
8. Change "POST_COLLECTION" to "POST" in the configuration
9. Refresh the documentation
10. => The field list is visible for the collection and the entity as well
11. => The page test now works on both collection and entity (which would be correct though)

Expected behavior

When using "POST_COLLECTION", the field list should only be visible for the fetchAll method, where it is also used.
This is true for all other HTTP-methods as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant