OpenAPI.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * @param self::SCOPE_*|string $scope Scopes are used to define different clients.
  46. * It is recommended to go with the scopes available as self::SCOPE_* constants,
  47. * but in exotic cases other APIs might need documentation as well,
  48. * then a free string can be provided (but it should be `a-z` only).
  49. * @param ?list<string> $tags Tags can be used to group routes inside a scope
  50. * for easier implementation and reviewing of the API specification.
  51. * It defaults to the controller name in snake_case (should be `a-z` and underscore only).
  52. * @since 28.0.0
  53. */
  54. public function __construct(
  55. protected string $scope = self::SCOPE_DEFAULT,
  56. protected ?array $tags = null,
  57. ) {
  58. }
  59. /**
  60. * @since 28.0.0
  61. */
  62. public function getScope(): string {
  63. return $this->scope;
  64. }
  65. /**
  66. * @return ?list<string>
  67. * @since 28.0.0
  68. */
  69. public function getTags(): ?array {
  70. return $this->tags;
  71. }
  72. }