Skip to content

Commit 949a32f

Browse files
committed
Fix cebe#175
1 parent 51875cb commit 949a32f

20 files changed

+678
-0
lines changed

src/lib/openapi/ResponseSchema.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ protected static function schemaNameByRef($schemaOrReference): ?string
4949
// if($schemaOrReference instanceof Reference){
5050
// $schemaOrReference->resolve();
5151
// }
52+
if (!$schemaOrReference instanceof Reference) { # https://github.com/cebe/yii2-openapi/issues/175
53+
return null;
54+
}
5255
$ref = $schemaOrReference->getJsonReference()->getJsonPointer()->getPointer();
5356
$name = strpos($ref, '/components/schemas/') === 0 ? substr($ref, 20) : null;
5457
return str_replace(JunctionSchemas::PREFIX, '', $name);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
return [
4+
'openApiPath' => '@specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.yaml',
5+
'generateUrls' => true,
6+
'generateModels' => true,
7+
'excludeModels' => [
8+
'Error',
9+
],
10+
'generateControllers' => true,
11+
'generateMigrations' => true,
12+
'generateModelFaker' => true, // `generateModels` must be `true` in orde to use `generateModelFaker` as `true`
13+
];
14+
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
openapi: 3.0.3
3+
4+
info:
5+
title: 'Proxy-Service'
6+
version: 1.0.0
7+
8+
components:
9+
10+
responses:
11+
12+
AccountExpanded:
13+
description: 'Returns one account by ID with additional information.'
14+
content:
15+
application/vnd.api+json:
16+
schema:
17+
type: object
18+
required:
19+
- status
20+
- Account
21+
properties:
22+
status:
23+
type: string
24+
enum:
25+
- valid
26+
- invalid
27+
Account:
28+
allOf:
29+
- $ref: '#/components/schemas/Account'
30+
- type: object
31+
properties:
32+
invoiceContact:
33+
$ref: "#/components/schemas/Contact"
34+
paymentMethod:
35+
$ref: "#/components/schemas/PaymentMethod"
36+
errors:
37+
type: object
38+
description: only exists if status = invalid
39+
40+
schemas:
41+
42+
Account:
43+
description: Account
44+
type: object
45+
required:
46+
- id
47+
- name
48+
properties:
49+
id:
50+
type: integer
51+
readOnly: true
52+
name:
53+
description: account name
54+
type: string
55+
maxLength: 128
56+
paymentMethodName:
57+
type: string
58+
59+
Contact:
60+
description: Contact
61+
type: object
62+
required:
63+
- id
64+
- account
65+
properties:
66+
id:
67+
type: integer
68+
readOnly: true
69+
account:
70+
$ref: '#/components/schemas/Account'
71+
active:
72+
type: boolean
73+
default: false
74+
nickname:
75+
type: string
76+
77+
PaymentMethod:
78+
type: object
79+
description: PaymentMethod
80+
x-indexes:
81+
- 'unique:name'
82+
required:
83+
- id
84+
- name
85+
properties:
86+
id:
87+
type: integer
88+
readOnly: true
89+
name:
90+
type: string
91+
example: Bank transfer within 14 days
92+
maxLength: 150
93+
x-faker: false
94+
95+
paths:
96+
97+
'/account/{id}':
98+
parameters:
99+
- name: Id
100+
in: path
101+
description: ID of Account
102+
required: true
103+
schema:
104+
type: integer
105+
106+
get:
107+
operationId: getAccount
108+
summary: Account information
109+
responses:
110+
'200':
111+
$ref: '#/components/responses/AccountExpanded'
112+
'404':
113+
description: Account with id = "\<account_id\>" was not found.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* OpenAPI UrlRules
4+
*
5+
* This file is auto generated.
6+
*/
7+
return [
8+
'GET account/<id>' => 'account/view',
9+
'account/<id>' => 'account/options',
10+
];
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace app\controllers;
4+
5+
class AccountController extends \app\controllers\base\AccountController
6+
{
7+
8+
public function checkAccess($action, $model = null, $params = [])
9+
{
10+
//TODO implement checkAccess
11+
}
12+
13+
public function actionView($id)
14+
{
15+
//TODO implement actionView
16+
}
17+
18+
19+
}
20+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace app\controllers\base;
4+
5+
abstract class AccountController extends \yii\rest\Controller
6+
{
7+
public function actions()
8+
{
9+
return [
10+
'options' => [
11+
'class' => \yii\rest\OptionsAction::class,
12+
],
13+
];
14+
}
15+
16+
/**
17+
* Checks the privilege of the current user.
18+
*
19+
* This method checks whether the current user has the privilege
20+
* to run the specified action against the specified data model.
21+
* If the user does not have access, a [[ForbiddenHttpException]] should be thrown.
22+
*
23+
* @param string $action the ID of the action to be executed
24+
* @param object $model the model to be accessed. If null, it means no specific model is being accessed.
25+
* @param array $params additional parameters
26+
* @throws \yii\web\ForbiddenHttpException if the user does not have access
27+
*/
28+
abstract public function checkAccess($action, $model = null, $params = []);
29+
30+
abstract public function actionView($id);
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* Table for Account
5+
*/
6+
class m200000_000000_create_table_accounts extends \yii\db\Migration
7+
{
8+
public function up()
9+
{
10+
$this->createTable('{{%accounts}}', [
11+
'id' => $this->primaryKey(),
12+
'name' => $this->string(128)->notNull(),
13+
'paymentMethodName' => $this->text()->null(),
14+
]);
15+
}
16+
17+
public function down()
18+
{
19+
$this->dropTable('{{%accounts}}');
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Table for Contact
5+
*/
6+
class m200000_000001_create_table_contacts extends \yii\db\Migration
7+
{
8+
public function up()
9+
{
10+
$this->createTable('{{%contacts}}', [
11+
'id' => $this->primaryKey(),
12+
'account_id' => $this->integer()->notNull(),
13+
'active' => $this->boolean()->null()->defaultValue(false),
14+
'nickname' => $this->text()->null(),
15+
]);
16+
$this->addForeignKey('fk_contacts_account_id_accounts_id', '{{%contacts}}', 'account_id', '{{%accounts}}', 'id');
17+
}
18+
19+
public function down()
20+
{
21+
$this->dropForeignKey('fk_contacts_account_id_accounts_id', '{{%contacts}}');
22+
$this->dropTable('{{%contacts}}');
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* Table for PaymentMethod
5+
*/
6+
class m200000_000002_create_table_payment_methods extends \yii\db\Migration
7+
{
8+
public function up()
9+
{
10+
$this->createTable('{{%payment_methods}}', [
11+
'id' => $this->primaryKey(),
12+
'name' => $this->string(150)->notNull(),
13+
]);
14+
$this->createIndex('payment_methods_name_key', '{{%payment_methods}}', 'name', true);
15+
}
16+
17+
public function down()
18+
{
19+
$this->dropIndex('payment_methods_name_key', '{{%payment_methods}}');
20+
$this->dropTable('{{%payment_methods}}');
21+
}
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
class Account extends \app\models\base\Account
6+
{
7+
8+
9+
}
10+

0 commit comments

Comments
 (0)