0

My method is POST, but it gets data by query parameters. I can't change the logic of the method to retrieve data by body. Is it possible to send a nested array in a query (not in http body, as it usually done in post queries) in this way:

@SWG\Parameter(
    name="find_data",
    in="query",
    type="array",
     required=true,
        SWG\Items(
            SWG\Property(property="service", type="integer", description="Client"),
            SWG\Property(property="tariff", type="integer", description="tariff"),
            SWG\Property(property="connection", type="integer", description="Connection")
        )
)?

I have done the following:

@SWG\Post(path="/tariff/get-by-data",
     tags={"Tariffs"},
     operationId="actionGetByData",
     summary="Find tariffs",
     @SWG\Parameter(
         name="type",
         in="query",
         type="string",
         required=true,
         description="Type of connect",
     ),
     @SWG\Parameter(
         name="find_data[0][service]",
         in="query",
         type="string",
         required=true,
         description="Client",
     ),
     @SWG\Parameter(
         name="find_data[0][tariff]",
         in="query",
         type="string",
         required=true,
         description="Tariff",
     ),
     @SWG\Parameter(
         name="find_data[0][connection]",
         in="query",
         type="string",
         required=true,
         description="Connection",
     ),
     @SWG\Response(
         response = 200,
         description = "Success",
         @SWG\Schema(
            @SWG\Property(property="id", type="integer", description="Id tariff")
         )
     )
)

but in swagger it doesn't look very nice, especially when trying to query in ui.

Also I tried make like here. I changed in="body" on in="query", but it gave out an error Failed to load API definition. Fetch errorInternal Server Error /api/docs/json-schema

2
  • 1
    OpenAPI Specification does not support arrays of objects in the query string. Commented Apr 12, 2023 at 16:32
  • I voted up for @Helen answer. You need to use OpenApi 3 instead of 2. Commented Apr 14, 2023 at 8:16

1 Answer 1

0

Found similar sample that you asking, can be helpful:

@OA\Parameter(
     name="body",
     in="query",
     required=false,
     explode=true,
     @OA\Schema(
          collectionFormat="multi",
          required={"product_id"},
          @OA\Property(property="product_id",  type="string",  ),
          @OA\Property(
                property="products",
                type="array",
                @OA\Items(
                      type="object",
                      format="query",
                      @OA\Property(property="name", type="string", ),
                      @OA\Property(property="category", type="string",),
                ),
           ),
     ),
)

So, the answer is:

@SWG\Parameter( -> @SWG\Schema( -> @SWG\Items( and you can add additional @SWG\items( if needed

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.