NelmioApiDocBundle not generate documentation - php

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();

Related

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

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.

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")
* )
* )
*/

AWS AMI Linux set crontab using arguments. I tried many solutions but can't resolve

I need to set one crone job with passing arguments using crontab of AWS AMI Linux.
I was tried like many things but none of working,
0 * * * * php /var/www/html/cron.php command=purge-unused-uploaded-files
0 * * * * php /var/www/html/cron.php?command=purge-unused-uploaded-files
0 * * * * php /var/www/html/cron.php command="purge-unused-uploaded-files"
0 * * * * php /var/www/html/cron.php -args command=purge-unused-uploaded-files
0 * * * * php /var/www/html/cron.php -args command="purge-unused-uploaded-files"
Please help me!
do you use $_GET in the script? Its not set when run like you do. Add this code
parse_str(implode('&', array_slice($argv, 1)), $_GET);
to parse the command line args into $_GET. Or use curl.

Symfony doctrine:schema:update not working

I have a strange problem :
I have an application symfony 2.3 (with sonata user)
I created a bundle with one entity - the entity was created without a problem
then I had to modify the entity and now it seems to be impossible to modify the schema :
To see what happens I increased all the string lengths with +1
The entity code (with annotations) :
namespace Too\ConfigAppBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* ConfigApp
*
* #ORM\Table(name="ConfigApp")
* #ORM\Entity(repositoryClass="Too\ConfigAppBundle\Entity\ActiviteRepository")
*/
class ConfigApp
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string $nom
*
* #ORM\Column(name="nom", type="string", length=101, unique=true)
*/
private $nom;
/**
* #var string $nomSlug
*
* #Gedmo\Slug(fields={"nom"}, updatable=true, separator="_")
* #ORM\Column(name="nomSlug", type="string", length=101, nullable=true)
*/
private $nomSlug;
/**
* #var string $email
*
* #ORM\Column(name="email", type="string", length=151)
*/
private $email;
/**
* #var string $telephone
*
* #ORM\Column(name="telephone", type="string", length=16)
*/
private $telephone;
/**
* #var datetime $cree_le
*
* #Gedmo\Timestampable(on="create")
* #ORM\Column(name="cree_le", type="datetime")
*/
private $cree_le;
/**
* #var datetime $modifie_le
*
* #Gedmo\Timestampable(on="update")
* #ORM\Column(name="modifie_le", type="datetime")
*/
private $modifie_le;
...
Now see the result of :
php app/console doctrine:schema:update --dump-sql
CREATE TABLE ConfigApp (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(100) NOT NULL, nomSlug VARCHAR(100) NOT NULL, email VARCHAR(150) NOT NULL, telephone VARCHAR(15) NOT NULL, cree_le DATETIME NOT NULL, modifie_le DATETIME NOT NULL, PRIMARYKEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
None of the new length is taken in account :
for example the field nom should have length=101,
but the dump-sql gives nom VARCHAR(100) !
Could anyone try to figure out whats going wrong ?
Thanks !
EDIT :
I tried to clear the cache before with :
* php app/console doctrine:cache:clear-metadata
* php app/console cache:clear
* by deleting all content in cache folders
I also tried --dump-sql and --force.
This changes nothing at all.
Please any hint would be welcome !
I just ended up on the exact same issue: schema doesn't update.
Note that --force returns exactly the same thing as --dump-sql, the only difference is that --force runs the SQL against the database.
Although, in my case, the issue wasn't because of the .orm.xml file. It was because I've set this in the config_dev.xml:
doctrine:
orm:
metadata_cache_driver:
type: memcached
host: localhost
port: 11211
instance_class: Memcached
query_cache_driver:
type: memcached
host: localhost
port: 11211
instance_class: Memcached
result_cache_driver:
type: memcached
host: localhost
port: 11211
instance_class: Memcached
Even when I issue an often salvatory:
php app/console cache:clear
the memcached data isn't flushed. So I had to restart memcached, then everything was up and running again!
So thanks for your question, it led me to the right spot in my case.
UPDATE: as Phil suggested above, running this command does the trick too:
php app/console doctrine:cache:clear-metadata
It is possible that you forget to enable Doctrine auto mapping;
orm:
#auto_mapping: true
If auto mapping is disabled (or commented like above) , you should register Entities of each bundle manually.
orm:
entity_managers:
default:
mappings:
AcmeHelloBundle: ~
Try to use YAML instead of the default annotation when you run
php app/console doctrine:generate:entity
Or instead of running
app/console doctrine:schema:update --force
You can just manually create your MySql table which is a very tedious task
I found the solution :
I did not see before but there was a doctrine folder in src\Too\ConfigAppBundle\Resources\config containing a file called ConfigApp.orm.yml :
Too\ConfigAppBundle\Entity\ConfigApp:
type: entity
table: null
repositoryClass: Too\ConfigAppBundle\Entity\ConfigAppRepository
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
nom:
type: string
length: '100'
nomSlug:
type: string
length: '100'
email:
type: string
length: '150'
telephone:
type: string
length: '15'
cree_le:
type: datetime
length: null
modifie_le:
type: datetime
length: null
lifecycleCallbacks: { }
I deleted this folder and now updating the schema works again.
Surely I did something to generate this doctrine folder but I don't know what it was - if someone could tell me how this stuff is generated - and why ?
Though some of the answers given by #rai and others are correct, one more suggestion for Symfony version is equal to or above 3.0 please use bin/console instead app/console, as shown below,
bin/console doctrine:schema:update --force
i think its beacause of the doctrine:mapping:import command. This command stores the schema of an existing database into .orm.xml files. Probebly you execute this command.
I had the same issue, coast me a lot of time to find out.
Because I was using .orm.yml-mapping I had the issue that I created the doctrine-folder, in which the yml mappings were present, under the wrong path, so I fixed it by moving the doctrine-folder to the the config folder:
...\BundleName\Resources\config\doctrine\MyEntity.orm.yml
Try
php app/console doctrine:schema:update --force
this is update your database schema with entity
Type php app/console help doctrine:schema:update in CLI
--dump-sql Dumps the generated SQL statements to the screen (does no
t execute them).
...
--force Causes the generated SQL statements to be physically exec
uted against your database.
So try the --force instead of --dump-sql.
And here is the command for cache clearing :
php app/console cache:clear
Don't forget to use the help keyword before a command namespace in order to get the help message for that command.
Hope it helps

CakePHP 1.3 - Infinite looping in cake libraries, Apache crash, Session helper and __start()?

Upon adding the session helper to the app controller Apache begins crashing. I've tracked the problem down a ways with logging and found that in /CORE/cake/libs/controller/component/session the function check() starts running once and doesn't complete. However, the function it calls ,__start(), runs infinitely (at least until Apache crashes it). And by running infinitely I mean the entire __start() function is run multiple times all the way through. Again, this happens once I add the session helper in app controller. Without it Cake seems to run fine until I hit a point where the session helper is used in a view. This system is being upgraded from Cake 1.1 and in Cake 1.1 the session helper was automatically included and ran fine. I've attempted this on both Cake 1.3.7 and Cake 1.3.15 with the same result. I'm guessing something with the session settings conflicts with the way Cake 1.3 does things. Below is my config/core file, the crash information from Apache, and the Apache log just before the crash. If any other information would be helpful please let me know in the comments. Any suggestions how to fix this? Thanks!
EDIT: I forgot to include a relevant discussion here. Unfortunately, they don't have a clear solution here, but they appear to want to fix the bug in cake, where I would be happy to alter my code to avoid the bug.
EDIT 2: I recently discovered that the manager of this project plans to discontinue the use of database sessions in the future, so that completely fixes the situation for me. Of course I will leave this question up for future visitors though.
app/config/core.php:
<?php
/**
* This is core configuration file.
*
* Use it to configure core behavior of Cake.
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* #copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* #link http://cakephp.org CakePHP(tm) Project
* #package cake
* #subpackage cake.app.config
* #since CakePHP(tm) v 0.2.9
* #license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* CakePHP Debug Level:
*
* Production Mode:
* 0: No error messages, errors, or warnings shown. Flash messages redirect.
*
* Development Mode:
* 1: Errors and warnings shown, model caches refreshed, flash messages halted.
* 2: As in 1, but also with full debug messages and SQL output.
*
* In production mode, flash messages redirect after a time interval.
* In development mode, you need to click the flash message to continue.
*/
//Configure::write('debug', 2);
/**
* CakePHP Log Level:
*
* In case of Production Mode CakePHP gives you the possibility to continue logging errors.
*
* The following parameters can be used:
* Boolean: Set true/false to activate/deactivate logging
* Configure::write('log', true);
*
* Integer: Use built-in PHP constants to set the error level (see error_reporting)
* Configure::write('log', E_ERROR | E_WARNING);
* Configure::write('log', E_ALL ^ E_NOTICE);
*/
//Configure::write('log', true);
/**
* Application wide charset encoding
*/
//Configure::write('App.encoding', 'UTF-8');
/**
* To configure CakePHP *not* to use mod_rewrite and to
* use CakePHP pretty URLs, remove these .htaccess
* files:
*
* /.htaccess
* /app/.htaccess
* /app/webroot/.htaccess
*
* And uncomment the App.baseUrl below:
*/
//Configure::write('App.baseUrl', env('SCRIPT_NAME'));
/**
* Uncomment the define below to use CakePHP prefix routes.
*
* The value of the define determines the names of the routes
* and their associated controller actions:
*
* Set to an array of prefixes you want to use in your application. Use for
* admin or other prefixed routes.
*
* Routing.prefixes = array('admin', 'manager');
*
* Enables:
* `admin_index()` and `/admin/controller/index`
* `manager_index()` and `/manager/controller/index`
*
* [Note Routing.admin is deprecated in 1.3. Use Routing.prefixes instead]
*/
//Configure::write('Routing.prefixes', array('admin'));
/**
* Turn off all caching application-wide.
*
*/
//Configure::write('Cache.disable', true);
define('DEBUG', 2);
define('DEBUG_AJAX', true);
/**
* Enable cache checking.
*
* If set to true, for view caching you must still use the controller
* var $cacheAction inside your controllers to define caching settings.
* You can either set it controller-wide by setting var $cacheAction = true,
* or in each action using $this->cacheAction = true.
*
*/
Configure::write('Cache.check', false);
/**
* Defines the default error type when using the log() function. Used for
* differentiating error logging and debugging. Currently PHP supports LOG_DEBUG.
*/
define('LOG_ERROR', 2);
/**
* The preferred session handling method. Valid values:
*
* 'php' Uses settings defined in your php.ini.
* 'cake' Saves session files in CakePHP's /tmp directory.
* 'database' Uses CakePHP's database sessions.
*
* To define a custom session handler, save it at /app/config/<name>.php.
* Set the value of 'Session.save' to <name> to utilize it in CakePHP.
*
* To use database sessions, run the app/config/schema/sessions.php schema using
* the cake shell command: cake schema create Sessions
*
*/
Configure::write('Session.save', 'database');
/**
* The model name to be used for the session model.
*
* 'Session.save' must be set to 'database' in order to utilize this constant.
*
* The model name set here should *not* be used elsewhere in your application.
*/
Configure::write('Session.model', 'Session');
/**
* The name of the table used to store CakePHP database sessions.
*
* 'Session.save' must be set to 'database' in order to utilize this constant.
*
* The table name set here should *not* include any table prefix defined elsewhere.
*
* Please note that if you set a value for Session.model (above), any value set for
* Session.table will be ignored.
*
* [Note: Session.table is deprecated as of CakePHP 1.3]
*/
Configure::write('Session.table', 'cake_sessions');
/**
* The DATABASE_CONFIG::$var to use for database session handling.
*
* 'Session.save' must be set to 'database' in order to utilize this constant.
*/
Configure::write('Session.database', 'default');
/**
* The name of CakePHP's session cookie.
*
* Note the guidelines for Session names states: "The session name references
* the session id in cookies and URLs. It should contain only alphanumeric
* characters."
* #link http://php.net/session_name
*/
Configure::write('Session.cookie', 'CAKEPHP');
/**
* Session time out time (in seconds).
* Actual value depends on 'Security.level' setting.
*/
Configure::write('Session.timeout', '120');
/**
* If set to false, sessions are not automatically started.
*/
Configure::write('Session.start', true);
/**
* When set to false, HTTP_USER_AGENT will not be checked
* in the session. You might want to set the value to false, when dealing with
* older versions of IE, Chrome Frame or certain web-browsing devices and AJAX
*/
Configure::write('Session.checkAgent', true);
/**
* The level of CakePHP security. The session timeout time defined
* in 'Session.timeout' is multiplied according to the settings here.
* Valid values:
*
* 'high' Session timeout in 'Session.timeout' x 10
* 'medium' Session timeout in 'Session.timeout' x 100
* 'low' Session timeout in 'Session.timeout' x 300
*
* CakePHP session IDs are also regenerated between requests if
* 'Security.level' is set to 'high'.
*/
Configure::write('Security.level', 'low');
/**
* A random string used in security hashing methods.
*/
Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
/**
* A random numeric string (digits only) used to encrypt/decrypt strings.
*/
Configure::write('Security.cipherSeed', '76859309657453542496749683645');
/**
* Apply timestamps with the last modified time to static assets (js, css, images).
* Will append a querystring parameter containing the time the file was modified. This is
* useful for invalidating browser caches.
*
* Set to `true` to apply timestamps, when debug = 0, or set to 'force' to always enable
* timestamping.
*/
//Configure::write('Asset.timestamp', true);
/**
* Compress CSS output by removing comments, whitespace, repeating tags, etc.
* This requires a/var/cache directory to be writable by the web server for caching.
* and /vendors/csspp/csspp.php
*
* To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use HtmlHelper::css().
*/
//Configure::write('Asset.filter.css', 'css.php');
/**
* Plug in your own custom JavaScript compressor by dropping a script in your webroot to handle the
* output, and setting the config below to the name of the script.
*
* To use, prefix your JavaScript link URLs with '/cjs/' instead of '/js/' or use JavaScriptHelper::link().
*/
//Configure::write('Asset.filter.js', 'custom_javascript_output_filter.php');
/**
* The classname and database used in CakePHP's
* access control lists.
*/
Configure::write('Acl.classname', 'DbAcl');
Configure::write('Acl.database', 'default');
/**
* If you are on PHP 5.3 uncomment this line and correct your server timezone
* to fix the date & time related errors.
*/
//date_default_timezone_set('UTC');
/**
*
* Cache Engine Configuration
* Default settings provided below
*
* File storage engine.
*
* Cache::config('default', array(
* 'engine' => 'File', //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'path' => CACHE, //[optional] use system tmp directory - remember to use absolute path
* 'prefix' => 'cake_', //[optional] prefix every cache file with this string
* 'lock' => false, //[optional] use file locking
* 'serialize' => true, [optional]
* ));
*
*
* APC (http://pecl.php.net/package/APC)
*
* Cache::config('default', array(
* 'engine' => 'Apc', //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
* ));
*
* Xcache (http://xcache.lighttpd.net/)
*
* Cache::config('default', array(
* 'engine' => 'Xcache', //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
* 'user' => 'user', //user from xcache.admin.user settings
* 'password' => 'password', //plaintext password (xcache.admin.pass)
* ));
*
*
* Memcache (http://www.danga.com/memcached/)
*
* Cache::config('default', array(
* 'engine' => 'Memcache', //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
* 'servers' => array(
* '127.0.0.1:11211' // localhost, default port 11211
* ), //[optional]
* 'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory)
* ));
*
*/
Cache::config('default', array('engine' => 'File'));
/**
* This is the URL at which your working copy
* is accessed -- no trailing forward slash
*/
define('BIRT_REPORT_BASE_URL', '');
/**
* This is the directory to which BIRT has
* permission to write files during graphing
*/
define('BIRT_REPORT_WRITABLE_IMAGE_DIR', '');
Apache crash:
Problem signature:
Problem Event Name: APPCRASH
Application Name: httpd.exe
Application Version: 2.2.11.0
Application Timestamp: 493f5d44
Fault Module Name: php5ts.dll
Fault Module Version: 5.2.9.9
Fault Module Timestamp: 49a56925
Exception Code: c00000fd
Exception Offset: 001a049d
OS Version: 6.1.7601.2.1.0.768.3
Locale ID: 1033
Additional Information 1: 8278
Additional Information 2: 82782538381a8681201b9137311ac754
Additional Information 3: 9f8d
Additional Information 4: 9f8d09670f894d997bbbca5236befa87
Apache error.log:
[Fri Apr 19 10:52:01 2013] [notice] Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9 configured -- resuming normal operations
[Fri Apr 19 10:52:01 2013] [notice] Server built: Dec 10 2008 00:10:06
[Fri Apr 19 10:52:01 2013] [notice] Parent: Created child process 7024
[Fri Apr 19 10:52:02 2013] [notice] Digest: generating secret for digest authentication ...
[Fri Apr 19 10:52:02 2013] [notice] Digest: done
[Fri Apr 19 10:52:03 2013] [notice] Child 7024: Child process is running
[Fri Apr 19 10:52:03 2013] [notice] Child 7024: Acquired the start mutex.
[Fri Apr 19 10:52:03 2013] [notice] Child 7024: Starting 250 worker threads.
[Fri Apr 19 10:52:03 2013] [notice] Child 7024: Starting thread to listen on port 443.
[Fri Apr 19 10:52:03 2013] [notice] Child 7024: Starting thread to listen on port 80.
I've found a workaround that allows the database version of sessions to work. It is not a fix, but it will probably work for my situation, although the real fix would still be preferred.
The work around is to turn the agent check off:
Configure::write('Session.checkAgent', false);

Categories