PHP code example of wapmorgan / openapi-generator

1. Go to this page and download the library: Download wapmorgan/openapi-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wapmorgan / openapi-generator example snippets


   Route::get('/selector/lists', [\App\Http\Controllers\SelectorController::class, 'lists']);
   Route::post('/selector/select', [\App\Http\Controllers\SelectorController::class, 'select']);
   Route::get('/selector/goTo', [\App\Http\Controllers\SelectorController::class, 'goTo']);
   Route::get('/geo/detect', [\App\Http\Controllers\GeoController::class, 'detect']);
   Route::get('/geo/select', [\App\Http\Controllers\GeoController::class, 'select']);
   

   /**
   * Returns lists of filters
   * @param Request $request
   * @return ListsResponse
   */
   public function lists(Request $request) {
     return new ListsResponse([
         //            'persons' => range(1, 15),
         'persons' => array_keys(Menu::$personsList),
         'tastes' => Menu::$tastes,
         'meat' => Menu::$meat,
         'pizzas' => Menu::$pizzas,
     ]);
   }
   
   /**
   * Makes a selection of pizzas according to criteria
   * @param \App\Http\Requests\SelectPizzas $request
   * @return PizzaListItem[]
   */
   public function select(\App\Http\Requests\SelectPizzas $request) {
     $validated = $request->validated();
   
     return (new Selector())->select(
         $validated['city'], $validated['persons'],
         $validated['tastes'] ?? null, $validated['meat'] ?? null,
         $validated['vegetarian'] ?? false, $validated['maxPrice'] ?? null);
   }
   

   class SelectPizzas extends FormRequest {
        public function rules()
        { 
            // ...
            return array_merge([
               'city' => ['c'],
               'pizzas' => ['array', Rule::in(array_keys(Menu::$pizzas))],
            ], $tastes, $meat);
        } 
   }

   class ListsResponse extends BaseResponse {
        /** @var string[] */
        public $persons;
        /** @var string[] */
        public $tastes;
        /** @var string[] */
        public $meat;
        /** @var string[] */
        public $pizzas;
   }
   
   class PizzaListItem extends BaseResponse {
        public string $pizzeria;
        public string $id;
        public int $sizeId;
        public string $name;
        public float $size;
        public array $tastes;
        public array $meat;
        public float $price;
        public float $pizzaArea;
        public float $pizzaCmPrice;
        public string $thumbnail;
        public array $ingredients;
        public int $dough;
   }
   

$generator->changeSetting(DefaultGenerator::CHANGE_GET_TO_POST_FOR_COMPLEX_PARAMETERS, true);