Added oneOf examples (#948)

Fixes #933
This commit is contained in:
Allan 2021-06-10 23:00:59 +02:00 committed by GitHub
parent 7ddbdb9e21
commit 4bb30fadce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 4 deletions

View File

@ -32,7 +32,7 @@ use OpenApi\Annotations as OA;
/**
* @OA\Post(
* path="/users",
* summary="Adds a new user",
* summary="Adds a new user - with oneOf examples",
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json",
@ -45,13 +45,41 @@ use OpenApi\Annotations as OA;
* property="name",
* type="string"
* ),
* example={"id": "a3fb6", "name": "Jessica Smith"}
* @OA\Property(
* property="phone",
* oneOf={
* @OA\Schema(type="string"),
* @OA\Schema(type="integer"),
* }
* ),
* example={"id": "a3fb6", "name": "Jessica Smith", "phone": 12345678}
* )
* )
* ),
* @OA\Response(
* response=200,
* description="OK"
* description="OK",
* @OA\JsonContent(
* oneOf={
* @OA\Schema(ref="#/components/schemas/Result"),
* @OA\Schema(type="boolean")
* }
* )
* )
* )
*/
/**
* @OA\Schema(
* schema="Result",
* title="Sample schema for using references",
* @OA\Property(
* property="status",
* type="string"
* ),
* @OA\Property(
* property="error",
* type="string"
* )
* )
*/

View File

@ -26,7 +26,7 @@ paths:
description: OK
/users:
post:
summary: 'Adds a new user'
summary: 'Adds a new user - with oneOf examples'
requestBody:
content:
application/json:
@ -36,10 +36,31 @@ paths:
type: string
name:
type: string
phone:
oneOf:
- type: string
- type: integer
type: object
example:
id: a3fb6
name: 'Jessica Smith'
phone: 12345678
responses:
'200':
description: OK
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Result'
- type: boolean
components:
schemas:
Result:
title: Sample schema for using references
type: object
properties:
status:
type: string
error:
type: string