Skip to content

Add initial OpenAPI 3.1 support - #138

Merged
stephenfin merged 7 commits into
sphinx-contrib:masterfrom
stephenfin:openapi31
Jan 13, 2023
Merged

stephenfin merged 7 commits into
sphinx-contrib:masterfrom
stephenfin:openapi31

Conversation

@stephenfin

Copy link
Copy Markdown
Member

This isn't my finest work but it passes with the schema I'm using locally.
There are quite a few changes in OpenAPI 3.1 but two are addressed here:

  • 'nullable' is gone in favour of the 'null' type and type arrays
  • 'paths' is now optional and spec files can contain only components

There's a whole lot more to support here including things like webhooks but we
focus on the MVP here. All that extra functionality can be added later.

A list of commits:

  • Add initial framework for OpenAPI 3.1
  • OAS 3.1: Support specs without 'paths'
  • OAS 3.1: Support null type
  • OAS 3.1: Prefer non-null values
  • tox: Allow running specific tests
  • Update OpenAPI-Specification submodule
  • Add tests for OpenAPI 3.1 schemas

This is effectively a copy of the openapi30 module with some minor
tweaks. We will actually get this working in later changes.

Signed-off-by: Stephen Finucane <[email protected]>
This is newly introduced.

Signed-off-by: Stephen Finucane <[email protected]>
OAS 3.1 finally provides a proper way to indicate nullable objects and
nullable references. For example:

  foo:
    oneOf:
      - type: null
      - type: string
  bar:
    oneOf:
      - type: null
      - $ref: '#/components/schema/Bar'

If a user indicates that a property can be nullable in this way, we want
to prefer the non-nullable option in our examples.

Signed-off-by: Stephen Finucane <[email protected]>
Signed-off-by: Stephen Finucane <[email protected]>
Signed-off-by: Stephen Finucane <[email protected]>
@stephenfin
stephenfin merged commit c959438 into sphinx-contrib:master Jan 13, 2023
@stephenfin
stephenfin deleted the openapi31 branch January 13, 2023 12:38
dstrodtman added a commit to ray-project/ray that referenced this pull request Aug 27, 2026
…5458)

> **Stacked PR.** This targets
`doc-1513-remove-invalid-response-summary` (#65457), not `master`,
because that PR makes the spec valid and this one shouldn't inherit a
failing validator run. Review #65457 first; GitHub retargets this to
`master` automatically when it merges. The two changes are independent
in substance and can be split if you'd rather take them separately.

## Why this change is needed

`doc/source/cluster/running-applications/job-submission/openapi.yml`
declares `openapi: 3.1.0` and uses not one construct that requires 3.1.

Audited the full spec for 3.1-only constructs. Every check came back
empty:

| 3.1-only construct | Present? |
| --- | --- |
| `jsonSchemaDialect` | no |
| top-level `webhooks` | no |
| `$schema` | no |
| `const` | no |
| `examples` (the plural, JSON-Schema-aligned form) | no |
| type arrays (`type: [string, "null"]`) | no |
| `null` type | no |
| `info.summary` | no |

It also uses no `nullable`, the 3.0-only keyword it would need if it had
ever expressed nullability. The complete set of keywords in the file is
`description`, `type`, `summary`, `schema`, `content`, `title`,
`required`, `properties`, `parameters`, `in`, `$ref`, `allOf`,
`additionalProperties`, `enum`, `deprecated`, `items`, `requestBody`,
`responses`, `get`, `post`, `delete`, `components`, `schemas`, `info`,
`paths`, and `version`. Every one is valid in 3.0.x with identical
semantics.

So the document is already a valid 3.0.3 document that happens to
declare 3.1.0.

**Declaring the oldest version the document actually conforms to widens
the set of tools that can consume it.** 3.1 support across the OpenAPI
ecosystem still lags 3.0 — client generators, validators, and renderers
handle 3.0.x completely and 3.1 partially. `rest.rst` explicitly invites
readers to generate client libraries from this spec, so the declared
version directly affects whether that works for them. Nothing is gained
by declaring 3.1 while using no 3.1 feature.

There's a concrete in-repo case for this too. The doc build currently
renders this spec with `sphinxcontrib-redoc`, unmaintained since 2020,
and the maintained alternative from the same org,
`sphinxcontrib-openapi`, has only partial 3.1 support:

- The PR that added it,
[sphinx-contrib/openapi#138](sphinx-contrib/openapi#138)
(merged January 2023), is titled "Add **initial** OpenAPI 3.1 support"
and its description says "we focus on the MVP here" with "a whole lot
more to support here including things like webhooks."
-
[sphinx-contrib/openapi#160](sphinx-contrib/openapi#160)
is an open, uncommented 3.1 rendering bug filed October 2024 — an
unhandled `TypeError` in the `openapi31.py` code path.

Declaring 3.0.3 removes that whole risk class from any future evaluation
of that extension, at the cost of one line and no lost expressiveness.

## Related changes

Stacked on #65457, which removes 21 invalid `summary` keys from Response
Objects. That's a separate, version-independent validity fix; this PR is
about the declared version only.

## What changes

One line: `openapi: 3.1.0` → `openapi: 3.0.3`.

**`info.version` deliberately stays at `4.0.0`.** It tracks the Ray Jobs
API version, not the OpenAPI document version. The two are easy to
conflate, so to be explicit: this PR changes only the OpenAPI
specification version the document claims to conform to, and nothing
about the API itself.

## The published page is unaffected, verified

ReDoc handles both versions, so no visual change is expected — but this
is a client-rendered page, and a green Sphinx build proves nothing about
it. So I rendered the spec through the same pinned ReDoc v2.5.3 bundle
the build uses, at both declared versions, and compared:

| Check | Result |
| --- | --- |
| Rendered body text | **Byte-identical** (10,561 chars each) |
| Full-page screenshot | **Pixel-identical** (same sha256) |
| JavaScript errors or warnings | **None**, at either version |
| Endpoint content actually rendered | Confirmed at both, so "identical"
isn't two identical failures |

## Checks

- [x] `openapi-spec-validator` reports `OK` against the declared 3.0.3.
- [x] Rendered-output comparison above.
- [x] `pre-commit run` clean on the staged change.
- [x] Confirm `api.html` is unchanged in the Read the Docs preview for
this PR.

## If you'd rather not take this

Reasonable outcomes here include declining it. If the intent is that
this spec should eventually use 3.1 features, say so and I'll close this
— the useful part is then the recorded finding that nothing in the
document depends on 3.1 today.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…y-project#65458)

> **Stacked PR.** This targets
`doc-1513-remove-invalid-response-summary` (ray-project#65457), not `master`,
because that PR makes the spec valid and this one shouldn't inherit a
failing validator run. Review ray-project#65457 first; GitHub retargets this to
`master` automatically when it merges. The two changes are independent
in substance and can be split if you'd rather take them separately.

## Why this change is needed

`doc/source/cluster/running-applications/job-submission/openapi.yml`
declares `openapi: 3.1.0` and uses not one construct that requires 3.1.

Audited the full spec for 3.1-only constructs. Every check came back
empty:

| 3.1-only construct | Present? |
| --- | --- |
| `jsonSchemaDialect` | no |
| top-level `webhooks` | no |
| `$schema` | no |
| `const` | no |
| `examples` (the plural, JSON-Schema-aligned form) | no |
| type arrays (`type: [string, "null"]`) | no |
| `null` type | no |
| `info.summary` | no |

It also uses no `nullable`, the 3.0-only keyword it would need if it had
ever expressed nullability. The complete set of keywords in the file is
`description`, `type`, `summary`, `schema`, `content`, `title`,
`required`, `properties`, `parameters`, `in`, `$ref`, `allOf`,
`additionalProperties`, `enum`, `deprecated`, `items`, `requestBody`,
`responses`, `get`, `post`, `delete`, `components`, `schemas`, `info`,
`paths`, and `version`. Every one is valid in 3.0.x with identical
semantics.

So the document is already a valid 3.0.3 document that happens to
declare 3.1.0.

**Declaring the oldest version the document actually conforms to widens
the set of tools that can consume it.** 3.1 support across the OpenAPI
ecosystem still lags 3.0 — client generators, validators, and renderers
handle 3.0.x completely and 3.1 partially. `rest.rst` explicitly invites
readers to generate client libraries from this spec, so the declared
version directly affects whether that works for them. Nothing is gained
by declaring 3.1 while using no 3.1 feature.

There's a concrete in-repo case for this too. The doc build currently
renders this spec with `sphinxcontrib-redoc`, unmaintained since 2020,
and the maintained alternative from the same org,
`sphinxcontrib-openapi`, has only partial 3.1 support:

- The PR that added it,
[sphinx-contrib/openapi#138](sphinx-contrib/openapi#138)
(merged January 2023), is titled "Add **initial** OpenAPI 3.1 support"
and its description says "we focus on the MVP here" with "a whole lot
more to support here including things like webhooks."
-
[sphinx-contrib/openapi#160](sphinx-contrib/openapi#160)
is an open, uncommented 3.1 rendering bug filed October 2024 — an
unhandled `TypeError` in the `openapi31.py` code path.

Declaring 3.0.3 removes that whole risk class from any future evaluation
of that extension, at the cost of one line and no lost expressiveness.

## Related changes

Stacked on ray-project#65457, which removes 21 invalid `summary` keys from Response
Objects. That's a separate, version-independent validity fix; this PR is
about the declared version only.

## What changes

One line: `openapi: 3.1.0` → `openapi: 3.0.3`.

**`info.version` deliberately stays at `4.0.0`.** It tracks the Ray Jobs
API version, not the OpenAPI document version. The two are easy to
conflate, so to be explicit: this PR changes only the OpenAPI
specification version the document claims to conform to, and nothing
about the API itself.

## The published page is unaffected, verified

ReDoc handles both versions, so no visual change is expected — but this
is a client-rendered page, and a green Sphinx build proves nothing about
it. So I rendered the spec through the same pinned ReDoc v2.5.3 bundle
the build uses, at both declared versions, and compared:

| Check | Result |
| --- | --- |
| Rendered body text | **Byte-identical** (10,561 chars each) |
| Full-page screenshot | **Pixel-identical** (same sha256) |
| JavaScript errors or warnings | **None**, at either version |
| Endpoint content actually rendered | Confirmed at both, so "identical"
isn't two identical failures |

## Checks

- [x] `openapi-spec-validator` reports `OK` against the declared 3.0.3.
- [x] Rendered-output comparison above.
- [x] `pre-commit run` clean on the staged change.
- [x] Confirm `api.html` is unchanged in the Read the Docs preview for
this PR.

## If you'd rather not take this

Reasonable outcomes here include declining it. If the intent is that
this spec should eventually use 3.1 features, say so and I'll close this
— the useful part is then the recorded finding that nothing in the
document depends on 3.1 today.

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant