Luracast / Restler

Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and/or RESTful API
http://luracast.com/products/restler/
GNU Lesser General Public License v2.1
1.36k stars 315 forks source link

Warnings in swagger.json #635

Closed davidsneighbour closed 3 years ago

davidsneighbour commented 4 years ago

My restler explorer is only working, if I set error_reporting to 0 before loading one specific class (amongst many). If not, it throws two warnings, that do not say much in sense of what is going wrong. The code that is "creating" the warnings is the following method:

    /**
     * @url POST /create/
     *
     * @param array<array-key, mixed> $request_data
     *
     * @return string|false
     */
    public static function postCreate(array $request_data = [])
    {
        try {
            $tour = Tours2::post(
                array_merge($request_data, ['is_charter' => '1'])
            );

            return '/bookings/add/?tripID=' . $tour['id'];
        } catch (GetParameterMissing $eException) {
            Tracking::trackException($eException);
        } catch (Exception $eException) {
            Tracking::trackException($eException);
        }

        return false;
    }

The API method itself works as expected without thrown exceptions or warnings, only the Explorer refuses to load the methods. In swagger.json the following warnings come up (sorry image, i can't copy the warnings properly):

Selection_015

The resulting json after the warnings is properly formatted and has no errors.

index:146 is $oRestler->handle();

Where should I look for the error?

davidsneighbour commented 4 years ago

It get's weirder. If I suppress the warnings then the explorer expects string as parameter for POST:

Selection_016

Arul- commented 4 years ago

Can you try changing the comment as follows

@param array $request_data {@type associative}

Instead and try!

davidsneighbour commented 4 years ago

The error stays. (I deleted the cache directory too.) I wonder if there is some deeper issue that results in it trying to be a string, but receiving array... chaos :)

Using the 3.1.0 tag by the way.

davidsneighbour commented 4 years ago

the json created for this function is

        "/tours/charter/create": {
            "post": {
                "operationId": "charterCreateCreate",
                "tags": [
                    "tours"
                ],
                "parameters": [
                    {
                        "name": "charterCreateCreateModel",
                        "description": "request_data  \n",
                        "in": "body",
                        "required": false,
                        "schema": {
                            "$ref": "#/definitions/charterCreateCreateModel"
                        }
                    }
                ],
                "summary": " 🔓",
                "description": "",
                "responses": {
                    "200": {
                        "description": "Success",
                        "schema": {
                            "type": "string"
                        }
                    }
                }
            }
        }
Arul- commented 4 years ago

Noted

Arul- commented 3 years ago

Fixed in 8f038ef6bd75a7ea1fc2b5abe186bfb2cc1887b2 in V5 branch. The issue is because multiple return types are not supported in Explorer. Fix assumes the last one in the list as the type for Explorer's consideration

In your above example, it is boolean

Please test and let me know!

Arul- commented 3 years ago

Now available in 5.0.7