shalvah 4 vuotta sitten
vanhempi
commit
8fb10116cd

+ 24 - 6
docs/documenting/documenting-endpoint-query-parameters.md

@@ -5,16 +5,16 @@ To describe query parameters for your endpoint, use the `@queryParam` annotation
 
 The `@queryParam` annotation takes the name of the parameter, an optional type, an optional "required" label, and a description.
 
-If you don't specify a type, Scribe will assume it's `string`. See [the documentation on body parameters](./documenting/documenting-endpoint-body-parameters.html) for a list of valid types.
+If you don't specify a type, Scribe will assume it's `string`. See [the documentation on body parameters](./documenting-endpoint-body-parameters.html) for a list of valid types.
 
 Here's an example:
 
 ```php
 /**
- * @queryParam sort string Field to sort by. Defaults to 'id'.
- * @queryParam fields required Comma-separated fields to include in the response
- * @queryParam filters[published_at] Filter by date published.
- * @queryParam filters[title] Filter by title.
+  * @queryParam sort string Field to sort by. Defaults to 'id'.
+  * @queryParam fields required Comma-separated list of fields to include in the response. Example: title,published_at,is_public
+  * @queryParam filters[published_at] Filter by date published.
+  * @queryParam filters[is_public] integer Filter by whether a post is public or not. Example: 1
  */
 public function listPosts()
 {
@@ -29,6 +29,24 @@ The query parameters will be included in the generated documentation text and ex
 ![](../images/endpoint-queryparams-2.png)
 
 
+If you need to handle array/object parameters, you can use the same conventions as [for body parameters](./documenting-endpoint-body-parameters.html#handling-array-and-object-parameters):
+
+```php
+/**
+  * @queryParam sort string Field to sort by. Defaults to 'id'.
+  * @queryParam fields string[] required Comma-separated list of fields to include in the response. Example: title,published_at,is_public
+  * @queryParam filters object Fields to filter by
+  * @queryParam filters.published_at Filter by date published.
+  * @queryParam filters.is_public integer Filter by whether a post is public or not. Example: 1
+ */
+```
+
+![](../images/endpoint-queryparams-4.png)
+
+```eval_rst
+.. Tip:: You should avoid using query parameters that are arrays or objects, because [there isn't a standardised format for handling them](https://stackoverflow.com/a/9547490/7370522).
+```
+
 If you're using a FormRequest in your controller, you can also add the `@queryParam` annotation there instead, and Scribe will fetch it.
 
 ```php
@@ -65,7 +83,7 @@ For instance:
     */
 ```
 
-![](../images/endpoint-queryparams-3.png)
+![](../images/endpoint-queryparams-4.png)
 
 ## Describing URL parameters
 To describe parameters in the URL, use the `@urlParam` annotation. For instance, if you defined your Laravel route like this:

BIN
docs/images/endpoint-bodyparams-2.png


BIN
docs/images/endpoint-queryparams-1.png


BIN
docs/images/endpoint-queryparams-2.png


BIN
docs/images/endpoint-queryparams-3.png


BIN
docs/images/endpoint-queryparams-4.png


+ 0 - 1
src/Extracting/Strategies/Responses/UseResponseFileTag.php

@@ -23,7 +23,6 @@ class UseResponseFileTag extends Strategy
      * @param array $alreadyExtractedData
      *
      * @return array|null
-     * @throws \Exception If the response file does not exist
      *
      */
     public function __invoke(Route $route, \ReflectionClass $controller, \ReflectionFunctionAbstract $method, array $routeRules, array $alreadyExtractedData = [])

+ 1 - 3
src/Tools/WritingUtils.php

@@ -44,9 +44,7 @@ class WritingUtils
     public static function printQueryParamsAsString(array $cleanQueryParams): string
     {
         $qs = '';
-        foreach ($cleanQueryParams as $parameter => $value) {
-            $paramName = urlencode($parameter);
-
+        foreach ($cleanQueryParams as $paramName => $value) {
             if (!is_array($value)) {
                 $qs .= "$paramName=" . urlencode($value) . "&";
             } else {

+ 1 - 1
src/Writing/PostmanCollectionWriter.php

@@ -210,7 +210,7 @@ class PostmanCollectionWriter
                 continue;
             }
 
-            if (Str::endsWith($parameterData['type'], '[]')) {
+            if (Str::endsWith($parameterData['type'], '[]') || $parameterData['type'] === 'object') {
                 $values = empty($parameterData['value']) ? [] : $parameterData['value'];
                 foreach ($values as $index => $value) {
                     // PHP's parse_str supports array query parameters as filters[0]=name&filters[1]=age OR filters[]=name&filters[]=age