Skip to content

Commit 34bc180

Browse files
committed
fixup! WIP: Add OpenAPI tutorial
1 parent 8190f95 commit 34bc180

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

developer_manual/client_apis/OCS/ocs-openapi.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ Tips and tricks
4141
---------------
4242

4343
The openapi-extractor tool forces you to set descriptions everywhere.
44-
To ease the adoption process you can set the `--allow-missing-docs` flag to ignore those problems.
44+
To ease the adoption process you can set the ``--allow-missing-docs`` flag to ignore those problems.
4545

46-
The tool also only shows errors one by one by default, but you can also let it show you all problems at once using the `--continue-on-error`.
46+
The tool also only shows errors one by one by default, but you can also let it show you all problems at once using the ``--continue-on-error``.
4747

4848
It is advised to use neither of the mentioned flags to generate the final specification.
4949
They hide problems that your code has.
@@ -125,21 +125,21 @@ Psalm will catch these problems for you if you configured the issue handlers men
125125
];
126126
}
127127
128-
PREFER to use `null` to represent empty data
128+
PREFER to use ``null`` to represent empty data
129129
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130130

131-
Your API should be designed in a way that represents empty data with `null`.
131+
Your API should be designed in a way that represents empty data with ``null``.
132132

133133
There is a problem with PHP and arrays that get converted to JSON.
134134
JSON has lists and objects while PHP only has arrays.
135-
If you were to return an empty array in PHP it will always turn into `[]` in JSON.
135+
If you were to return an empty array in PHP it will always turn into ``[]`` in JSON.
136136
This is not a problem for endpoints that always return lists, but most endpoints return a single JSON object.
137-
For those endpoints returning `[]` in PHP is a problem because the consumer will either get `[]` or `{...}` which is hard to handle.
137+
For those endpoints returning ``[]`` in PHP is a problem because the consumer will either get ``[]`` or ``{...}`` which is hard to handle.
138138

139-
If you are not able to use `null` for whatever reason, use `new \stdClass()` instead.
140-
It will get correctly converted into `{}` in the JSON response on Nextcloud 28 and later.
139+
If you are not able to use ``null`` for whatever reason, use ``new \stdClass()`` instead.
140+
It will get correctly converted into ``{}`` in the JSON response on Nextcloud 28 and later.
141141

142-
If you are working with an existing API where you can not break compatibility, you can also type the result as `array<empty>`.
142+
If you are working with an existing API where you can not break compatibility, you can also type the result as ``array<empty>``.
143143

144144
.. collapse:: Examples
145145

@@ -213,7 +213,7 @@ Return valid responses with an error message instead.
213213
DO use the same data structures for the same group of responses
214214
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
215215

216-
Using `null` to represent empty data is encouraged.
216+
Using ``null`` to represent empty data is encouraged.
217217
All 2xx responses should return the same data structure and all 4xx should also return the same data structure.
218218

219219
.. collapse:: Examples
@@ -272,11 +272,11 @@ All 2xx responses should return the same data structure and all 4xx should also
272272
}
273273
}
274274
275-
DO NOT use the `addHeader` method for setting headers for your responses
275+
DO NOT use the ``addHeader`` method for setting headers for your responses
276276
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
277277

278278
Right now it is not possible for psalm to trace headers you set this way, so they will not be validated by psalm.
279-
Use the `setHeaders` method instead.
279+
Use the ``setHeaders`` method instead.
280280

281281
.. collapse:: Examples
282282

@@ -525,7 +525,7 @@ What you want to do now is to firstly create the correct parameter annotations a
525525
The next step is to add the return types.
526526
This is the most important step to get your API documented.
527527

528-
It is best to start with helper methods that are used multiple times like the `formatTodo` method in this example:
528+
It is best to start with helper methods that are used multiple times like the ``formatTodo`` method in this example:
529529

530530
.. code-block:: php
531531
@@ -537,7 +537,7 @@ It is best to start with helper methods that are used multiple times like the `f
537537
}
538538
539539
Afterwards you can add the return types to all the other methods.
540-
If two different status codes return the same data structure and headers, you can use the union operator to indicate it: `Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND`.
540+
If two different status codes return the same data structure and headers, you can use the union operator to indicate it: ``Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND``.
541541

542542
You are required to add a description for every status code returned by the method.
543543

@@ -600,7 +600,7 @@ How to add response definitions to share type definitions
600600

601601
In the previous steps we have been re-using the same data structure multiple times, but it was copied every time.
602602
This is tedious and error prone, therefore we want to create some shared type definitions.
603-
Create a new file called `ResponseDefinitions.php` in the `lib` folder of your app.
603+
Create a new file called ``ResponseDefinitions.php`` in the ``lib`` folder of your app.
604604
It will only work with that file name at that location.
605605

606606
.. code-block:: php
@@ -628,14 +628,14 @@ To import and use the type definition you have to import it in your controller:
628628
...
629629
}
630630
631-
Now you can replace every occurrence of `array{id: int, title: string, description: ?string, image: ?string}` with `TodoItem`.
631+
Now you can replace every occurrence of ``array{id: int, title: string, description: ?string, image: ?string}`` with ``TodoItem``.
632632

633633
How to handle exceptions
634634
------------------------
635635

636636
Sometimes you want to end with an exception instead of returning a response.
637637
It is better to not do it, but when migrating existing APIs you might have to deal with exceptions.
638-
For this example our `update` will throw an exception when the ETag does not match:
638+
For this example our ``update`` will throw an exception when the ETag does not match:
639639

640640
.. code-block:: php
641641
@@ -670,7 +670,7 @@ How to ignore certain endpoints
670670
-------------------------------
671671

672672
The tool already ignores all the endpoints that are not reachable from the outside, but some apps have reachable endpoints that are not APIs (e.g. serving some HTML).
673-
To ignore those you can add the `#[IgnoreOpenAPI]` attribute or if you still support PHP 7 the `@IgnoreOpenAPI` annotation to the controller method or the controller class:
673+
To ignore those you can add the ``#[IgnoreOpenAPI]`` attribute or if you still support PHP 7 the ``@IgnoreOpenAPI`` annotation to the controller method or the controller class:
674674

675675
.. code-block:: php
676676
@@ -726,6 +726,6 @@ The capabilities will automatically appear in the generated specification.
726726
How to generate the specification
727727
---------------------------------
728728

729-
If you followed the installation instructions for openapi-extractor you can run `composer exec generate-spec` in your apps root folder and you will have a new file called `openapi.json`.
729+
If you followed the installation instructions for openapi-extractor you can run ``composer exec generate-spec`` in your apps root folder and you will have a new file called ``openapi.json``.
730730
If the tool fails somewhere it will tell you what is wrong and often times also how to fix the problem.
731731
Additionally you should run psalm to check for any problems.

0 commit comments

Comments
 (0)