vendor/zircote/swagger-php/src/Annotations/Response.php line 121

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * @license Apache 2.0
  4.  */
  5. namespace OpenApi\Annotations;
  6. use OpenApi\Generator;
  7. /**
  8.  * Describes a single response from an API Operation, including design-time,
  9.  * static links to operations based on the response.
  10.  *
  11.  * @see [OAI Response Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#response-object)
  12.  *
  13.  * @Annotation
  14.  */
  15. class Response extends AbstractAnnotation
  16. {
  17.     /**
  18.      * The relative or absolute path to a response.
  19.      *
  20.      * @see [Using refs](https://swagger.io/docs/specification/using-ref/)
  21.      *
  22.      * @var string|class-string|object
  23.      */
  24.     public $ref Generator::UNDEFINED;
  25.     /**
  26.      * The key into Operations->responses array.
  27.      *
  28.      * A HTTP status code or <code>default</code>.
  29.      *
  30.      * @var string|int
  31.      */
  32.     public $response Generator::UNDEFINED;
  33.     /**
  34.      * A short description of the response.
  35.      *
  36.      * CommonMark syntax may be used for rich text representation.
  37.      *
  38.      * @var string
  39.      */
  40.     public $description Generator::UNDEFINED;
  41.     /**
  42.      * Maps a header name to its definition.
  43.      *
  44.      * RFC7230 states header names are case insensitive.
  45.      *
  46.      * If a response header is defined with the name "Content-Type", it shall be ignored.
  47.      *
  48.      * @see [RFC7230](https://tools.ietf.org/html/rfc7230#page-22)
  49.      *
  50.      * @var Header[]
  51.      */
  52.     public $headers Generator::UNDEFINED;
  53.     /**
  54.      * A map containing descriptions of potential response payloads.
  55.      *
  56.      * The key is a media type or media type range and the value describes it.
  57.      *
  58.      * For responses that match multiple keys, only the most specific key is applicable;
  59.      * e.g. <code>text/plain</code> overrides <code>text/*</code>.
  60.      *
  61.      * @var MediaType|JsonContent|XmlContent|Attachable|array<MediaType|JsonContent|XmlContent|Attachable>
  62.      */
  63.     public $content Generator::UNDEFINED;
  64.     /**
  65.      * A map of operations links that can be followed from the response.
  66.      *
  67.      * The key of the map is a short name for the link, following the naming constraints of the names for Component
  68.      * Objects.
  69.      *
  70.      * @var Link[]
  71.      */
  72.     public $links Generator::UNDEFINED;
  73.     /**
  74.      * @inheritdoc
  75.      */
  76.     public static $_types = [
  77.         'description' => 'string',
  78.     ];
  79.     /**
  80.      * @inheritdoc
  81.      */
  82.     public static $_nested = [
  83.         MediaType::class => ['content''mediaType'],
  84.         Header::class => ['headers''header'],
  85.         Link::class => ['links''link'],
  86.         Attachable::class => ['attachables'],
  87.     ];
  88.     /**
  89.      * @inheritdoc
  90.      */
  91.     public static $_parents = [
  92.         Components::class,
  93.         Operation::class,
  94.         Get::class,
  95.         Post::class,
  96.         Put::class,
  97.         Patch::class,
  98.         Delete::class,
  99.         Head::class,
  100.         Options::class,
  101.         Trace::class,
  102.     ];
  103.     /**
  104.      * @inheritdoc
  105.      */
  106.     public function validate(array $stack = [], array $skip = [], string $ref ''$context null): bool
  107.     {
  108.         $valid parent::validate($stack$skip$ref$context);
  109.         if (Generator::isDefault($this->description) && Generator::isDefault($this->ref)) {
  110.             $this->_context->logger->warning($this->identity() . ' One of description or ref is required');
  111.             $valid false;
  112.         }
  113.         return $valid;
  114.     }
  115. }