Skip to content

Commit 09922f3

Browse files
committed
feat: improve CustomizeType to render basic constant values
1 parent 3a40253 commit 09922f3

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

__tests__/JSONSchemaViewer/__snapshots__/generateFriendlyName.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,7 @@ exports[`JSONSchemaViewer - generateFriendlyName cases test Prefer title 1`] = `
22212221
</strong>
22222222
 
22232223
<code>
2224-
Hello World
2224+
"Hello World"
22252225
</code>
22262226
 
22272227
<strong>

__tests__/JSONSchemaViewer/__snapshots__/generic_keywords.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ exports[`JSONSchemaViewer - Generic keywords test const 1`] = `
166166
</strong>
167167
 
168168
<code>
169-
United States of America
169+
"United States of America"
170170
</code>
171171
 
172172
<strong>

__tests__/JSONSchemaViewer/__snapshots__/schema_conditionally.test.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else (multiple) 1`
331331
</strong>
332332
 
333333
<code>
334-
United States of America
334+
"United States of America"
335335
</code>
336336
 
337337
<strong>
@@ -588,7 +588,7 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else (multiple) 1`
588588
</strong>
589589
 
590590
<code>
591-
Canada
591+
"Canada"
592592
</code>
593593
 
594594
<strong>
@@ -849,7 +849,7 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else (multiple) 1`
849849
</strong>
850850
 
851851
<code>
852-
Netherlands
852+
"Netherlands"
853853
</code>
854854
 
855855
<strong>
@@ -1248,7 +1248,7 @@ exports[`JSONSchemaViewer - schema conditionally test If Then Else 1`] = `
12481248
</strong>
12491249
 
12501250
<code>
1251-
United States of America
1251+
"United States of America"
12521252
</code>
12531253
 
12541254
<strong>

src/theme/JSONSchemaViewer/utils/generateFriendlyName.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from "react"
22

3+
import CodeBlock from "@theme-original/CodeBlock"
4+
35
// Utility functions to know which case we have
46
import { detectedTypes } from "@theme/JSONSchemaViewer/utils"
57

@@ -17,7 +19,6 @@ import type {
1719
JSONSchemaNS,
1820
TypeValues,
1921
} from "@theme/JSONSchemaViewer/types"
20-
import { printSchemaType } from "@theme/JSONSchemaViewer/utils/QualifierMessages"
2122

2223
// common function I need below
2324
function shouldAddSeparator(idx: number, length: number): boolean {
@@ -139,12 +140,21 @@ function CustomizeType({ schema, type }: CustomizeProps): JSX.Element {
139140
}
140141

141142
// For constant values
143+
// I used Docusaurus Codeblock (instead of printSchemaType) as they put quotes whereas normal <code> don't
142144
if (!["array", "object"].includes(type)) {
143145
if (schema.const !== undefined) {
144-
return printSchemaType(schema.const)
146+
return (
147+
<CodeBlock language="json">{`${JSON.stringify(
148+
schema.const,
149+
)}`}</CodeBlock>
150+
)
145151
}
146152
if (schema.enum !== undefined && schema.enum.length === 1) {
147-
return printSchemaType(schema.enum[0])
153+
return (
154+
<CodeBlock language="json">{`${JSON.stringify(
155+
schema.enum[0],
156+
)}`}</CodeBlock>
157+
)
148158
}
149159
}
150160

0 commit comments

Comments
 (0)