Versions and output

OpenAPI 3.2

The QUERY method, other HTTP methods, streams, tag hierarchies and the other 3.2 additions.

OpenAPI 3.2 adds new methods, streaming media types, tag hierarchies and smaller fields. Declare the version once with openapi(), or pass it when writing.

use Ark4ne\OpenApiWriter\Enums\Version;

$document = $document->openapi(Version::V3_2_0);

Written for an older version, each of these features throws in strict mode, and is dropped in lenient mode; see Conversions for the full list.

The QUERY method and other methods

QUERY is a safe method with a body, for searches that do not fit in a URL. Any other method goes to additionalOperations, through Operation::create():

PathItem
use Ark4ne\OpenApiWriter\Objects\MediaType;
use Ark4ne\OpenApiWriter\Objects\Operation;
use Ark4ne\OpenApiWriter\Objects\PathItem;
use Ark4ne\OpenApiWriter\Objects\Response;
use Ark4ne\OpenApiWriter\Objects\Schema;

PathItem::create('/books/search')->operations(
    Operation::query()
        ->operationId('books.search')
        ->responses(Response::ok()->content(
            MediaType::of('application/jsonl')
                ->itemSchema(Schema::ref('Book')),
        )),
    Operation::create('COPY')
        ->operationId('books.copy')
        ->responses(Response::created()),
);
toArray(Version::V3_2_0)
{
  "query": {
    "operationId": "books.search",
    "responses": {
      "200": {
        "description": "OK",
        "content": {
          "application/jsonl": {
            "itemSchema": { "$ref": "#/components/schemas/Book" }
          }
        }
      }
    }
  },
  "additionalOperations": {
    "COPY": {
      "operationId": "books.copy",
      "responses": {
        "201": { "description": "Created" }
      }
    }
  }
}

A method that has its own field (get, post, query…) cannot go to additionalOperations.

Streams

MediaType::itemSchema() describes each item of a stream, such as JSON lines or server-sent events. Above, application/jsonl returns one Book per line. prefixEncoding() and itemEncoding() describe the encoding of positional and repeated parts.

Tag hierarchy

use Ark4ne\OpenApiWriter\Objects\Tag;

$document = $document->tags(
    Tag::create()->name('library')->summary('Library')->kind('nav'),
    Tag::create()->name('books')->parent('library'),
);

parent() names another declared tag; kind() is free (nav, badge, audience…). The validator checks that each parent exists and that parents do not loop (TagParentsRule). For Redoc on an older version, the hierarchy can be written as x-tagGroups; see Redoc extensions.

Other additions

MethodPurpose
OpenApi::self(?string)The $self URI of the document
Server::name(?string)A name for the server
Parameter::querystring($name)The whole query string as one parameter, described by content()
ParameterStyle::CookieThe cookie style
Components::mediaTypes(), MediaType::ref()Reusable media types
MediaType::description(?string), Response::summary(?string)
Example::dataValue(mixed), Example::serializedValue(?string)The value as data, and as sent on the wire
Discriminator::defaultMapping(?string)The schema used when the discriminator value is not mapped
Xml::nodeType(XmlNodeType|string|null)Exclusive with attribute and wrapped
OAuthFlows::deviceAuthorization()The device authorization flow, with OAuthFlow::deviceAuthorizationUrl()
SecurityScheme::oauth2MetadataUrl(?string), deprecated()