Skip to content

Commit 216d6bd

Browse files
sserrataclaude
andauthored
fix(license): support SPDX identifier field in OAS v3.1.0 License Object (#1365)
* feat(i18n): make QualifierMessage strings translatable Move qualifier-message rendering fully to the theme layer so that Docusaurus i18n can translate the human-readable constraint strings: - "characters" (minLength / maxLength) - "non-empty" (minLength === 1) - "Value must match regular expression" (pattern) Architecture: - `getQualifierMessage` is removed from the plugin and kept only in the theme (`docusaurus-theme-openapi-docs/src/markdown/schema.ts`), where `translate()` is available at render time. - `SchemaItem` now computes `qualifierMessage` from its `schema` prop when the caller doesn't pass one explicitly, so all callers are simplified — no more `qualifierMessage={getQualifierMessage(schema)}` at every call site. - Plugin `createSchema.ts` and `Schema/index.tsx` drop all `qualifierMessage` prop passes; the theme component handles it. - `utils.ts` `create()` skips props with `undefined` values, cleaning up generated MDX. - Dead code removed: `humanizeConstraints`, `humanizeNumberRange`, and related helpers were exported but unused. Translation IDs added: theme.openapi.schemaItem.characters theme.openapi.schemaItem.nonEmpty theme.openapi.schemaItem.expression Demo directory intentionally untouched (no locale config added). Closes #1249. Credit: @dsuket Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(license): support SPDX identifier field in OAS v3.1.0 License Object Adds rendering support for the `identifier` field introduced in OAS v3.1.0, which is mutually exclusive with `url`. When present, links to the canonical SPDX license page at https://spdx.org/licenses/<identifier>.html. Closes #1319 * test(license): add demo test spec for SPDX identifier support Adds licenseIdentifier.yaml to demo/examples/tests to verify that a spec using license.identifier renders a clickable SPDX license link correctly. Related to #1319 * test(license): add licenseUrl.yaml for regression check alongside identifier test Related to #1319 * fix(types): add identifier field to LicenseObject Required for createLicense.ts to compile after adding SPDX identifier support. Closes #1319 --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 59e7ecc commit 216d6bd

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
openapi: 3.1.0
2+
info:
3+
title: License Identifier Demo API
4+
description: |
5+
Demonstrates OAS v3.1.0 `license.identifier` support (SPDX expression).
6+
7+
Per the OAS v3.1.0 spec, `identifier` and `url` are mutually exclusive.
8+
When `identifier` is present, a link to the canonical SPDX license page
9+
should be rendered in the License section.
10+
version: 1.0.0
11+
license:
12+
name: Apache 2.0
13+
identifier: Apache-2.0
14+
tags:
15+
- name: licenseIdentifier
16+
description: License identifier tests
17+
paths:
18+
/license-identifier:
19+
get:
20+
tags:
21+
- licenseIdentifier
22+
summary: License rendered via SPDX identifier
23+
description: |
24+
This endpoint exists to verify that a spec using `license.identifier`
25+
(instead of `license.url`) correctly renders a clickable license link
26+
pointing to `https://spdx.org/licenses/Apache-2.0.html`.
27+
responses:
28+
"204":
29+
description: No content
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
openapi: 3.1.0
2+
info:
3+
title: License URL Demo API
4+
description: |
5+
Demonstrates `license.url` rendering (regression check).
6+
7+
Verifies that the existing `license.url` behavior is unaffected by the
8+
addition of `license.identifier` support.
9+
version: 1.0.0
10+
license:
11+
name: Apache 2.0
12+
url: https://www.apache.org/licenses/LICENSE-2.0.html
13+
tags:
14+
- name: licenseUrl
15+
description: License url tests
16+
paths:
17+
/license-url:
18+
get:
19+
tags:
20+
- licenseUrl
21+
summary: License rendered via URL
22+
description: |
23+
Verifies that a spec using `license.url` renders a clickable license
24+
link pointing to the provided URL.
25+
responses:
26+
"204":
27+
description: No content

packages/docusaurus-plugin-openapi-docs/src/markdown/createLicense.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { LicenseObject } from "../openapi/types";
1010

1111
export function createLicense(license: LicenseObject) {
1212
if (!license || !Object.keys(license).length) return "";
13-
const { name, url } = license;
13+
const { name, url, identifier } = license;
1414

1515
return create("div", {
1616
style: {
@@ -29,6 +29,12 @@ export function createLicense(license: LicenseObject) {
2929
children: name ?? url,
3030
})
3131
),
32+
guard(identifier, () =>
33+
create("a", {
34+
href: `https://spdx.org/licenses/${identifier}.html`,
35+
children: name ?? identifier,
36+
})
37+
),
3238
],
3339
});
3440
}

packages/docusaurus-plugin-openapi-docs/src/openapi/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export interface ContactObject {
6565
export interface LicenseObject {
6666
name: string;
6767
url?: string;
68+
identifier?: string;
6869
}
6970

7071
export interface ServerObject {

0 commit comments

Comments
 (0)