L5 - swagger why Required #SWG\Info() not found? - php

I'm integrating into my Laravel5 project swagger :
"darkaonline/l5-swagger": "^5.5"
I have two projects with no problem having the following block of code defined at the top of ../routes/api.php
/**
* #SWG\Swagger(
* basePath="/api",
* #SWG\Info(
* title="MyApp API",
* version="0.2"
* )
* )
*/
Now with a new project I'm experiencing #SWG\Info() not found error when :
php artisan l5-swagger:generate
If I move the #SWG\Swagger block of code form routes\api.php to
..../app/Http/Controllers/ApiController.php
Command l5-swagger:generate will instead succeed.
Why is that? Laravel Projects looks the same. What could prevent from generating the swagger having the SWG\info in routes\api.php?

You already installed this below the library.
"darkaonline/l5-swagger": "^5.5"
Then put this below code in parent controller below the class name like this.
/**
* #SWG\Swagger(
* #SWG\Info(
* title="Site Title",
* version="1.0",
* description="Site description",
* #SWG\Contact(
* email="xyz#xyz.com"
* )
* )
* )
*/
class Controller extends BaseController
{
}

I got this problem as well.
Laravel version:5 5.7
After running command:
composer require zircote/swagger-php:2.*require zircote/swagger-php:2.*
Then add the following setting .env
SWAGGER_VERSION=2.0
Changing a line in Config/l5-swagger.php
'swagger_version' => env('SWAGGER_VERSION', '2.0'),
Problem solved~solved.

Related

Oxidshop - Override changebasket function in BasketComponent

I am customising Oxidshop for one of my clients. I want to customise the "changebasket" function in BasketComponent file to add more validations to it.
For this purpose I have also created a custom module. I am trying to extend the class using metadata file.
'extend' => array(
'oxcmp_basket' => \MyVendor\Basket\Application\Components\BasketComponent::class,
),
The BasketComponent file has following code,
<?php
namespace MyVendor\Basket\Application\Components;
/**
* Class LinslinSliderMain.
*/
class BasketComponent extends BasketComponent_parent
{
/**
* #param null $sProductId
* #param null $dAmount
* #param null $aSel
* #param null $aPersParam
* #param bool $blOverride
*/
public function changebasket($sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = true)
{
echo 'call success';exit;
parent::changebasket($sProductId, $dAmount, $aSel, $aPersParam, $blOverride);
}
}
The gets activated. However, when I refresh any page in frontend, it gets deactivated automatically. I don't know, what's wrong with the code.
EDIT: I am getting this error in oxideshop.log file
Module class MyVendor\Basket\Application\Components\BauerBasketComponent not found. Module ID basket disabled.
depending on your OXID eShop version it might be a different line, but the error message you are stating originates from OxidEsales\EshopCommunity\Core\Module\ModuleChainsGenerator::onModuleExtensionCreationError.
When activating your module, the system tries to generate the class chain with your BasketComponent class in it. As your class is a namespaced class, OXID tries to check if it can find the class via the composer autoload file, if not, the shop throws this exception.
So I assume the module is not installed via composer, at least the namespace seems unknown to composer. You can check in the module documentation on how this should be achieved
Hope I could help
/Flo

NelmioApiDocBundle not generate documentation

I want to use NelmioApiDocBundle for generating documentation automatically. I fallowed standard Symfony doc to install and configure it: https://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html. Unfortunately when I go to /api/doc my doc is empty.
I use Symfony 3.4 and NelmioApiDocBundle in v. 3.2.0.
Here is my config:
nelmio_api_doc:
areas:
path_patterns: # an array of regexps
- ^/api(?!/doc$)
host_patterns:
- ^api\.
documentation:
host: 127.0.0.1
schemes: [http, https]
info:
title: Thanatos API
description: This is documentation of Thanatos
version: 1.0.0
security:
- Bearer: []
And annotations in my controller (in beginning I want to see any data in my documentation):
/**
* #Route(
* "/",
* name="thanatos_dashboard_index",
* )
*
* #SWG\Response(
* response=200,
* description="Returns the rewards of an user",
* #SWG\Schema(
* type="array",
* #SWG\Items(ref=#Model(type=Reward::class, groups={"full"}))
* )
* )
* #SWG\Parameter(
* name="order",
* in="query",
* type="string",
* description="The field used to order rewards"
* )
* #SWG\Tag(name="rewards")
* #NelmioSecurity(name="Bearer")
*/
public function indexAction()
{
return $this->render("#AppThanatos/Dashboard/index.html.twig");
}
In /api/doc I see "No operations defined in spec!". What am I doing wrong?
#UPDATE
I just start to use Sami: http://symfony.com/projects/sami
I've the same problem. Working on my Mac I have always ERR_EMPTY_RESPONSE (using Chrome) but in the production environment the same configuration works fine.
The only difference was Xdebug, I've tried disabling the module and now everything works.
The assets normally are installed by composer if any command event (usually post-install-cmd or post-update-cmd) triggers the ScriptHandler::installAssets script. If you have not set up this script, you can manually execute this command:
php bin/console assets:install --symlink
Try this :
Replace
* #Route(
* "/",
* name="thanatos_dashboard_index",
* )
By
#Rest\Get("/getVehicles")
And, in your action controller, return array or object like this :
$em = $this->getDoctrine();
return $em->getRepository('AppBundle:Vehicle')->findAll();

Where to put #SWG\Definition to be reused with Swagger-PHP and Nelmio API-DOC Bundle

I'd like to write a #SWG\Definition somewhere and refer to it in the #SWG\Schema in #SWG\Response annotations for multiple REST API actions in my Symfony 3 application. I'm using the dev-master version of Nelmio's api-doc-bundle but I can seem to find anything that suggests where that definition should go. The Swagger-PHP docs urge not repeating if possible and I'd like to follow that recommendation. Any hints?
Typical... Finally break down and ask then figure out a solution shortly after...
I found that I can preload the documentation data in Symfony's app/config/config.yml.
nelmio_api_doc:
documentation:
definitios:
Error:
type: object
properties:
success:
type: boolean
example: false
error:
type: string
example: message
Now I can use something like this in all my REST actions
/**
* #API\Operation(
* ...
* #SWG\Response(
* response="default",
* description="Failure",
* #SWG\Schema(ref="#definitions/Error")
* )
* )
*/

Doctrine MappingException with message 'The target-entity Entity\\ItemsBags cannot be found in 'Entity\\Players#itemsBag'

Good day. I'm already on my second day and I can not understand what's the matter ... I get the error in runtime:
PHP Fatal error: Uncaught exception
'Doctrine\ORM\Mapping\MappingException' with message 'The
target-entity Entity\ItemsBags cannot be found in
'Entity\Players#itemsBag'.' in
/var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:762
Stack trace:
#0./var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php(1028):
Doctrine\ORM\Mapping\MappingException::invalidTargetEntityClass('Entity\\ItemsBag...',
'Entity\\Players', 'itemsBag')
#1./var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(272):
Doctrine\ORM\Mapping\ClassMetadataInfo->validateAssociations()
#2./var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(251):
Doctrine\ORM\Mapping\ClassMetadataFactory->validateRuntimeMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata),
NULL)
#3./var/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(332):
Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadM in
/var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php
on line 762
When I check the doctrine, and the update, everything goes well:
root#comp:# php vendor/bin/doctrine orm:schema:update --force Updating
database schema... Database schema updated successfully! "4" queries
were executed
root#comp:# php vendor/bin/doctrine orm:validate-schema [Mapping] OK
- The mapping files are correct. [Database] OK - The database schema is in sync with the mapping files.
I tried to clear the cache, delete the proxy and regenerate them, but nothing produced results ...
root#comp:# php vendor/bin/doctrine orm:clear-cache:metadata
Clearing ALL Metadata cache entries
Successfully deleted cache entries.
root#comp:# php vendor/bin/doctrine orm:clear-cache:query
Clearing ALL Query cache entries
Successfully deleted cache entries.
root#comp:# php vendor/bin/doctrine orm:clear-cache:result
Clearing ALL Result cache entries
Successfully deleted cache entries.
root#comp:# php vendor/bin/doctrine orm:generate-proxies
Processing entity "Entity\Objects"
Processing entity "Entity\Weapons"
Processing entity "Entity\ItemsBags"
Processing entity "Entity\Players"
Processing entity "Entity\Translations"
Processing entity "Entity\Worlds"
Processing entity "Entity\Tiles"
Processing entity "Entity\WorldStructures"
Proxy classes generated to "/tmp"
Players.php
namespace Entity;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* #Entity
* #Table(name="players")
*
*/
class Players{
...
/**
* #var ItemsBags
*
* #OneToOne(targetEntity="ItemsBags", mappedBy="player")
*/
private $itemsBag;
...
}
ItemsBags.php
namespace Entity;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* #Entity
* #Table(name="item_bags")
*
*/
class ItemsBags{
...
/**
* #var Players
*
* #OneToOne(targetEntity="Players", inversedBy="itemsBag")
* #JoinColumn(name="player_id", referencedColumnName="id")
*/
private $player;
...
}
Tell me please, what am I doing wrong?
Thanks to #Sarcoma. I just forgot to specify autoload section in my composer.json
"autoload": {
"psr-4": { "": "core/" }
},
P.S Can enyone me tell, why my project running normal before?) Before I too have many entinties, no have that section in my composer.json, but all works fine.

CRON command with Yii

I have a code that will automatic create a sitemap.xml . My Url look like this : http://example.com/sitemap
But now I want it to automatic run every minutes (just test) . I tried 2 way but none of them work :
first is call through URL ,ex:
*/1 * * * * wget http://example.com/sitemap
or
*/5 * * * * curl http://example.com/check
second is call throught php file , I'm using Yii so i'm not sure what the file .php is ? is this controller file or something else?
*/1 * * * * /usr/bin/php /home/domains/public_html/protected/modules/homepage/controller/HomepageController.php
my Sitemap action's code inside HomepageController.php
Use console command for running CRON calls. For example, create SitemapCommand.php (place it in protected/command/) with following code:
class SitemapCommand extends CConsoleCommand
{
public function actionGenerate($debug=0)
{
#generating of sitemap
}
}
Then add line like this, to your crontab file:
*/1 * * * * /usr/bin/php /home/domains/public_html/protected/yiic.php sitemap generate
You have to put something like this in your linux cron tab->
http://www.Yourwebstieaddress.com/index.php (use one spacebar) Controller_name (use one spacebar) function_name
it will definitely work

Categories