Skip to content

Commit

Permalink
Add nullable scratch test
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Aug 30, 2023
1 parent 434cd0a commit e6ae89d
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/Fixtures/Scratch/Nullable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

namespace OpenApi\Tests\Fixtures\Scratch;

use OpenApi\Attributes as OAT;

#[OAT\Info(
title: 'Nullable',
version: '1.0'
)]
class Api
{
}

#[OAT\Schema(
type: 'string',
format: 'rfc3339-timestamp',
externalDocs: new OAT\ExternalDocumentation(
description: '**RFC3339** IETF',
url: 'https://tools.ietf.org/html/rfc3339'
),
example: '2023-08-02T07:06:46+03:30'
)]
class MyDateTime
{
}

#[OAT\Schema]
class Nullable
{
#[OAT\Property]
public ?string $firstname;

#[OAT\Property(nullable: true)]
public ?string $lastname;

#[OAT\Property]
public ?MyDateTime $birthdate;

#[OAT\Property(nullable: true)]
public MyDateTime $otherdate;

#[OAT\Property]
public MyDateTime|null $anotherdate;
}

#[OAT\Get(
path: '/api/endpoint',
description: 'An endpoint',
responses: [new OAT\Response(response: 200, description: 'OK')]
)]
class NullableEndpoint
{
}
44 changes: 44 additions & 0 deletions tests/Fixtures/Scratch/Nullable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
openapi: 3.0.0
info:
title: Nullable
version: '1.0'
paths:
/api/endpoint:
get:
description: 'An endpoint'
responses:
'200':
description: OK
components:
schemas:
MyDateTime:
type: string
format: rfc3339-timestamp
externalDocs:
description: '**RFC3339** IETF'
url: 'https://tools.ietf.org/html/rfc3339'
example: '2023-08-02T07:06:46+03:30'
Nullable:
properties:
firstname:
type: string
nullable: true
lastname:
type: string
nullable: true
birthdate:
nullable: true
oneOf:
-
$ref: '#/components/schemas/MyDateTime'
otherdate:
nullable: true
oneOf:
-
$ref: '#/components/schemas/MyDateTime'
anotherdate:
nullable: true
oneOf:
-
$ref: '#/components/schemas/MyDateTime'
type: object

0 comments on commit e6ae89d

Please sign in to comment.