L5-Swagger icon indicating copy to clipboard operation
L5-Swagger copied to clipboard

Nested Example is not working for OAS 3

Open QuantumPixelForge opened this issue 4 years ago • 1 comments

  • L5-Swagger Version: 8.0.4
  • PHP Version: PHP 7.4.12
  • OS: macOS Catalina

Description:

Nested Example is not working. In documentation: https://swagger.io/docs/specification/2-0/adding-examples/ is written:

OpenAPI 2.0 example and examples keywords require inline examples and do not support $ref. The example values are displayed as is, so $ref would be displayed as an object property named $ref.

Referencing examples is supported in OpenAPI 3.0.

But swagger 8.0.4 is OAS 3, and i suppose it should work..

Steps To Reproduce:

/**
     *      @OA\Examples(
     *          summary="ClansResource",
     *          example = "ClansResource",
     *          value = {
     *              "id": 1,
     *              "name": "Superclan",
     *              "description": "Some clan rules and clan description",
     *              "type": "open",
     *              "icon": "icon123",
     *              "required_points": 1000,
     *              "clan_points": 35403,
     *              "owner": @OA\Examples( ref="#/components/examples/OwnerResource"),
     *              "created_at": "2021-05-11 12:02:02"
     *          },
     *      )
     */
/**
     *      @OA\Examples(
     *          summary="OwnerResource",
     *          example = "OwnerResource",
     *          value = {
     *              "device_id": "C7688FE2-0649-4166-9B54-298B8E629D61",
     *              "username" : "Alex"
     *          },
     *      )
     */

and generated output (http://localhost/clans/public/docs/api-docs.json):

...
"examples": {
            "ClansResource": {
                "summary": "ClansResource",
                "value": {
                    "id": 1,
                    "name": "Superclan",
                    "description": "Some clan rules and clan description",
                    "type": "open",
                    "icon": "icon123",
                    "required_points": 1000,
                    "clan_points": 35403,
                    "owner": {
                        "$ref": "#/components/examples/OwnerResource"
                    },
                    "created_at": "2021-05-11 12:02:02"
                }
            },
            "OwnerResource": {
                "summary": "OwnerResource",
                "value": {
                    "device_id": "C7688FE2-0649-4166-9B54-298B8E629D61",
                    "username": "Alex"
                }
            }
        }
...

And example json what I see in swagger UI:

{
  "id": 1,
  "name": "Superclan",
  "description": "Some clan rules and clan description",
  "type": "open",
  "icon": "icon123",
  "required_points": 1000,
  "clan_points": 35403,
  "owner": {
    "$ref": "#/components/examples/OwnerResource"
  },
  "created_at": "2021-05-11 12:02:02"
}

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

QuantumPixelForge avatar May 11 '21 09:05 QuantumPixelForge

+1

arifszn avatar Nov 05 '21 11:11 arifszn