Skip to content

How to handle parameters dynamically? #1773

@caixingyue

Description

@caixingyue
{
  "name": "20240624010101",
  "export_type": "A",
  "filters": {
    "serial_no": "20250624152106683213"
  }
}

I want to dynamically define the key in filters based on the value of export_type. For example, if it is A, the filter can fill in serial_no, as shown in the example above. If it is B, serial_no cannot be filled in, but trade_no can be filled in.

I don't know how to write it in laravel. The closest thing I have is as follows, but there are problems with this result


#[OA\Property(property: 'name', description: 'Task Name', type: 'string', example: '20240624010101')]
#[OA\Property(property: 'export_type', description: 'The is export type', type: 'string', enum: ExportType::class, example: ExportType::TRADE_RECEIPT)]
#[OA\Property(property: 'filters', description: 'The is filters', type: 'object', discriminator: new OA\Discriminator(
        propertyName: 'export_type',
        mapping: [
            'TRADE_RECEIPT' => '#/components/schemas/TradeReceiptFilters',
            'TRANSFER_RECEIPT' => '#/components/schemas/TransferReceiptFilters',
            'FUND_FLOW_RECEIPT' => '#/components/schemas/FundFlowReceiptFilters',
        ]
    ), oneOf: [
            new OA\Schema(ref: '#/components/schemas/TradeReceiptFilters'),
            new OA\Schema(ref: '#/components/schemas/TransferReceiptFilters'),
            new OA\Schema(ref: '#/components/schemas/FundFlowReceiptFilters'),
        ]
    )]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions