Skip to content

Commit 8d101f7

Browse files
committed
Add REST controller to doc
1 parent 72c0614 commit 8d101f7

File tree

1 file changed

+88
-1
lines changed

1 file changed

+88
-1
lines changed

code_samples/api/rest_api/src/Rest/Controller/DefaultController.php

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,90 @@
1212
use Symfony\Component\Serializer\Encoder\XmlEncoder;
1313
use Symfony\Component\Serializer\SerializerInterface;
1414

15+
#[Get(
16+
uriTemplate: '/greet',
17+
extraProperties: [OpenApiFactory::OVERRIDE_OPENAPI_RESPONSES => false],
18+
openapi: new Model\Operation(
19+
summary: 'Greet',
20+
description: 'Greets a recipient with a salutation',
21+
tags: [
22+
'App',
23+
],
24+
parameters: [
25+
new Model\Parameter(
26+
name: 'Accept',
27+
in: 'header',
28+
required: false,
29+
description: 'If set, the greeting is returned in XML or JSON format.',
30+
schema: [
31+
'type' => 'string',
32+
],
33+
example: 'application/vnd.ibexa.api.Greeting+json',
34+
),
35+
],
36+
responses: [
37+
Response::HTTP_OK => [
38+
'description' => 'OK - Return a greeting',
39+
'content' => [
40+
'application/vnd.ibexa.api.Greeting+xml' => [
41+
'schema' => [
42+
'xml' => [
43+
'name' => 'Greeting',
44+
'wrapped' => false,
45+
],
46+
'properties' => [
47+
'salutation' => [
48+
'type' => 'string',
49+
],
50+
'recipient' => [
51+
'type' => 'string',
52+
],
53+
'sentence' => [
54+
'type' => 'string',
55+
'description' => 'Composed sentence using salutation and recipient.'
56+
]
57+
],
58+
],
59+
'example' => [
60+
'salutation' => 'Hello',
61+
'recipient' => 'World',
62+
'sentence' => 'Hello World',
63+
],
64+
],
65+
'application/vnd.ibexa.api.Greeting+json' => [
66+
'schema' => [
67+
'type' => 'object',
68+
'properties' => [
69+
'Greeting' => [
70+
'type' => 'object',
71+
'properties' => [
72+
'salutation' => [
73+
'type' => 'string',
74+
],
75+
'recipient' => [
76+
'type' => 'string',
77+
],
78+
'sentence' => [
79+
'type' => 'string',
80+
'description' => 'Composed sentence using salutation and recipient.'
81+
],
82+
],
83+
],
84+
],
85+
],
86+
'example' => [
87+
'Greeting' => [
88+
'salutation' => 'Hello',
89+
'recipient' => 'World',
90+
'sentence' => 'Hello World',
91+
],
92+
],
93+
],
94+
],
95+
],
96+
],
97+
),
98+
)]
1599
#[Post(
16100
uriTemplate: '/greet',
17101
extraProperties: [OpenApiFactory::OVERRIDE_OPENAPI_RESPONSES => false],
@@ -30,15 +114,17 @@
30114
schema: [
31115
'type' => 'string',
32116
],
117+
example: 'application/vnd.ibexa.api.GreetingInput+json',
33118
),
34119
new Model\Parameter(
35120
name: 'Accept',
36121
in: 'header',
37-
required: true,
122+
required: false,
38123
description: 'If set, the greeting is returned in XML or JSON format.',
39124
schema: [
40125
'type' => 'string',
41126
],
127+
example: 'application/vnd.ibexa.api.Greeting+json',
42128
),
43129
],
44130
requestBody: new Model\RequestBody(
@@ -138,6 +224,7 @@
138224
],
139225
'sentence' => [
140226
'type' => 'string',
227+
'description' => 'Composed sentence using salutation and recipient.'
141228
],
142229
],
143230
],

0 commit comments

Comments
 (0)