Comments (19)
Do you get an error? What happens?
from cakephp-swagger-bake.
I forgot the full line, sorry.
/**
* @Swag\SwagDtoQuery(name="Value", type="number", format="double", description="Required.")
* @var number
*/
private $value;
/**
* @return mixed
*/
public function getValue()
{
return $this->value;
}
/**
* @param mixed $value
* @return QueryDto
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
Argument 1 passed to SwaggerBake\Lib\OpenApi\SchemaProperty::setType() must be of the type string, null given, called in /src/WebApp/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/DtoParser.php on line 113
Only work with Integer or String.
from cakephp-swagger-bake.
If i change to string or integer, works well, but i need the param to be a float or decimal.
from cakephp-swagger-bake.
Odd behavior. What type of route is this? HTTP GET or HTTP POST/PUT/PATCH?
from cakephp-swagger-bake.
Also, please post full stack trace.
from cakephp-swagger-bake.
2023-01-05 15:30:50 [TypeError] Argument 1 passed to SwaggerBake\Lib\OpenApi\SchemaProperty::setType() must be of the type string, null given, called in /src/WebApp/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/DtoParser.php on line 113 in /src/WebApp/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/OpenApi/SchemaTrait.php on line 45 Stack Trace: - /src/WebApp/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/DtoParser.php:113 - /src/WebApp/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/OperationRequestBody.php:240 - /src/WebApp/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/OperationRequestBody.php:93 - /src/WebApp/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/OperationFromRouteFactory.php:89 - /src/WebApp/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Swagger.php:337 - /src/WebApp/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Swagger.php:81 - /src/WebApp/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Factory/SwaggerFactory.php:51 - /src/WebApp/vendor/cnizzardini/cakephp-swagger-bake/src/Controller/Component/SwaggerUiComponent.php:50 - /src/WebApp/vendor/cakephp/cakephp/src/Event/EventManager.php:309 - /src/WebApp/vendor/cakephp/cakephp/src/Event/EventManager.php:286 - /src/WebApp/vendor/cakephp/cakephp/src/Event/EventDispatcherTrait.php:92 - /src/WebApp/vendor/cakephp/cakephp/src/Controller/Controller.php:575 - /src/WebApp/vendor/cakephp/cakephp/src/Controller/ControllerFactory.php:96 - /src/WebApp/vendor/cakephp/cakephp/src/Http/BaseApplication.php:313 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:77 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Middleware/CsrfProtectionMiddleware.php:169 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:73 - /src/WebApp/src/Middleware/DebitoEmAnaliseMiddleware.php:19 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:73 - /src/WebApp/src/Middleware/UsuarioMiddleware.php:20 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:73 - /src/WebApp/src/Middleware/TermosFranquiaMiddleware.php:18 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:73 - /src/WebApp/src/Middleware/CorsMiddleware.php:18 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:73 - /src/WebApp/vendor/cakephp/authentication/src/Middleware/AuthenticationMiddleware.php:124 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:73 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Middleware/BodyParserMiddleware.php:159 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:73 - /src/WebApp/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php:161 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:73 - /src/WebApp/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php:68 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:73 - /src/WebApp/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php:126 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:73 - /src/WebApp/vendor/cakephp/debug_kit/src/Middleware/DebugKitMiddleware.php:60 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:73 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Runner.php:58 - /src/WebApp/vendor/cakephp/cakephp/src/Http/Server.php:90 - /src/WebApp/webroot/index.php:40 Request URL: /api/swagger Client IP: 127.0.0.1
Its a HTTP POST.
from cakephp-swagger-bake.
I figured you'd say HTTP POST. The code was never designed expecting an HTTP GET based DTO to be used on a POST route and as such is failing because there is no condition for that.
Best practice is not to placing GET parameters on POST routes since you can just put everything in the POST body, but if you must my suggestion is just to use @SwagQuery
on the controller action to document your GET parameters.
from cakephp-swagger-bake.
Actually that won't work either (most likely) because that too expects GET parameters to only be used on HTTP GET routes....
from cakephp-swagger-bake.
Sorry, if I didnt understood.
So the plugin doenst generete an endpoint (post) on swagger with body where can be double/decimal?
I already have the controller, the decimal works fine, but on swagger shows wrong (string or integer).
from cakephp-swagger-bake.
If the route is HTTP POST, why not use @SwagDtoRequestBody
?
from cakephp-swagger-bake.
I am using this example, dtoBodyExample:
https://github.com/cnizzardini/cakephp-swagger-bake-demo/blob/1.next/src/Controller/ExamplesController.php
Who use this DTO:
https://github.com/cnizzardini/cakephp-swagger-bake-demo/blob/1.next/src/Dto/RequestBodyDto.php
from cakephp-swagger-bake.
Changed to
@swag\SwagRequestBody and @SwagDtoRequestBody(
Same problem.
from cakephp-swagger-bake.
post stack trace please.
from cakephp-swagger-bake.
@swag\SwagRequestBody
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/OpenApi/SchemaTrait.php:45
SwaggerBake\Lib\OpenApi\SchemaProperty->setType
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/DtoParser.php:113
SwaggerBake\Lib\Operation\DtoParser->getSchemaProperties
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/OperationRequestBody.php:240
SwaggerBake\Lib\Operation\OperationRequestBody->assignSwagDto
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/OperationRequestBody.php:93
SwaggerBake\Lib\Operation\OperationRequestBody->getOperationWithRequestBody
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/OperationFromRouteFactory.php:89
SwaggerBake\Lib\Operation\OperationFromRouteFactory->create
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Swagger.php:337
SwaggerBake\Lib\Swagger->buildPathsFromRoutes
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Swagger.php:81
SwaggerBake\Lib\Swagger->__construct
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Factory/SwaggerFactory.php:51
SwaggerBake\Lib\Factory\SwaggerFactory->create
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Controller/Component/SwaggerUiComponent.php:50
SwaggerBake\Controller\Component\SwaggerUiComponent->beforeFilter
CORE/src/Event/EventManager.php:309
Cake\Event\EventManager->_callListener
CORE/src/Event/EventManager.php:286
Cake\Event\EventManager->dispatch
CORE/src/Event/EventDispatcherTrait.php:92
Cake\Controller\Controller->dispatchEvent
CORE/src/Controller/Controller.php:575
Cake\Controller\Controller->startupProcess
CORE/src/Controller/ControllerFactory.php:96
Cake\Controller\ControllerFactory->invoke
CORE/src/Http/BaseApplication.php:313
Cake\Http\BaseApplication->handle
CORE/src/Http/Runner.php:77
Cake\Http\Runner->handle
CORE/src/Http/Middleware/CsrfProtectionMiddleware.php:169
Cake\Http\Middleware\CsrfProtectionMiddleware->process
CORE/src/Http/Runner.php:73
Cake\Http\Runner->handle
APP/Middleware/DebitoEmAnaliseMiddleware.php:19
App\Middleware\DebitoEmAnaliseMiddleware->process
CORE/src/Http/Runner.php:73
Cake\Http\Runner->handle
APP/Middleware/UsuarioMiddleware.php:20
App\Middleware\UsuarioMiddleware->process
CORE/src/Http/Runner.php:73
Cake\Http\Runner->handle
APP/Middleware/TermosFranquiaMiddleware.php:18
App\Middleware\TermosFranquiaMiddleware->process
CORE/src/Http/Runner.php:73
Cake\Http\Runner->handle
APP/Middleware/CorsMiddleware.php:18
App\Middleware\CorsMiddleware->process
CORE/src/Http/Runner.php:73
Cake\Http\Runner->handle
ROOT/vendor/cakephp/authentication/src/Middleware/AuthenticationMiddleware.php:124
Authentication\Middleware\AuthenticationMiddleware->process
CORE/src/Http/Runner.php:73
Cake\Http\Runner->handle
CORE/src/Http/Middleware/BodyParserMiddleware.php:159
Cake\Http\Middleware\BodyParserMiddleware->process
CORE/src/Http/Runner.php:73
Cake\Http\Runner->handle
CORE/src/Routing/Middleware/RoutingMiddleware.php:161
Cake\Routing\Middleware\RoutingMiddleware->process
CORE/src/Http/Runner.php:73
Cake\Http\Runner->handle
CORE/src/Routing/Middleware/AssetMiddleware.php:68
Cake\Routing\Middleware\AssetMiddleware->process
CORE/src/Http/Runner.php:73
Cake\Http\Runner->handle
CORE/src/Error/Middleware/ErrorHandlerMiddleware.php:126
Cake\Error\Middleware\ErrorHandlerMiddleware->process
CORE/src/Http/Runner.php:73
Cake\Http\Runner->handle
ROOT/vendor/cakephp/debug_kit/src/Middleware/DebugKitMiddleware.php:60
DebugKit\Middleware\DebugKitMiddleware->process
CORE/src/Http/Runner.php:73
Cake\Http\Runner->handle
CORE/src/Http/Runner.php:58
Cake\Http\Runner->run
CORE/src/Http/Server.php:90
Cake\Http\Server->run
from cakephp-swagger-bake.
Yeah that doesn't make a lot of sense, it's saying that the value getting passed into here: https://github.com/cnizzardini/cakephp-swagger-bake/blob/1.next/src/Lib/OpenApi/SchemaTrait.php#L45 is failing the type check... but "number"
is indeed a string. I guess double-check you're not doing anything weird on your end and I'll see if I can reproduce this on my end...
from cakephp-swagger-bake.
At my api controller to reproduce:
/**
* Test.
*
* @Swag\SwagDto(class="\App\Dto\RequestBodyDto")
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
* @throws \Cake\Http\Exception\MethodNotAllowedException
*/
public function try()
{
$this->request->allowMethod(["post"]);
$post = [
'value' => $this->request->getData('value')
];
$this->set(compact('post'));
$this->viewBuilder()->setOption('serialize', 'post');
}
Like i said works fine when i change to integer or string, but not if number.
Anyway, thanks for your time.
from cakephp-swagger-bake.
And my routes.php
$routes->scope('/api', function (RouteBuilder $builder){
$builder->setExtensions(['json', 'xml']);
$builder->resources('Test', [
'only' => [
'try',
],
'map' => [
'try' => [
'method' => 'post',
'action' => 'try',
'path' => 'try'
]
],
'prefix' => 'Api'
]);
$builder->connect('/swagger', ['plugin' => 'SwaggerBake', 'controller' => 'Swagger', 'action' => 'index']);
});
from cakephp-swagger-bake.
Remove the @var
annnotations from your code, they are confusing the annotation parser and I don't want to dig into this since the 1.x branch is not really actively developed. I did add some test coverage to debug this here though: #503 but specifically this: https://github.com/cnizzardini/cakephp-swagger-bake/pull/503/files#diff-3773e7eb1700eea788f8f81c15eecb7fed9a872786915f9da358220844058017
Won't be releasing that, just gonna merge it in so there was nothing to actually fix in the library.
from cakephp-swagger-bake.
Thank you man, worked very well, now i can do everything I need.
from cakephp-swagger-bake.
Related Issues (20)
- Remove exception if no routes are found
- Add PHP 8.2 to github actions
- Empty schema causes error in Swagger->getArray HOT 1
- path required set to false with OpenApiPathParam HOT 2
- Run v3.0.0 branch against latest 5.0.0-x
- PHP8.2 - deprecation warning when setting dynamic properties on OpenApi\Schema HOT 4
- SwaggerBake config namespace is null in Configuration constructor HOT 4
- Support for MySQL json field type HOT 7
- OpenApiResponse annotation doesn't work properly with schemaType: 'array' and ref. HOT 4
- OpenApiSchemaProperty(name: 'propert_name', type: 'array') not working
- Logic of Configuration class HOT 11
- Feature Query: is it possible to hide model properties? HOT 4
- Backport fix from 5.x branch
- Too few arguments to function Cake\View\Exception\MissingTemplateException::__construct(), 0 passed HOT 4
- Throw tags taking precedence over OpenApiResponse attribute
- collection generation HOT 3
- Undefined array key "securitySchemes" in Cakaphp 4.15 version HOT 2
- Undefined array key "securitySchemes" HOT 10
- Cannot make controller working HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cakephp-swagger-bake.