I am trying to send an array using swagger. But when I check the array in inspect mode, I notice that the array being send is just a string and is not an array
/**
* #OA\Post(
* path="/api/update-landing-page",
* summary="Update Landing Page",
* description="Update Landing Page",
* tags={"Landing Page Backend"},
* security={{"bearer": {} }},
* #OA\RequestBody(
* required=true,
* #OA\MediaType(
* mediaType="multipart/form-data",
* #OA\Schema(
* required={"businesses","image"},
* #OA\Property(
* property="businesses",
* description="Business ID",
* type="array",
* #OA\Items(type="string", format="id"),
* ),
* #OA\Property(property="image", type="string", format="binary")
* )
* )
* ),
* #OA\Response(
* response=200,
* description="",
* #OA\MediaType(
* mediaType="application/json",
* )
* )
* )
*/
I want to have an array of business IDs. Which look something like this
businesses: [1,2,3].
But When I click in inspect mode, I notice it turns into a string
How do I make it turn into an array?
Thanks for taking you time and appreciate it.
I managed to solve this problem with:
#OA\Property(
property="businesses[]",
description="Business ID",
type="array",
collectionFormat="multi",
#OA\Items(type="string", format="id"),
),
Not sure whether this will help others, but this is what works for me.
Related
I use Laravel + Swagger PHP. In one of my services, I handle parameters like this :
$params = [
'addressChild' => [
'address' => ' ... ',
'city' => ' ... ',
],
'addressParent' => [
'address' => ' ... ',
'city' => ' ... ',
],
];
I am trying to describe this schema in Swagger Annotations, using OpenApi 3 :
/**
* #OA\Post(
* path="/entity/{entity}/addresses",
* #OA\Response(
* response=200,
* #OA\JsonContent()
* ),
* #OA\RequestBody(
* description="Addresses to store",
* required=true,
* #OA\JsonContent(
* type="object",
* #OA\Property()
* ),
* ),
* )
*
*/
public function update(Request $request)
{
// ...
}
I tried many things like :
#OA\JsonContent(
type="object",
#OA\Property(name="addressKid", ref="#/components/schemas/ParkingAddressRequest") // error
),
My address data is described in ref="#/components/schemas/ParkingAddressRequest" schema, how can I set it as an array in RequestBody ?
If I understood your problem, you could do it like this
/**
* #OA\Post(
* path="/entity/{entity}/addresses",
* #OA\Response(
* response=200,
* #OA\JsonContent()
* ),
* #OA\RequestBody(
* description="Addresses to store",
* required=true,
* #OA\JsonContent(
* type="array",
* #OA\Items(ref="#/components/schemas/ParkingAddressRequest")
* ),
* ),
* )
*
*/
I have a Google Spreadsheets formula like this with two named range: RangeA and RangeB.
=(1+VLOOKUP($A2,Test!RangeA,2,0)) * VLOOKUP($A2,Test!RangeA,3,0)
+ if(B2>=11,(index(Test!RangeB,1,2) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(index(Test!RangeB,1,1)-1)) * vlookup($A2,Test!RangeA,3,0),0)
+ if(B2>=21,(index(Test!RangeB,2,2) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(index(Test!RangeB,2,1)-1)) * vlookup($A2,Test!RangeA,3,0),0)
+ if(B2>=41,(index(Test!RangeB,3,2) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(index(Test!RangeB,3,1)-1)) * vlookup($A2,Test!RangeA,3,0),0)
+ if(B2>=61,(index(Test!RangeB,4,2) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(index(Test!RangeB,4,1)-1)) * vlookup($A2,Test!RangeA,3,0),0)
+ if(B2>=81,(index(Test!RangeB,5,2) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(index(Test!RangeB,5,1)-1)) * vlookup($A2,Test!RangeA,3,0),0)
https://docs.google.com/spreadsheets/d/1_4Xc8PMXjUVuI2SXY3QgkqrYQn3xc922bYJjH0KHX2Q/edit?usp=sharing
The problem is: it contains many long if (it is much longer than the example above) which I think could be shortened since it increases the index 1 row per time. Please help.
Replace the INDEX with:
vlookup(row(indirect("1:"&match(B2,index(Test!RangeB,0,1)))),{row(Test!RangeB)-min(row(Test!RangeB))+1,Test!RangeB},3,false)
Keep the first IF and get rid of the rest:
=(1+VLOOKUP($A2,Test!RangeA,2,0)) * VLOOKUP($A2,Test!RangeA,3,0)
+ if(B2>=11,sumproduct((vlookup(row(indirect("1:"&match(B2,index(Test!RangeB,0,1)))),{row(Test!RangeB)-min(row(Test!RangeB))+1,Test!RangeB},3,false) - 1) * ((1+vlookup($A2,Test!RangeA,2,0))^(vlookup(row(indirect("1:"&match(B2,index(Test!RangeB,0,1)))),{row(Test!RangeB)-min(row(Test!RangeB))+1,Test!RangeB},2,false)-1)) * vlookup($A2,Test!RangeA,3,0)),0)
The problem is that I need the documentation to show that it is possible to transfer the field colums in the form of an array and in it the following fields (name, description, created_at, updated_at, author). json is successfully generated but in the swagger-editor documentation it is not visible these fields
/**
* #SWG\Get(path="/articles",
* tags={"Article"},
* summary="Get all Articles",
* description="Show list of Articles",
* operationId="all",
* produces={"application/json"},
* #SWG\Parameter(
* name="columns",
* in="query",
* description="get specific columns",
* required=false,
* type="array",
* collectionFormat="multi",
* #SWG\Items(
* type="string",
* #SWG\Property(property="name", type="string"),
* #SWG\Property(property="description", type="string"),
* #SWG\Property(property="author", type="string"),
* #SWG\Property(property="created_at", type="string"),
* #SWG\Property(property="updated_at)", type="string")
* )
* ),
* #SWG\Response(response="200"),
* #SWG\Response(response=500)
* ),
* )
*/
Hi guys I tried to eliminate this error that persists when I generate the swagger.json, the error says:
[WARN] [Syntax Error] Expected Value, got '#' in
\App\Http\Controllers... and in my code, OHH iM WORKING WITH LUMEN.
/**
* #SWG\Put(
* path="/v1/resource/{id1}/rsc/{id2}",
* summary="Update ...",
* operationId="update",
* tags={"Update"},
*
*
* #SWG\Response(response=200, description="Json [client] "),
* #SWG\Response(response=404, description="Recurso no encontrado"),
* #SWG\Response(response=500, description="[error] Error interno del servidor"),
* #SWG\Parameter(
* name="id1",
* in="path",
* description="Id1.",
* required=true,
* type="integer"
* ),
* #SWG\Parameter(
* name="id2",
* in="path",
* description="Id2",
* required=true,
* type="integer"
* ),
* #SWG\Parameter(
* name="JSON update body",
* in="body",
* description="Request.",
* required=true,
* #SWG\Schema(type="array",#Model(type=vendor\LibModel\DAO\src\Model\Hospital))
* )
* )
*/
public function update($id1,$id2, Request $request){...}
When I check the json does not generate the definitions -> "definitions": {}.
My model defined it in the following way, I do not know if the problem is that my model is under a different namespace because it is defined as a vendor or something declarative that I lack:
/**
* Class Hospital
*
*
* #SWG\Definition(
* definition="Hospital"
* )
*
*/
class Hospital extends Model
{
/**
* #SWG\Property(format="string")
* #var string
*/
protected $name;
/**
* #SWG\Property(format="string")
* #var string
*/
protected $email;
..and in my view of swagger m an ERROR appears ... I think it's because it does not load the values of the model, thanks to who can help me
The doctrine parser complains about #Model which is not part of swagger-php.
The swagger-php notation is:
* #SWG\Parameter(
* name="JSON update body",
* in="body",
* description="Request.",
* required=true,
* #SWG\Schema(
* type="array",
* #SWG\Items(ref="#/definitions/Hospital")
* )
* )
I've wan't to use NelmioApiDocBundle (which uses that #Model annotation) check their guides to see how to set that up.
I am having a little trouble generating my json file. Here is what I am trying to compiler that is giving me an error, some code has changed to protect my work:
/**
* #SWG\Post(
* path="/path", * summary="summary of post",
* #SWG\Response(
* response=100,description="Success" * ),
* #SWG\Parameter(
* name="parameters",
* description="parameters are passed",
* in="body",
* #SWG\Schema(
* type="object",
* required={
* "req1",
* "req2",
* "req3",
* },
* properties={
* "req1"={
* type="number",
* format="int64"
* },
* "req2"={
* type="string"
* },
* "req3"={
* type="string"
* },
* "param1"={
* type="string"
* },
* "param2"={
* type="number",
* format="int64"
* },
* "param3"={
* type="string"
* },
* "param4"={
* type="string"
* },
* "param5"={
* type="string"
* },
* "param6"={
* type="string"
* },
* "param7"={
* type="string"
* },
* "param8"={
* type="number",
* format="int64"
* },
* "param9"={
* type="string",
* format="date-time"
* },
* "param10"={
* type="string"
* },
* "p11"={
* type="string"
* },
* "p12"={
* type="number",
* format="int64"
* },
* "p13"={
* type="number",
* format="int64"
* },
* "p14"={
* type="string"
* },
* "p15"={
* type="string"
* },
* "p16"={
* type="string"
* },
* "p17"={
* type="string"
* }
* }
* )
* )
* )
*/
But I am getting this error:
[WARN] [Semantical Error] Couldn't find constant type, \Path->index_post() in /path/to/file.php on line 7.
Any help to resolve this issue would be great!
I am not sure, maybe problem in * after path="/path",
My swagger example
/**
* #SWG\Post(path="/v1/users",
* tags={"user"},
* summary="Create a user",
* description="This can only be done by the logged user.",
* operationId="createUser",
* produces={"application/xml", "application/json"},
There are two leftover * symbols in your definition.
You probably meant to add a newline before them?
path="/path", * <-- One line above #SWG\Response
description="Success" * ), <-- One line below #SWG\Response