cebe / yii2-openapi

REST API application generator for Yii2, openapi 3.0 YAML -> Yii2
MIT License
129 stars 23 forks source link

Bug with "format: date-time" #161

Open siggi-k opened 9 months ago

siggi-k commented 9 months ago

Initial

schema.yaml

openapi: 3.0.3
# Edit this schema and start your project
# This is sample schema
# To generate code which is based on this schema
# run commands mentioned Development section in README.md file
info:
  title: 'Proxy-Service'
  description: ""
  version: 1.0.0
  contact:
    name: '...'
    email: you@example.com
servers:
  - url: 'http://localhost:9937'
    description: 'Local Dev API'
security:
  - BasicAuth: []
components:
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
  schemas:

    Subscription:
      type: object
      required:
        - id
      properties:
        id:
          type: integer
        start:
          type: string
          format: date-time
        end:
          type: string
          format: date-time
        createdAt:
          type: string
          format: date-time
          readOnly: True
        updatedAt:
          type: string
          format: date-time
          readOnly: true

Reproduction steps

./yii gii/api ./yii migrate

again

./yii gii/api

Expected No more migration

Result

<?php

/**
 * Table for Subscription
 */
class m240205_140005_change_table_subscriptions extends \yii\db\Migration
{
    public function up()
    {
        $this->alterColumn('{{%subscriptions}}', 'start', $this->timestamp()->null()->defaultValue(null));
        $this->alterColumn('{{%subscriptions}}', 'end', $this->timestamp()->null()->defaultValue(null));
        $this->alterColumn('{{%subscriptions}}', 'createdAt', $this->timestamp()->null()->defaultValue(null));
        $this->alterColumn('{{%subscriptions}}', 'updatedAt', $this->timestamp()->null()->defaultValue(null));
    }

    public function down()
    {
        $this->alterColumn('{{%subscriptions}}', 'updatedAt', $this->timestamp()->null()->defaultValue(null));
        $this->alterColumn('{{%subscriptions}}', 'createdAt', $this->timestamp()->null()->defaultValue(null));
        $this->alterColumn('{{%subscriptions}}', 'end', $this->timestamp()->null()->defaultValue(null));
        $this->alterColumn('{{%subscriptions}}', 'start', $this->timestamp()->null()->defaultValue(null));
    }
}
SOHELAHMED7 commented 6 months ago

I am not able to reproduce this issue.

I attempted to create failing test for PgSQL:

// above attempt yields this migration which is correct and expected
<?php

/**
 * Table for Subscription
 */
class m200000_000000_change_table_subscriptions extends \yii\db\Migration
{
    public function safeUp()
    {
        $this->addColumn('{{%subscriptions}}', 'updatedAt2', $this->timestamp()->null()->defaultValue(null));
    }

    public function safeDown()
    {
        $this->dropColumn('{{%subscriptions}}', 'updatedAt2');
    }
}

Please provide following details: