File tree 11 files changed +236
-3
lines changed
examples/specs/polymorphism
11 files changed +236
-3
lines changed Original file line number Diff line number Diff line change
1
+ ## Polymorphism
2
+
3
+ Demonstrates the use of ` Discriminator `
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ class Controller
29
29
/**
30
30
* @OA\Get(
31
31
* path="/test",
32
+ * operationId="test",
32
33
* description="Get test",
33
34
* tags={"api"},
34
35
* @OA\Response(
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * @license Apache 2.0
5
+ */
6
+
7
+ namespace OpenApi \Examples \Specs \Polymorphism \Attributes ;
8
+
9
+ use OpenApi \Attributes as OAT ;
10
+
11
+ #[OAT \Schema(
12
+ schema: 'Responsible ' ,
13
+ oneOf: [
14
+ new OAT \Schema (ref: Fl::class),
15
+ new OAT \Schema (ref: Employee::class),
16
+ ],
17
+ discriminator: new OAT \Discriminator (
18
+ propertyName: 'type ' ,
19
+ mapping: [
20
+ 'fl ' => '#/components/schemas/FlResponsible ' ,
21
+ 'employee ' => '#/components/schemas/EmployeeResponsible ' ,
22
+ ]
23
+ )
24
+ )]
25
+ abstract class AbstractResponsible
26
+ {
27
+ protected const TYPE = null ;
28
+
29
+ #[OAT \Property(
30
+ nullable: false ,
31
+ enum: ['employee ' , 'assignee ' , 'fl ' ]
32
+ )]
33
+ protected string $ type ;
34
+
35
+ public function __construct ()
36
+ {
37
+ $ this ->type = static ::TYPE ;
38
+ }
39
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * @license Apache 2.0
5
+ */
6
+
7
+ namespace OpenApi \Examples \Specs \Polymorphism \Attributes ;
8
+
9
+ use OpenApi \Attributes as OAT ;
10
+
11
+ #[OAT \Info(
12
+ title: 'Polymorphism ' ,
13
+ description: 'Polymorphism example ' ,
14
+ version: '1 ' ,
15
+ contact: new OAT \Contact (
16
+ name: 'Swagger API Team '
17
+ )
18
+ )]
19
+ #[OAT \Tag(
20
+ name: 'api ' ,
21
+ description: 'API operations '
22
+ )]
23
+ #[OAT \Server(
24
+ url: 'https://example.localhost ' ,
25
+ description: 'API server '
26
+ )]
27
+ class Controller
28
+ {
29
+ #[OAT \Get(
30
+ path: '/test ' ,
31
+ operationId: 'test ' ,
32
+ description: 'Get test ' ,
33
+ tags: ['api ' ],
34
+ responses: [
35
+ new OAT \Response (
36
+ response: 200 ,
37
+ description: 'Polymorphism ' ,
38
+ content: new OAT \JsonContent (
39
+ ref: Request::class
40
+ )
41
+ ),
42
+ ]
43
+ )]
44
+ public function getProduct ($ id )
45
+ {
46
+ }
47
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * @license Apache 2.0
5
+ */
6
+
7
+ namespace OpenApi \Examples \Specs \Polymorphism \Attributes ;
8
+
9
+ use OpenApi \Attributes as OAT ;
10
+
11
+ #[OAT \Schema(
12
+ schema: 'EmployeeResponsible '
13
+ )]
14
+ final class Employee extends AbstractResponsible
15
+ {
16
+ #[OAT \Property(
17
+ property: 'type '
18
+ )]
19
+ protected const TYPE = 'Virtual ' ;
20
+
21
+ #[OAT \Property(
22
+ nullable: false
23
+ )]
24
+ public string $ property2 ;
25
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * @license Apache 2.0
5
+ */
6
+
7
+ namespace OpenApi \Examples \Specs \Polymorphism \Attributes ;
8
+
9
+ use OpenApi \Attributes as OAT ;
10
+
11
+ #[OAT \Schema(
12
+ schema: 'FlResponsible '
13
+ )]
14
+ final class Fl extends AbstractResponsible
15
+ {
16
+ public const TYPE = 'fl ' ;
17
+
18
+ #[OAT \Property()]
19
+ public ?string $ property3 ;
20
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * @license Apache 2.0
5
+ */
6
+
7
+ namespace OpenApi \Examples \Specs \Polymorphism \Attributes ;
8
+
9
+ use OpenApi \Attributes as OAT ;
10
+
11
+ #[OAT \Schema()]
12
+ final class Request
13
+ {
14
+ protected const TYPE = 'employee ' ;
15
+
16
+ #[OAT \Property()]
17
+ public AbstractResponsible $ payload ;
18
+ }
Original file line number Diff line number Diff line change 15
15
tags :
16
16
- api
17
17
description : ' Get test'
18
- operationId : c2ce98e75eedefc189265e365c6e54de
18
+ operationId : test
19
19
responses :
20
20
' 200 ' :
21
21
description : Polymorphism
Original file line number Diff line number Diff line change 15
15
tags :
16
16
- api
17
17
description : ' Get test'
18
- operationId : c2ce98e75eedefc189265e365c6e54de
18
+ operationId : test
19
19
responses :
20
20
' 200 ' :
21
21
description : Polymorphism
Original file line number Diff line number Diff line change @@ -299,3 +299,83 @@ Classic petstore sample app. Uses `OAuth`
299
299
</template >
300
300
</codeblock >
301
301
302
+
303
+ ## Polymorphism
304
+
305
+ Demonstrates the use of ` Discriminator `
306
+
307
+ ### Controller.php
308
+
309
+ <codeblock id =" polymorphism-Controller " >
310
+ <template v-slot:at >
311
+
312
+ <<< @/examples/specs/polymorphism/attributes/Controller.php
313
+
314
+ </template >
315
+ <template v-slot:an >
316
+
317
+ <<< @/examples/specs/polymorphism/annotations/Controller.php
318
+
319
+ </template >
320
+ </codeblock >
321
+
322
+ ### Request.php
323
+
324
+ <codeblock id =" polymorphism-Request " >
325
+ <template v-slot:at >
326
+
327
+ <<< @/examples/specs/polymorphism/attributes/Request.php
328
+
329
+ </template >
330
+ <template v-slot:an >
331
+
332
+ <<< @/examples/specs/polymorphism/annotations/Request.php
333
+
334
+ </template >
335
+ </codeblock >
336
+
337
+ ### Employee.php
338
+
339
+ <codeblock id =" polymorphism-Employee " >
340
+ <template v-slot:at >
341
+
342
+ <<< @/examples/specs/polymorphism/attributes/Employee.php
343
+
344
+ </template >
345
+ <template v-slot:an >
346
+
347
+ <<< @/examples/specs/polymorphism/annotations/Employee.php
348
+
349
+ </template >
350
+ </codeblock >
351
+
352
+ ### AbstractResponsible.php
353
+
354
+ <codeblock id =" polymorphism-AbstractResponsible " >
355
+ <template v-slot:at >
356
+
357
+ <<< @/examples/specs/polymorphism/attributes/AbstractResponsible.php
358
+
359
+ </template >
360
+ <template v-slot:an >
361
+
362
+ <<< @/examples/specs/polymorphism/annotations/AbstractResponsible.php
363
+
364
+ </template >
365
+ </codeblock >
366
+
367
+ ### Fl.php
368
+
369
+ <codeblock id =" polymorphism-Fl " >
370
+ <template v-slot:at >
371
+
372
+ <<< @/examples/specs/polymorphism/attributes/Fl.php
373
+
374
+ </template >
375
+ <template v-slot:an >
376
+
377
+ <<< @/examples/specs/polymorphism/annotations/Fl.php
378
+
379
+ </template >
380
+ </codeblock >
381
+
Original file line number Diff line number Diff line change 9
9
ob_start ();
10
10
echo $ gen ->preamble ('Example ' );
11
11
12
- foreach (['api ' , 'petstore ' ] as $ name ) {
12
+ foreach (['api ' , 'petstore ' , ' polymorphism ' ] as $ name ) {
13
13
$ exampleFolder = $ gen ->examplePath ("specs/ $ name " );
14
14
15
15
echo PHP_EOL ;
You can’t perform that action at this time.
0 commit comments