SoliDry / api-generator

PHP-code generator for Laravel framework, with complete support of JSON-API data format

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MigrationTrait creates faulty php code with numbers without min/max

meneken17 opened this issue · comments

Describe the bug

To Reproduce

  1. .yaml file contains:
    LocationAttributes:
      type: object
      properties:
        name: Name
        lat:
          type: number
          format: float
        lon:
          type: number
          format: float
    Location:
      type: object
      properties:
        type: Type
        id: ID
        attributes: LocationAttributes
  1. generate api
  2. migrate

This will create ..._create_location_table.php

     8|     public function up() 
     9|     {
    10|         Schema::create('location', function(Blueprint $table) {
    11|             $table->bigIncrements('id');
  > 12|             $table->float('lat', array, array);
    13|             $table->float('lon', array, array);
    14|             $table->timestamps();
    15|         });
    16|     }

Which will throw syntax error, unexpected ',', expecting '(' because array expects arguments.

This is caused by MigrationTraits.php line 124/125:

$max = empty($attrVal[ApiInterface::RAML_INTEGER_MAX]) ? PhpInterface::PHP_TYPES_ARRAY : $attrVal[ApiInterface::RAML_INTEGER_MAX];
$min = empty($attrVal[ApiInterface::RAML_INTEGER_MIN]) ? PhpInterface::PHP_TYPES_ARRAY : $attrVal[ApiInterface::RAML_INTEGER_MIN];

I am not quite sure what value would make sense here but array apperantly not.

Hi, thank u for exploring this bug and detailed description, I'll try to fix it right-away.

Added default values for double/float types.