You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -622,6 +628,7 @@ The name of every type definition has to start with the app ID.
622
628
To import and use the type definition you have to import it in your controller:
623
629
624
630
.. code-block:: php
631
+
:emphasize-lines: 2
625
632
626
633
/**
627
634
* @psalm-import-type TodoItem from ResponseDefinitions
@@ -653,6 +660,7 @@ For this example our ``update`` will throw an exception when the ETag does not m
653
660
Adding the correct annotation works like this:
654
661
655
662
.. code-block:: php
663
+
:emphasize-lines: 4
656
664
657
665
/**
658
666
* ...
@@ -672,16 +680,17 @@ How to ignore certain endpoints
672
680
-------------------------------
673
681
674
682
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).
675
-
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:
683
+
To ignore those you can add the ``#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]`` attribute or if you still support PHP 7 the ``@IgnoreOpenAPI`` annotation to the controller method or the controller class:
676
684
677
685
.. code-block:: php
686
+
:emphasize-lines: 4,6
678
687
679
688
/**
680
689
* ...
681
690
*
682
691
* @IgnoreOpenAPI
683
692
*/
684
-
#[IgnoreOpenAPI]
693
+
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
685
694
#[NoAdminRequired]
686
695
public function show(): TemplateResponse {
687
696
...
@@ -708,6 +717,7 @@ Imagine we take the same Todo app of the previous example and want to expose som
708
717
Now you have to add the correct return type annotation:
709
718
710
719
.. code-block:: php
720
+
:emphasize-lines: 3
711
721
712
722
class Capabilities implements ICapability {
713
723
/**
@@ -725,9 +735,49 @@ Now you have to add the correct return type annotation:
725
735
726
736
The capabilities will automatically appear in the generated specification.
727
737
738
+
Scopes
739
+
------
740
+
741
+
In some cases a consumer of the API might not want or need to implement all APIs your app offers.
742
+
Examples are federation between apps on different servers, administration related endpoints, and more.
743
+
The default client which should implement the main functionality is called ``OpenAPI::SCOPE_DEFAULT``.
744
+
Constants are available in ``OCP\AppFramework\Http\Attribute\OpenAPI::SCOPE_*`` for better cross-app experience.
745
+
A controller and methods can have multiple scopes, however when a method has the attribute set,
746
+
all scopes from the controller are ignored.
747
+
748
+
Methods that require admin permissions due to missing ``#[NoAdminRequired]`` or ``#[PublicPage]`` attribute or the
749
+
matching annotation, default to the ``OpenAPI::SCOPE_ADMINISTRATION`` scope.
750
+
751
+
.. code-block:: php
752
+
753
+
#[OpenAPI(scope: OpenAPI::SCOPE_ADMINISTRATION)]
754
+
#[OpenAPI(scope: OpenAPI::SCOPE_FEDERATION)]
755
+
#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)]
756
+
#[OpenAPI(scope: 'myscope')]
757
+
public function show(): TemplateResponse {
758
+
...
759
+
}
760
+
761
+
The different scopes will be saved as ``openapi.json`` for the default scope and ``openapi-{scope}.json`` for the others.
762
+
763
+
Tags
764
+
^^^^
765
+
766
+
To organize the API endpoints within a scope, tags can be used to group them. By default the controller name is used.
public function saveSettings(): TemplateResponse {
774
+
...
775
+
}
776
+
728
777
How to generate the specification
729
778
---------------------------------
730
779
731
-
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``.
780
+
If you followed the installation instructions for openapi-extractor you can run ``composer exec generate-spec`` in your
781
+
apps root folder and you will have a new file called ``openapi.json`` (depending on the used scopes).
732
782
If the tool fails somewhere it will tell you what is wrong and often times also how to fix the problem.
733
783
Additionally you should run psalm to check for any problems.
0 commit comments