swagception icon indicating copy to clipboard operation
swagception copied to clipboard

Validation does not work on schema with keyword $ref

Open floxiann opened this issue 7 years ago • 2 comments

Swagger

@SWG\Response(
 *         response="200",
 *         description="Response example",
 *         examples={
 *             "application/json": {
 *                 "result": {
 *                     "dealers": {
 *                         {
 *                             "id": 740011,
 *                             "name": "瀧dvarqudbfa 和xwacuweroo",
 *                             "phone": "08091616422",
 *                             "email": "[email protected]",
 *                         }
 *                     }
 *                 },
 *                 "status_result": "success"
 *             },
 *          },
 *          @SWG\Schema(ref="#/definitions/DealerList")
 *     ),
@SWG\Definition(
 *     definition="DealerList",
 *     type="object",
 *     required={"status_result"},
 *     @SWG\Property(property="dealers", type="array", @SWG\Items(ref="#/definitions/Dealer")),
 *     @SWG\Property(property="status_result", type="string", format="string")
 * )

$schema in Validator.php

class stdClass#558 (1) {
   public $$ref =>
   string(91) "http://..../swagger/v1.json#/definitions/DealerList"
}

Maybe $schema should be like this

class stdClass#829 (3) {
   public $definition => string(10) "DealerList"
   public $type => string(6) "object"
   public $required =>
      array(1) {
         [0] => string(13) "status_result"
      }
........
}

then validation works

floxiann avatar Jun 25 '18 12:06 floxiann

I don't have any $refs in my json, because I use:

$dereferencer = new \League\JsonReference\Dereferencer();
$dereferencer->setReferenceSerializer(new \League\JsonReference\ReferenceSerializer\InlineReferenceSerializer());
$schema = $dereferencer->dereference('file:///' . $unresolvedFile);

From https://github.com/thephpleague/json-reference which is now unmaintained, so I'll need to find a new one.

I will include a dereferencer in this library. Thank you for pointing this out.

mlambley avatar Jun 25 '18 23:06 mlambley

Thank you

floxiann avatar Jun 26 '18 05:06 floxiann