forked from cebe/yii2-openapi
    
        
        - 
                Notifications
    You must be signed in to change notification settings 
- Fork 1
Properties that are marked as readOnly are not read only #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            cebe
  merged 10 commits into
  master
from
78-properties-that-are-marked-as-readonly-are-not-read-only
  
      
      
   
  May 22, 2025 
      
    
  
     Merged
                    Changes from 17 commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      0df2645
              
                Fix merge conflict
              
              
                SOHELAHMED7 1aa99e2
              
                Fix merge conflict 2
              
              
                SOHELAHMED7 709018b
              
                Fix merge conflict 3
              
              
                SOHELAHMED7 3fb5f3d
              
                Merge branch 'master' of github.com:php-openapi/yii2-openapi into 78-…
              
              
                SOHELAHMED7 4c79609
              
                Fix conflict
              
              
                SOHELAHMED7 1b8962f
              
                Merge branch '79-response-status-codes-are-not-the-codes-defined-in-s…
              
              
                SOHELAHMED7 ea09e68
              
                Merge branch '96-component-schema-should-be-optional' of github.com:p…
              
              
                SOHELAHMED7 cd3d9af
              
                Update src/lib/generators/ControllersGenerator.php
              
              
                cebe b4172bd
              
                Merge branch 'master' of github.com:php-openapi/yii2-openapi into 78-…
              
              
                SOHELAHMED7 0351ab5
              
                Merge branch '78-properties-that-are-marked-as-readonly-are-not-read-…
              
              
                SOHELAHMED7 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            13 changes: 13 additions & 0 deletions
          
          13 
        
  tests/specs/issue_fix/78_properties_that_are_marked_as_readonly_are_not_read_only/index.php
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|  | ||
| return [ | ||
| 'openApiPath' => '@specs/issue_fix/78_properties_that_are_marked_as_readonly_are_not_read_only/index.yaml', | ||
| 'generateUrls' => false, | ||
| 'generateModels' => true, | ||
| 'excludeModels' => [ | ||
| 'Error', | ||
| ], | ||
| 'generateControllers' => false, | ||
| 'generateMigrations' => false, | ||
| 'generateModelFaker' => true, // `generateModels` must be `true` in order to use `generateModelFaker` as `true` | ||
| ]; | 
        
          
          
            24 changes: 24 additions & 0 deletions
          
          24 
        
  tests/specs/issue_fix/78_properties_that_are_marked_as_readonly_are_not_read_only/index.yaml
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| openapi: 3.0.3 | ||
|  | ||
| info: | ||
| title: '#78' | ||
| version: 1.0.0 | ||
|  | ||
| paths: | ||
| /: | ||
| get: | ||
| responses: | ||
| '200': | ||
| description: The Response | ||
|  | ||
| components: | ||
| schemas: | ||
| Payment: | ||
| properties: | ||
| id: | ||
| type: integer | ||
| amount: | ||
| type: integer | ||
| readOnly: true | ||
| currency: | ||
| type: string | 
        
          
          
            144 changes: 144 additions & 0 deletions
          
          144 
        
  ..._properties_that_are_marked_as_readonly_are_not_read_only/mysql/models/BaseModelFaker.php
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| <?php | ||
|  | ||
| namespace app\models; | ||
|  | ||
| use Faker\Factory as FakerFactory; | ||
| use Faker\Generator; | ||
| use Faker\UniqueGenerator; | ||
|  | ||
| /** | ||
| * Base fake data generator | ||
| */ | ||
| abstract class BaseModelFaker | ||
| { | ||
| /** | ||
| * @var Generator | ||
| */ | ||
| protected $faker; | ||
| /** | ||
| * @var UniqueGenerator | ||
| */ | ||
| protected $uniqueFaker; | ||
|  | ||
| public function __construct() | ||
| { | ||
| $this->faker = FakerFactory::create(str_replace('-', '_', \Yii::$app->language)); | ||
| $this->uniqueFaker = new UniqueGenerator($this->faker); | ||
| } | ||
|  | ||
| abstract public function generateModel($attributes = []); | ||
|  | ||
| public function getFaker():Generator | ||
| { | ||
| return $this->faker; | ||
| } | ||
|  | ||
| public function getUniqueFaker():UniqueGenerator | ||
| { | ||
| return $this->uniqueFaker; | ||
| } | ||
|  | ||
| public function setFaker(Generator $faker):void | ||
| { | ||
| $this->faker = $faker; | ||
| } | ||
|  | ||
| public function setUniqueFaker(UniqueGenerator $faker):void | ||
| { | ||
| $this->uniqueFaker = $faker; | ||
| } | ||
|  | ||
| /** | ||
| * Generate and return model | ||
| * @param array|callable $attributes | ||
| * @param UniqueGenerator|null $uniqueFaker | ||
| * @return \yii\db\ActiveRecord | ||
| * @example MyFaker::makeOne(['user_id' => 1, 'title' => 'foo']); | ||
| * @example MyFaker::makeOne( function($model, $faker) { | ||
| * $model->scenario = 'create'; | ||
| * $model->setAttributes(['user_id' => 1, 'title' => $faker->sentence]); | ||
| * return $model; | ||
| * }); | ||
| */ | ||
| public static function makeOne($attributes = [], ?UniqueGenerator $uniqueFaker = null) | ||
| { | ||
| $fakeBuilder = new static(); | ||
| if ($uniqueFaker !== null) { | ||
| $fakeBuilder->setUniqueFaker($uniqueFaker); | ||
| } | ||
| $model = $fakeBuilder->generateModel($attributes); | ||
| return $model; | ||
| } | ||
|  | ||
| /** | ||
| * Generate, save and return model | ||
| * @param array|callable $attributes | ||
| * @param UniqueGenerator|null $uniqueFaker | ||
| * @return \yii\db\ActiveRecord | ||
| * @example MyFaker::saveOne(['user_id' => 1, 'title' => 'foo']); | ||
| * @example MyFaker::saveOne( function($model, $faker) { | ||
| * $model->scenario = 'create'; | ||
| * $model->setAttributes(['user_id' => 1, 'title' => $faker->sentence]); | ||
| * return $model; | ||
| * }); | ||
| */ | ||
| public static function saveOne($attributes = [], ?UniqueGenerator $uniqueFaker = null) | ||
| { | ||
| $model = static::makeOne($attributes, $uniqueFaker); | ||
| $model->save(); | ||
| return $model; | ||
| } | ||
|  | ||
| /** | ||
| * Generate and return multiple models | ||
| * @param int $number | ||
| * @param array|callable $commonAttributes | ||
| * @return \yii\db\ActiveRecord[]|array | ||
| * @example TaskFaker::make(5, ['project_id'=>1, 'user_id' => 2]); | ||
| * @example TaskFaker::make(5, function($model, $faker, $uniqueFaker) { | ||
| * $model->setAttributes(['name' => $uniqueFaker->username, 'state'=>$faker->boolean(20)]); | ||
| * return $model; | ||
| * }); | ||
| */ | ||
| public static function make(int $number, $commonAttributes = [], ?UniqueGenerator $uniqueFaker = null):array | ||
| { | ||
| if ($number < 1) { | ||
| return []; | ||
| } | ||
| $fakeBuilder = new static(); | ||
| if ($uniqueFaker !== null) { | ||
| $fakeBuilder->setUniqueFaker($uniqueFaker); | ||
| } | ||
| return array_map(function () use ($commonAttributes, $fakeBuilder) { | ||
| $model = $fakeBuilder->generateModel($commonAttributes); | ||
| return $model; | ||
| }, range(0, $number -1)); | ||
| } | ||
|  | ||
| /** | ||
| * Generate, save and return multiple models | ||
| * @param int $number | ||
| * @param array|callable $commonAttributes | ||
| * @return \yii\db\ActiveRecord[]|array | ||
| * @example TaskFaker::save(5, ['project_id'=>1, 'user_id' => 2]); | ||
| * @example TaskFaker::save(5, function($model, $faker, $uniqueFaker) { | ||
| * $model->setAttributes(['name' => $uniqueFaker->username, 'state'=>$faker->boolean(20)]); | ||
| * return $model; | ||
| * }); | ||
| */ | ||
| public static function save(int $number, $commonAttributes = [], ?UniqueGenerator $uniqueFaker = null):array | ||
| { | ||
| if ($number < 1) { | ||
| return []; | ||
| } | ||
| $fakeBuilder = new static(); | ||
| if ($uniqueFaker !== null) { | ||
| $fakeBuilder->setUniqueFaker($uniqueFaker); | ||
| } | ||
| return array_map(function () use ($commonAttributes, $fakeBuilder) { | ||
| $model = $fakeBuilder->generateModel($commonAttributes); | ||
| $model->save(); | ||
| return $model; | ||
| }, range(0, $number -1)); | ||
| } | ||
| } | 
        
          
          
            10 changes: 10 additions & 0 deletions
          
          10 
        
  ..._fix/78_properties_that_are_marked_as_readonly_are_not_read_only/mysql/models/Payment.php
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|  | ||
| namespace app\models; | ||
|  | ||
| class Payment extends \app\models\base\Payment | ||
| { | ||
|  | ||
|  | ||
| } | ||
|  | 
        
          
          
            42 changes: 42 additions & 0 deletions
          
          42 
        
  ...78_properties_that_are_marked_as_readonly_are_not_read_only/mysql/models/PaymentFaker.php
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
| namespace app\models; | ||
|  | ||
| use Faker\UniqueGenerator; | ||
|  | ||
| /** | ||
| * Fake data generator for Payment | ||
| * @method static Payment makeOne($attributes = [], ?UniqueGenerator $uniqueFaker = null); | ||
| * @method static Payment saveOne($attributes = [], ?UniqueGenerator $uniqueFaker = null); | ||
| * @method static Payment[] make(int $number, $commonAttributes = [], ?UniqueGenerator $uniqueFaker = null) | ||
| * @method static Payment[] save(int $number, $commonAttributes = [], ?UniqueGenerator $uniqueFaker = null) | ||
| */ | ||
| class PaymentFaker extends BaseModelFaker | ||
| { | ||
|  | ||
| /** | ||
| * @param array|callable $attributes | ||
| * @return Payment|\yii\db\ActiveRecord | ||
| * @example | ||
| * $model = (new PostFaker())->generateModels(['author_id' => 1]); | ||
| * $model = (new PostFaker())->generateModels(function($model, $faker, $uniqueFaker) { | ||
| * $model->scenario = 'create'; | ||
| * $model->author_id = 1; | ||
| * return $model; | ||
| * }); | ||
| **/ | ||
| public function generateModel($attributes = []) | ||
| { | ||
| $faker = $this->faker; | ||
| $uniqueFaker = $this->uniqueFaker; | ||
| $model = new Payment(); | ||
| //$model->id = $uniqueFaker->numberBetween(0, 1000000); | ||
| $model->amount = $faker->numberBetween(0, 1000000); | ||
| $model->currency = $faker->currencyCode; | ||
| if (!is_callable($attributes)) { | ||
| $model->setAttributes($attributes, false); | ||
| } else { | ||
| $model = $attributes($model, $faker, $uniqueFaker); | ||
| } | ||
| return $model; | ||
| } | ||
| } | 
        
          
          
            31 changes: 31 additions & 0 deletions
          
          31 
        
  ...78_properties_that_are_marked_as_readonly_are_not_read_only/mysql/models/base/Payment.php
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?php | ||
|  | ||
| /** | ||
| * This file is generated by Gii, do not change manually! | ||
| */ | ||
|  | ||
| namespace app\models\base; | ||
|  | ||
| /** | ||
| * This is the model class for table "payments". | ||
| * | ||
| * @property int $id | ||
| * @property int $amount | ||
| * @property string $currency | ||
| * | ||
| */ | ||
| abstract class Payment extends \yii\db\ActiveRecord | ||
| { | ||
| public static function tableName() | ||
| { | ||
| return '{{%payments}}'; | ||
| } | ||
|  | ||
| public function rules() | ||
| { | ||
| return [ | ||
| 'trim' => [['currency'], 'trim'], | ||
| 'currency_string' => [['currency'], 'string'], | ||
| ]; | ||
| } | ||
| } | 
        
          
          
            13 changes: 13 additions & 0 deletions
          
          13 
        
  tests/specs/issue_fix/79_response_status_codes_are_not_the_codes_defined_in_spec/index.php
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|  | ||
| return [ | ||
| 'openApiPath' => '@specs/issue_fix/79_response_status_codes_are_not_the_codes_defined_in_spec/index.yml', | ||
| 'generateUrls' => false, | ||
| 'generateModels' => false, | ||
| 'excludeModels' => [ | ||
| 'Error', | ||
| ], | ||
| 'generateControllers' => true, | ||
| 'generateMigrations' => false, | ||
| 'generateModelFaker' => false, | ||
| ]; | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.