OpenAPI.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\AppFramework\Http\Attribute;
  8. use Attribute;
  9. /**
  10. * With this attribute a controller or a method can be moved into a different
  11. * scope or tag. Scopes should be seen as API consumers, tags can be used to group
  12. * different routes inside the same scope.
  13. *
  14. * @since 28.0.0
  15. */
  16. #[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
  17. class OpenAPI {
  18. /**
  19. * APIs used for normal user facing interaction with your app,
  20. * e.g. when you would implement a mobile client or standalone frontend.
  21. *
  22. * @since 28.0.0
  23. */
  24. public const SCOPE_DEFAULT = 'default';
  25. /**
  26. * APIs used to administrate your app's configuration on an administrative level.
  27. * Will be set automatically when admin permissions are required to access the route.
  28. *
  29. * @since 28.0.0
  30. */
  31. public const SCOPE_ADMINISTRATION = 'administration';
  32. /**
  33. * APIs used by servers to federate with each other.
  34. *
  35. * @since 28.0.0
  36. */
  37. public const SCOPE_FEDERATION = 'federation';
  38. /**
  39. * Ignore this controller or method in all generated OpenAPI specifications.
  40. *
  41. * @since 28.0.0
  42. */
  43. public const SCOPE_IGNORE = 'ignore';
  44. /**
  45. * APIs used by ExApps.
  46. * Will be set automatically when an ExApp is required to access the route.
  47. *
  48. * @since 30.0.0
  49. */
  50. public const SCOPE_EX_APP = 'ex_app';
  51. /**
  52. * @param self::SCOPE_*|string $scope Scopes are used to define different clients.
  53. * It is recommended to go with the scopes available as self::SCOPE_* constants,
  54. * but in exotic cases other APIs might need documentation as well,
  55. * then a free string can be provided (but it should be `a-z` only).
  56. * @param ?list<string> $tags Tags can be used to group routes inside a scope
  57. * for easier implementation and reviewing of the API specification.
  58. * It defaults to the controller name in snake_case (should be `a-z` and underscore only).
  59. * @since 28.0.0
  60. */
  61. public function __construct(
  62. protected string $scope = self::SCOPE_DEFAULT,
  63. protected ?array $tags = null,
  64. ) {
  65. }
  66. /**
  67. * @since 28.0.0
  68. */
  69. public function getScope(): string {
  70. return $this->scope;
  71. }
  72. /**
  73. * @return ?list<string>
  74. * @since 28.0.0
  75. */
  76. public function getTags(): ?array {
  77. return $this->tags;
  78. }
  79. }