Closed mbehzad-bhz closed 1 month ago
Try using @bodyParam socialMedias object[]
instead of @bodyParam socialMedias array
.
See the examples in the docs. https://scribe.knuckles.wtf/laravel/documenting/query-body-parameters#arrays-of-objects
my updated code is : `/**
}
*/ got error :
Illuminate\View\ViewException
Object of class stdClass could not be converted to string (View: /home/tenetup-coreccconcept/htdocs/coreccconcept.tenetup.com/vendor/knuckleswtf/scribe/resources/views/partials/example-requests/bash.md.blade.php) (View: /home/tenetup-coreccconcept/htdocs/coreccconcept.tenetup.com/vendor/knuckleswtf/scribe/resources/views/themes/default/endpoint.blade.php) (View: /home/tenetup-coreccconcept/htdocs/coreccconcept.tenetup.com/vendor/knuckleswtf/scribe/resources/views/themes/default/endpoint.blade.php) (View: /home/tenetup-coreccconcept/htdocs/coreccconcept.tenetup.com/vendor/knuckleswtf/scribe/resources/views/themes/default/endpoint.blade.php)
at storage/framework/views/5900fb6d077d8febac4c0ce79edd567a.php:16 12▕ <?php endif; ?> 13▕ <?php if($endpoint->hasFiles() || (isset($endpoint->headers['Content-Type']) && $endpoint->headers['Content-Type'] == 'multipart/form-data' && count($endpoint->cleanBodyParameters))): ?> 14▕ <?php $currentLoopData = $endpoint->cleanBodyParameters; $env->addLoop($currentLoopData); foreach($currentLoopData as $parameter => $value): $env->incrementLoopIndices(); $loop = $env->getLastLoop(); ?> 15▕ <?php $currentLoopData = u::getParameterNamesAndValuesForFormData($parameter, $value); $env->addLoop($currentLoopData); foreach($currentLoopData as $key => $actualValue): $env->incrementLoopIndices(); $loop = $env->getLastLoop(); ?> ➜ 16▕ --form "<?php echo "$key=".$actualValue; ?>"<?php if(!($loop->parent->last) || count($endpoint->fileParameters)): ?>\ 17▕ <?php endif; ?> 18▕ <?php endforeach; $env->popLoop(); $loop = $env->getLastLoop(); ?> 19▕ <?php endforeach; $env->popLoop(); $loop = $env->getLastLoop(); ?> 20▕ <?php $currentLoopData = $endpoint->fileParameters; $env->addLoop($currentLoopData); foreach($currentLoopData as $parameter => $value): $env->incrementLoopIndices(); $loop = $env->getLastLoop(); ?>
+1 vendor frames
2 storage/framework/views/5900fb6d077d8febac4c0ce79edd567a.php:16 Illuminate\View\ViewException::("Object of class stdClass could not be converted to string (View: /home/tenetup-coreccconcept/htdocs/coreccconcept.tenetup.com/vendor/knuckleswtf/scribe/resources/views/partials/example-requests/bash.md.blade.php) (View: /home/tenetup-coreccconcept/htdocs/coreccconcept.tenetup.com/vendor/knuckleswtf/scribe/resources/views/themes/default/endpoint.blade.php) (View: /home/tenetup-coreccconcept/htdocs/coreccconcept.tenetup.com/vendor/knuckleswtf/scribe/resources/views/themes/default/endpoint.blade.php)") +1 vendor frames
4 storage/framework/views/5900fb6d077d8febac4c0ce79edd567a.php:16 Illuminate\View\ViewException::("Object of class stdClass could not be converted to string (View: /home/tenetup-coreccconcept/htdocs/coreccconcept.tenetup.com/vendor/knuckleswtf/scribe/resources/views/partials/example-requests/bash.md.blade.php) (View: /home/tenetup-coreccconcept/htdocs/coreccconcept.tenetup.com/vendor/knuckleswtf/scribe/resources/views/themes/default/endpoint.blade.php)") `
@shalvah i just change the library code and its fixed now , the below files its changed:
` @php use Knuckles\Scribe\Tools\WritingUtils as u; /* @var Knuckles\Camel\Output\OutputEndpointData $endpoint / @endphp
curl --request {{$endpoint->httpMethods[0]}} \
{{$endpoint->httpMethods[0] == 'GET' ? '--get ' : ''}}"{!! rtrim($baseUrl, '/') !!}/{{ ltrim($endpoint->boundUri, '/') }}@if(count($endpoint->cleanQueryParameters))?{!! u::printQueryParamsAsString($endpoint->cleanQueryParameters) !!}@endif"@if(count($endpoint->headers)) \
@foreach($endpoint->headers as $header => $value)
--header "{{$header}}: {{ addslashes($value) }}"@if(! ($loop->last) || ($loop->last && count($endpoint->bodyParameters))) \
@endif
@endforeach
@endif
@if($endpoint->hasFiles() || (isset($endpoint->headers['Content-Type']) && $endpoint->headers['Content-Type'] == 'multipart/form-data' && count($endpoint->cleanBodyParameters)))
@foreach($endpoint->cleanBodyParameters as $parameter => $value)
@foreach(u::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $actualValue)
--form "{!! "$key=".(is_object($actualValue) ? json_encode($actualValue) : $actualValue) !!}"@if(!($loop->parent->last) || count($endpoint->fileParameters))\
@endif
@endforeach
@endforeach
@foreach($endpoint->fileParameters as $parameter => $value)
@foreach(u::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $file)
--form "{!! "$key=@".$file->path() !!}" @if(!($loop->parent->last))\
@endif
@endforeach
@endforeach
@elseif(count($endpoint->cleanBodyParameters))
@if ($endpoint->headers['Content-Type'] == 'application/x-www-form-urlencoded')
--data "{!! http_build_query($endpoint->cleanBodyParameters, '', '&') !!}"
@else
--data "{!! addslashes(json_encode($endpoint->cleanBodyParameters, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)) !!}"
@endif
@endif
`
const url = new URL(
"{!! rtrim($baseUrl, '/') !!}/{{ ltrim($endpoint->boundUri, '/') }}"
);
@if(count($endpoint->cleanQueryParameters))
const params = {!! u::printQueryParamsAsKeyValue($endpoint->cleanQueryParameters, "\"", ":", 4, "{}") !!}; Object.keys(params) .forEach(key => url.searchParams.append(key, params[key])); @endif
@if(!empty($endpoint->headers)) const headers = { @foreach($endpoint->headers as $header => $value) "{{$header}}": "{{$value}}", @endforeach @empty($endpoint->headers['Accept']) "Accept": "application/json", @endempty }; @endif
@if($endpoint->hasFiles() || (isset($endpoint->headers['Content-Type']) && $endpoint->headers['Content-Type'] == 'multipart/form-data' && count($endpoint->cleanBodyParameters))) const body = new FormData(); @foreach($endpoint->cleanBodyParameters as $parameter => $value) @foreach( u::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $actualValue) body.append('{!! $key !!}', '{!! is_object($actualValue) || is_array($actualValue) ? json_encode($actualValue) : addslashes($actualValue) !!}'); @endforeach @endforeach @foreach($endpoint->fileParameters as $parameter => $value) @foreach( u::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $file) body.append('{!! $key !!}', document.querySelector('input[name="{!! $key !!}"]').files[0]); @endforeach @endforeach @elseif(count($endpoint->cleanBodyParameters)) @if ($endpoint->headers['Content-Type'] == 'application/x-www-form-urlencoded') let body = "{!! http_build_query($endpoint->cleanBodyParameters, '', '&') !!}"; @else let body = {!! json_encode($endpoint->cleanBodyParameters, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}; @endif @endif
fetch(url, { method: "{{$endpoint->httpMethods[0]}}", @if(count($endpoint->headers)) headers, @endif @if($endpoint->hasFiles() || (isset($endpoint->headers['Content-Type']) && $endpoint->headers['Content-Type'] == 'multipart/form-data' && count($endpoint->cleanBodyParameters))) body, @elseif(count($endpoint->cleanBodyParameters)) @if ($endpoint->headers['Content-Type'] == 'application/x-www-form-urlencoded') body, @else body: JSON.stringify(body), @endif @endif }).then(response => response.json());
`
`the changes is only about $actualValue
@foreach( u::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $actualValue)
body.append('{!! $key !!}', '{!! is_object($actualValue) || is_array($actualValue) ? json_encode($actualValue) : addslashes($actualValue) !!}');
@endforeach`
and
`--form "{!! "$key=".(is_object($actualValue) ? json_encode($actualValue) : $actualValue) !!}"@if(!($loop->parent->last) || count($endpoint->fileParameters))\`
hey, to format your multiline code snippets correctly in Markdown use 3x backticks (```). So do:
``` this is multiple lines ```
and you'll get:
this is
multiple lines
Don't do
`this is multiple lines`
because you'll get:
this is multiple lines
which makes it harder to read your code
Scribe version
^4.37
PHP version
^8.2
Framework
Laravel
Framework version
^11.9
Scribe config
What happened?
this is my php doc for endpoint that has request socialMedias with type and link in every object of array : `/**
link
andtype
.and curl is : curl -X 'POST' \ 'https://example.com/api/supplier_request/sendRequest' \ -H 'accept: application/json' \ -H 'Content-Type: multipart/form-data' \ -F 'name=My Supplier' \ -F 'brandName=My Brand' \ -F 'description=Leading supplier of organic products.' \ -F 'text=We specialize in organic and eco-friendly products.' \ -F 'thumb=@3.jpeg;type=image/jpeg' \ -F 'brandLogo=@3.jpeg;type=image/jpeg' \ -F 'socialMedias=string'
it should be somthing like this : curl -X 'POST' \ 'https://example.com/api/supplier_panel/supplier_request/sendRequest' \ -H 'accept: application/json' \ -H 'Content-Type: multipart/form-data' \ -F 'name=My Supplier' \ -F 'brandName=My Brand' \ -F 'description=Leading supplier of organic products.' \ -F 'text=We specialize in organic and eco-friendly products.' \ -F 'thumb=@3.jpeg;type=image/jpeg' \ -F 'brandLogo=@3.jpeg;type=image/jpeg' \ -F 'socialMedias[0][type]=INSTAGRAM' \ -F 'socialMedias[0][link]=https://instagram.com/mybrand' \ -F 'socialMedias[1][type]=FACEBOOK' \ -F 'socialMedias[1][link]=https://facebook.com/mybrand'
would anyone be so kind as to respond to my question, please?
Docs