This repository was archived by the owner on Jun 4, 2024. It is now read-only.
This repository was archived by the owner on Jun 4, 2024. It is now read-only.
schema.yaml: requestBody has no effect #172
Description
PROBLEM
Prerequisite:
responses: '201': description: OK
requestBody does not create a \yii\rest\CreateAction, but only an abstract CreateAction.
GIVEN
schema.yaml
openapi: 3.0.3
info:
title: 'Proxy-Service'
version: 1.0.0
components:
requestBodies:
Account:
description: 'Create / update account'
required: true
content:
application/vnd.api+json:
schema:
type: object
properties:
data:
$ref: '#/components/schemas/Account'
responses:
Account:
description: 'Returns one account by ID.'
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/Account'
schemas:
Account:
description: Account
type: object
required:
- id
- name
properties:
id:
type: integer
readOnly: true
name:
description: account name
type: string
maxLength: 128
paths:
'/accounts':
post:
operationId: createAccount
summary: Create a account
description: Create account
requestBody:
$ref: '#/components/requestBodies/Account'
responses:
'201':
description: OK
'400':
description: BodyParams must be an array.
'422':
description: Validation error.
tags:
- Accounts
I have deliberately declared responses 201 as OK instead of Account Model, so that responses have no effect.
EXECUTE
./yii gii/api
EXPECTED
public function actions()
{
return [
+ 'create' => [
+ 'class' => \yii\rest\CreateAction::class,
+ 'modelClass' => \common\models\Account::class,
+ 'checkAccess' => [$this, 'checkAccess'],
+ ],
'view' => [
'class' => \yii\rest\ViewAction::class,
'modelClass' => \common\models\Account::class,
ACTUAL
abstract public function actionList();
+ abstract public function actionCreate();
+
}
P.S.
The expected change can also be achieved by entering a $ref instead of OK for responses 201.
Like here:
paths:
'/accounts':
post:
operationId: createAccount
summary: Create a account
description: Create account
requestBody:
$ref: '#/components/requestBodies/Account'
responses:
'201':
$ref: '#/components/responses/Account'
However, it must also work if you do not specify $ref as responses