Skip to content

Tracy panel cannot render OpenAPI 3.1 documents the library itself produces (vendored Swagger UI is 3.24.2) #16

Description

@AdamFiser

The Tracy panel does not render OpenAPI 3.1 documents, although the library produces, describes and validates them. For any document declaring openapi: 3.1.0, Contributte\OpenApi\Tracy\SwaggerPanel shows only "Unable to render this definition".

The vendored Swagger UI in src/Tracy/templates/assets/ is 3.24.2, built 2019-11-04, and has never been updated (git log -- src/Tracy/templates/assets/ shows the initial commit alone). Its version detection accepts the 3.0 series only:

function s(e){var t=e.get("openapi");return"string"==typeof t&&(t.startsWith("3.0.")&&t.length>4)}
function u(e){var t=e.get("swagger");return"string"==typeof t&&t.startsWith("2.0")}

A document declaring openapi: 3.1.0 matches neither, so VersionPragmaFilter renders the fallback instead of the API. Swagger UI renders 3.1 from 5.0.0 on.

Meanwhile Version::SUPPORTED lists V3_1, and Validator\VersionValidator carries rules for constructs 3.1 introduced (jsonSchemaDialect, webhooks, info.summary, components.pathItems, mutualTLS, optional paths).

Reproduced

tests/Cases/Schema/examples/complete-3-1.yaml through OpenApi::fromArray(...)->toArray() (which yields openapi: 3.1.0), rendered in headless Chrome through the markup panel.phtml produces:

Swagger UI document version-pragma__message--missing node rendered operations
3.24.2 (vendored) openapi: 3.1.0 1 0
3.24.2 (vendored) same document as openapi: 3.0.4 0 8

The only difference between the two rows is the version field. The rendered node:

<div class="version-pragma__message version-pragma__message--missing"><div>
  <h3>Unable to render this definition</h3>
  <p>The provided definition does not specify a valid version field.</p>
  <p>Please indicate a valid Swagger or OpenAPI version field. Supported version fields are
     <code>swagger: "2.0"</code> and those that match <code>openapi: 3.0.n</code>
     (for example, <code>openapi: 3.0.0</code>).</p>
</div></div>

The message is also misleading: it blames the definition for specifying no valid version field, when the definition is valid and the bundled viewer is old.

One constraint worth knowing before touching this: src/Tracy/templates/assets/swagger-ui.css is not the distributed file. Every selector is scoped to #tracy-debug, because the panel renders inside a host page it must not style.

Found via contributte/apitte in an application that must emit OpenAPI 3.1. Verified on v0.2.0 and on master (f6186a3).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions