cebe / yii2-openapi

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

Methods naming for non crud actions #144

Open mtangoo opened 1 year ago

mtangoo commented 1 year ago

I have this OA file (top parts removed). I want Payments to do many things. for example /payments/invoice for paying invoices or payments/cash for non-credit payments. These takes different objects and are obviously non crud. I cannot get the library to generate correct methods for me. For example for the file below it creates PaymentsController/actionCreateinvoice.

Is there a way of setting my own naming and disable treating everything as CRUD?

tags:
  - name: Payments
    description: Pay or receive payments for your products from different channels
    externalDocs:
      description: Find out more
      url: http://developer.adiuta.com/book/payments
paths:
  /payments/invoice/{invoice}:
    post:
      summary: Pay Invoice
      description: Pay for Invoice with given invoice number
      requestBody:
        description: Record new payment for an invoice
        content:
          application/json:
            schema:  
              $ref: '#/components/schemas/Payments'   
        required: true
      responses:
        '200':
          description: Successfully paid the invoice
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Success'   

components:
  schemas:
    Payments:
      required:
        - reference  
        - amount
        - currency
      properties:
        invoice_number:
          type: string
        amount:
          type: integer
          format: int64
        currency:
          type: string  

    Success:
      required:
        - success  
        - message
      properties:
        success:
          type: boolean
        message:
          type: string  

    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
mtangoo commented 1 year ago

Addition: I see it is spitting wrong names

/payments/invoice-payment produces actionCreateinvoicePayment instead of actionCreateInvoicePayment wrong capitalization

SOHELAHMED7 commented 1 year ago

At this moment, there is no way to do that.

Loosely similar to https://github.com/cebe/yii2-openapi/issues/84

Work-around is

class PaymentController ... 
{
    public function actionCreateinvoice($invoice)
    {
        return $this->runAction('invoice', ['invoice' => $invoice]);
    }

    public function actionInvoice($invoice)
    {
        // TODO implement
    }
}
mtangoo commented 1 year ago

I just fell back to classic API/Code crafting. hope to come back soon