Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

schema.yaml: requestBody has no effect #172

Closed
siggi-k opened this issue May 27, 2024 · 0 comments · Fixed by SOHELAHMED7/yii2-openapi#37
Closed

schema.yaml: requestBody has no effect #172

siggi-k opened this issue May 27, 2024 · 0 comments · Fixed by SOHELAHMED7/yii2-openapi#37
Labels
bug Something isn't working generator-feature Functionality missing from the generator

Comments

@siggi-k
Copy link
Contributor

siggi-k commented May 27, 2024

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

@cebe cebe added bug Something isn't working generator-feature Functionality missing from the generator labels May 27, 2024
SOHELAHMED7 added a commit to SOHELAHMED7/yii2-openapi that referenced this issue May 29, 2024
…s-no-effect

Draft: cebe#172 schema.yaml: requestBody has no effect
@cebe cebe closed this as completed in e42e3f2 Jun 4, 2024
cebe added a commit that referenced this issue Jun 4, 2024
| Fix Issue # | Fork PR # |
| ------ | ------ |
| #175 | SOHELAHMED7#36 |
| #172 | SOHELAHMED7#37 |
| #159  | SOHELAHMED7#39 |
| #158 | SOHELAHMED7#40 |
| #178 |
SOHELAHMED7#41 |
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working generator-feature Functionality missing from the generator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants