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

array to string conversion #455

Closed
1 task done
ibrahem-kamal opened this issue Mar 29, 2022 · 4 comments
Closed
1 task done

array to string conversion #455

ibrahem-kamal opened this issue Mar 29, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@ibrahem-kamal
Copy link

when adding nested array it fails in generating the docs and gives the error below ,

image

it fails because of the filter.categories_ids and filter.brands_ids are arrays

image

@ibrahem-kamal ibrahem-kamal added the bug Something isn't working label Mar 29, 2022
@issakujitsuk
Copy link

I'm facing a similar problem, so I'll add some information.

Points:

  • 'example_languages': "bash", "javascript", "php", etc
  • Route method must be "get"

Case 1.

routes/api.php:

/**
 * ?param[id][0]=1
 * @queryParam param object
 * @queryParam param.id integer[] required
 */
Route::get("/test", function () {
    return "Test";
});

Then

  at vendor/knuckleswtf/scribe/src/Tools/WritingUtils.php:119
    115▕                 } else {
    116▕                     // Hash query param (eg filter[name]=john should become "filter[name]": "john")
    117▕                     foreach ($value as $item => $itemValue) {
    118▕                         $output .= str_repeat(" ", $spacesIndentation);
  ➜ 119▕                         $output .= "$startLinesWith$quote$parameter" . "[$item]$quote$delimiter $quote$itemValue$quote$endLinesWith\n";
    120▕                     }
    121▕                 }
    122▕             }
    123▕         }

      +9 vendor frames 
  10  storage/framework/views/a445359943839067f85d5861bd9b00bd1213813a.php:15
      Knuckles\Scribe\Tools\WritingUtils::printQueryParamsAsKeyValue([], "'", "=>", "[]")

      +8 vendor frames 
  19  storage/framework/views/82d66105162ba1e5469d368df4c08c33adede6c9.php:21
      Illuminate\View\View::render()

Case 2.

routes/api.php:

/**
 * ?param[0][id]=1
 * @queryParam param object[]
 * @queryParam param.*.id integer required
 */
Route::get("/test", function () {
    return "Test";
});

Then

  at vendor/knuckleswtf/scribe/src/Tools/WritingUtils.php:114
    110▕                 }
    111▕                 if (array_keys($value)[0] === 0) {
    112▕                     // List query param (eg filter[]=haha should become "filter[]": "haha")
    113▕                     $output .= str_repeat(" ", $spacesIndentation);
  ➜ 114▕                     $output .= "$startLinesWith$quote$parameter" . "[]$quote$delimiter $quote$value[0]$quote$endLinesWith\n";
    115▕                 } else {
    116▕                     // Hash query param (eg filter[name]=john should become "filter[name]": "john")
    117▕                     foreach ($value as $item => $itemValue) {
    118▕                         $output .= str_repeat(" ", $spacesIndentation);

      +9 vendor frames 
  10  storage/framework/views/a445359943839067f85d5861bd9b00bd1213813a.php:15
      Knuckles\Scribe\Tools\WritingUtils::printQueryParamsAsKeyValue([], "'", "=>", "[]")

      +8 vendor frames 
  19  storage/framework/views/82d66105162ba1e5469d368df4c08c33adede6c9.php:21
      Illuminate\View\View::render()

My environment:

  • PHP version: 8.0.8
  • Framework: Laravel
  • Laravel/Lumen version: v9.0.2
  • Scribe version: 3.26.0

My Scribe config (minus the comments):

<?php
use Knuckles\Scribe\Extracting\Strategies;
return [
    'theme' => 'default',
    'title' => null,
    'description' => '',
    'base_url' => null,
    'routes' => [
        [
            'match' => [
                'prefixes' => ['api/*'],
                'domains' => ['*'],
                'versions' => ['v1'],
            ],
            'include' => [
            ],
            'exclude' => [
            ],
            'apply' => [
                'headers' => [
                    'Content-Type' => 'application/json',
                    'Accept' => 'application/json',
                ],
                'response_calls' => [
                    'methods' => ['GET'],
                    'config' => [
                        'app.env' => 'documentation',
                    ],
                    'queryParams' => [
                    ],
                    'bodyParams' => [
                    ],
                    'fileParams' => [
                    ],
                    'cookies' => [
                    ],
                ],
            ],
        ],
    ],
    'type' => 'static',
    'static' => [
        'output_path' => 'public/docs',
    ],
    'laravel' => [
        'add_routes' => true,
        'docs_url' => '/docs',
        'middleware' => [],
    ],
    'try_it_out' => [
        'enabled' => true,
        'base_url' => null,
        'use_csrf' => false,
        'csrf_url' => '/sanctum/csrf-cookie',
    ],
    'auth' => [
        'enabled' => false,
        'default' => false,
        'in' => 'bearer',
        'name' => 'key',
        'use_value' => env('SCRIBE_AUTH_KEY'),
        'placeholder' => '{YOUR_AUTH_KEY}',
        'extra_info' => 'You can retrieve your token by visiting your dashboard and clicking <b>Generate API token</b>.',
    ],
    'intro_text' => "",
    'example_languages' => [
        "php",
        // 'bash',
        // 'javascript',
    ],
    'postman' => [
        'enabled' => true,
        'overrides' => [
        ],
    ],
    'openapi' => [
        'enabled' => true,
        'overrides' => [
        ],
    ],
    'default_group' => 'Endpoints',
    'logo' => false,
    'faker_seed' => null,
    'strategies' => [
        'metadata' => [
            Strategies\Metadata\GetFromDocBlocks::class,
        ],
        'urlParameters' => [
            Strategies\UrlParameters\GetFromLaravelAPI::class,
            Strategies\UrlParameters\GetFromLumenAPI::class,
            Strategies\UrlParameters\GetFromUrlParamTag::class,
        ],
        'queryParameters' => [
            Strategies\QueryParameters\GetFromFormRequest::class,
            Strategies\QueryParameters\GetFromInlineValidator::class,
            Strategies\QueryParameters\GetFromQueryParamTag::class,
        ],
        'headers' => [
            Strategies\Headers\GetFromRouteRules::class,
            Strategies\Headers\GetFromHeaderTag::class,
        ],
        'bodyParameters' => [
            Strategies\BodyParameters\GetFromFormRequest::class,
            Strategies\BodyParameters\GetFromInlineValidator::class,
            Strategies\BodyParameters\GetFromBodyParamTag::class,
        ],
        'responses' => [
            Strategies\Responses\UseTransformerTags::class,
            Strategies\Responses\UseApiResourceTags::class,
            Strategies\Responses\UseResponseTag::class,
            Strategies\Responses\UseResponseFileTag::class,
            Strategies\Responses\ResponseCalls::class,
        ],
        'responseFields' => [
            Strategies\ResponseFields\GetFromResponseFieldTag::class,
        ],
    ],
    'fractal' => [
        'serializer' => null,
    ],
    'routeMatcher' => \Knuckles\Scribe\Matching\RouteMatcher::class,
    'database_connections_to_transact' => [config('database.default')]
];

@issakujitsuk
Copy link

Sorry💦 maybe the problem mentioned in my reply is a duplicate of issue #308

@shalvah
Copy link
Contributor

shalvah commented Jan 15, 2023

This should be fixed by #603. Let me know if it's still an issue.

@shalvah shalvah closed this as completed Jan 15, 2023
@chWagnr
Copy link

chWagnr commented Jan 17, 2023

Hi @shalvah
it works with PHP, JS and Python, but not with bash

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

4 participants