SoliDry / api-generator

PHP-code generator for Laravel framework, with complete support of JSON-API data format
MIT License
327 stars 60 forks source link

MigrationTrait creates faulty php code with numbers without min/max #197

Closed meneken17 closed 4 years ago

meneken17 commented 4 years ago

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

2) generate api 3) 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.

arthurkushman commented 4 years ago

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

arthurkushman commented 4 years ago

Added default values for double/float types.