Skip to content

Commit 59e7ecc

Browse files
sserrataclaude
andauthored
feat(i18n): make QualifierMessage strings translatable (#1364)
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>
1 parent 22d48e4 commit 59e7ecc

File tree

11 files changed

+39
-618
lines changed

11 files changed

+39
-618
lines changed

packages/docusaurus-plugin-openapi-docs/src/markdown/__snapshots__/createSchema.test.ts.snap

Lines changed: 0 additions & 100 deletions
Large diffs are not rendered by default.

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

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import { createDescription } from "./createDescription";
1818
import { createDetails } from "./createDetails";
1919
import { createDetailsSummary } from "./createDetailsSummary";
20-
import { getQualifierMessage, getSchemaName } from "./schema";
20+
import { getSchemaName } from "./schema";
2121
import { create, guard } from "./utils";
2222
import { SchemaObject } from "../openapi/types";
2323

@@ -140,7 +140,6 @@ function createProperties(schema: SchemaObject) {
140140
name: "",
141141
required: false,
142142
schemaName: "object",
143-
qualifierMessage: undefined,
144143
schema: {},
145144
});
146145
}
@@ -169,7 +168,6 @@ function createAdditionalProperties(schema: SchemaObject) {
169168
name: "property name*",
170169
required: false,
171170
schemaName: "any",
172-
qualifierMessage: getQualifierMessage(schema),
173171
schema: schema,
174172
collapsible: false,
175173
discriminator: false,
@@ -209,7 +207,6 @@ function createAdditionalProperties(schema: SchemaObject) {
209207
name: "property name*",
210208
required: false,
211209
schemaName: schemaName,
212-
qualifierMessage: getQualifierMessage(schema),
213210
schema: additionalProperties,
214211
collapsible: false,
215212
discriminator: false,
@@ -399,12 +396,6 @@ function createDetailsNode(
399396
children: createDescription(description),
400397
})
401398
),
402-
guard(getQualifierMessage(schema), (message) =>
403-
create("div", {
404-
style: { marginTop: ".5rem", marginBottom: ".5rem" },
405-
children: createDescription(message),
406-
})
407-
),
408399
createNodes(schema, SCHEMA_TYPE),
409400
],
410401
}),
@@ -545,14 +536,6 @@ function createPropertyDiscriminator(
545536
children: createDescription(description),
546537
})
547538
),
548-
guard(getQualifierMessage(discriminator), (message) =>
549-
create("div", {
550-
style: {
551-
paddingLeft: "1rem",
552-
},
553-
children: createDescription(message),
554-
})
555-
),
556539
create("DiscriminatorTabs", {
557540
className: "openapi-tabs__discriminator",
558541
children: Object.keys(discriminator?.mapping!).map((key, index) => {
@@ -727,7 +710,6 @@ function createEdges({
727710
name,
728711
required: Array.isArray(required) ? required.includes(name) : required,
729712
schemaName: mergedSchemaName,
730-
qualifierMessage: getQualifierMessage(mergedSchemas),
731713
schema: mergedSchemas,
732714
});
733715
}
@@ -738,7 +720,6 @@ function createEdges({
738720
name,
739721
required: Array.isArray(required) ? required.includes(name) : required,
740722
schemaName: schemaName,
741-
qualifierMessage: getQualifierMessage(schema),
742723
schema: schema,
743724
});
744725
}
@@ -823,17 +804,7 @@ export function createNodes(
823804
marginTop: ".5rem",
824805
marginBottom: ".5rem",
825806
},
826-
children: [
827-
createDescription(schema.type),
828-
guard(getQualifierMessage(schema), (message) =>
829-
create("div", {
830-
style: {
831-
paddingTop: "1rem",
832-
},
833-
children: createDescription(message),
834-
})
835-
),
836-
],
807+
children: [createDescription(schema.type)],
837808
});
838809
}
839810

@@ -844,17 +815,7 @@ export function createNodes(
844815
marginTop: ".5rem",
845816
marginBottom: ".5rem",
846817
},
847-
children: [
848-
createDescription(schema),
849-
guard(getQualifierMessage(schema), (message) =>
850-
create("div", {
851-
style: {
852-
paddingTop: "1rem",
853-
},
854-
children: createDescription(message),
855-
})
856-
),
857-
],
818+
children: [createDescription(schema)],
858819
});
859820
}
860821

packages/docusaurus-plugin-openapi-docs/src/markdown/schema.test.ts

Lines changed: 0 additions & 208 deletions
This file was deleted.

0 commit comments

Comments
 (0)