Versions and output

Redoc extensions

Keep webhooks and tag hierarchies in older versions, as the x-webhooks and x-tagGroups that Redoc reads.

Redoc reads two extensions that predate the specification: x-webhooks and x-tagGroups. With VendorExtensions::Redoc, the library writes webhooks and tag parents in these forms where the target version lacks them, instead of rejecting them. It is off by default, so that the output follows the specification.

ModelMissing beforeWritten as
OpenApi::webhooks()3.1.0x-webhooks at the root, same shape as webhooks
Tag::parent()3.2.0x-tagGroups at the root, and parent removed from the tags

Turning it on

Every writing method takes it, and so does the validator:

use Ark4ne\OpenApiWriter\Enums\VendorExtensions;
use Ark4ne\OpenApiWriter\Enums\Version;

$json = $document->toJson(
    Version::V3_0_4,
    JSON_PRETTY_PRINT,
    VendorExtensions::Redoc,
);
$yaml = $document->toYaml(Version::V3_0_4, VendorExtensions::Redoc);
use Ark4ne\OpenApiWriter\Enums\Strictness;
use Ark4ne\OpenApiWriter\Serialization\Serializer;

$result = Serializer::for(
    Version::V3_0_4,
    Strictness::Lenient,
    VendorExtensions::Redoc,
)->serialize($document);

The strings work too: Serializer::for('3.0.4', 'lenient', 'redoc').

Example

OpenApi
use Ark4ne\OpenApiWriter\Objects\Operation;
use Ark4ne\OpenApiWriter\Objects\PathItem;
use Ark4ne\OpenApiWriter\Objects\Response;
use Ark4ne\OpenApiWriter\Objects\Tag;

$document = $document
    ->tags(
        Tag::create()->name('shop'),
        Tag::create()->name('orders')->parent('shop'),
    )
    ->webhooks(
        PathItem::create('orderPaid')->operations(
            Operation::post()
                ->responses(Response::noContent()),
        ),
    );
toArray('3.0.4', 'redoc'), excerpt
{
  "tags": [{ "name": "shop" }, { "name": "orders" }],
  "x-webhooks": {
    "orderPaid": {
      "post": {
        "responses": {
          "204": { "description": "No Content" }
        }
      }
    }
  },
  "x-tagGroups": [
    { "name": "shop", "tags": ["shop", "orders"] }
  ]
}

Each conversion is reported as a converted diagnostic, in both modes:

[converted] /tags/1/parent: parent written in x-tagGroups
[converted] /webhooks: webhooks written as x-webhooks

How tag groups are built

  • Groups follow the order of the tags. Redoc groups on one level: a tag goes into the group of its topmost ancestor, named after it (cats → pets → animals goes into the group animals).
  • A tag without parent forms its own group, holding itself, because Redoc hides the tags of no group. A parent missing from tags still names its group. A tag whose parents loop forms its own group.
  • Without any parent, no x-tagGroups is written.
  • Redoc shows only the tags listed in a group: declare in OpenApi::tags() every tag used by an operation.

Limits

  • Tag::summary() and Tag::kind() have no Redoc form: they stay unsupported before 3.2.
  • An x-webhooks or x-tagGroups set by the document with x() wins: the matching feature is then not converted, and stays unsupported.
  • A Tag written alone, outside an OpenApi, has no root to hold x-tagGroups: its parent stays unsupported.
  • Validate with the same option, $validator->validate($document, '3.0.4', VendorExtensions::Redoc): before 3.1, the rules then read x-webhooks like webhooks.