File tree Expand file tree Collapse file tree 3 files changed +123
-2
lines changed
packages/docusaurus-theme-openapi-docs/src/theme Expand file tree Collapse file tree 3 files changed +123
-2
lines changed Original file line number Diff line number Diff line change
1
+ openapi : 3.1.1
2
+ info :
3
+ title : Const
4
+ description : Demonstrates various const.
5
+ version : 1.0.0
6
+ tags :
7
+ - name : const
8
+ description : const tests
9
+ paths :
10
+ /const :
11
+ get :
12
+ tags :
13
+ - const
14
+ summary : const with primitives
15
+ description : |
16
+ Schema:
17
+ ```yaml
18
+ type: object
19
+ properties:
20
+ type:
21
+ type: string
22
+ const: example
23
+ title: Example
24
+ description: |
25
+ This is an example
26
+ quality:
27
+ type: string
28
+ oneOf:
29
+ - const: good
30
+ title: Good
31
+ description: |
32
+ This is a good example
33
+ - const: bad
34
+ title: Bad
35
+ description: |
36
+ This is a bad example
37
+ tags:
38
+ type: array
39
+ items:
40
+ anyOf:
41
+ - const: dog
42
+ title: Dog
43
+ description: |
44
+ This is a dog
45
+ - const: cat
46
+ title: Cat
47
+ description: |
48
+ This is a cat
49
+ required:
50
+ - type
51
+ - quality
52
+ ```
53
+ responses :
54
+ " 200 " :
55
+ description : Successful response
56
+ content :
57
+ application/json :
58
+ schema :
59
+ type : object
60
+ properties :
61
+ type :
62
+ type : string
63
+ const : constExample
64
+ title : Const Example
65
+ description : |
66
+ Const example description
67
+ quality :
68
+ type : string
69
+ oneOf :
70
+ - const : good
71
+ title : Good
72
+ description : |
73
+ This is a good example
74
+ - const : bad
75
+ title : Bad
76
+ description : |
77
+ This is a bad example
78
+ tags :
79
+ type : array
80
+ items :
81
+ type : string
82
+ anyOf :
83
+ - const : dog
84
+ title : Dog
85
+ description : |
86
+ This is a dog
87
+ - const : cat
88
+ title : Cat
89
+ description : |
90
+ This is a cat
91
+ required :
92
+ - type
93
+ - quality
Original file line number Diff line number Diff line change @@ -122,9 +122,10 @@ const AnyOneOf: React.FC<SchemaProps> = ({ schema, schemaType }) => {
122
122
value = { `${ index } -item-properties` }
123
123
>
124
124
{ /* Handle primitive types directly */ }
125
- { [ "string" , "number" , "integer" , "boolean" ] . includes (
125
+ { ( [ "string" , "number" , "integer" , "boolean" ] . includes (
126
126
anyOneSchema . type
127
- ) && (
127
+ ) ||
128
+ anyOneSchema . const ) && (
128
129
< SchemaItem
129
130
collapsible = { false }
130
131
name = { undefined }
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ export default function SchemaItem(props: Props) {
65
65
let example : string | undefined ;
66
66
let nullable ;
67
67
let enumDescriptions : [ string , string ] [ ] = [ ] ;
68
+ let constValue : string | undefined ;
68
69
69
70
if ( schema ) {
70
71
deprecated = schema . deprecated ;
@@ -75,6 +76,7 @@ export default function SchemaItem(props: Props) {
75
76
nullable =
76
77
schema . nullable ||
77
78
( Array . isArray ( schema . type ) && schema . type . includes ( "null" ) ) ; // support JSON Schema nullable
79
+ constValue = schema . const ;
78
80
}
79
81
80
82
const renderRequired = guard (
@@ -161,6 +163,30 @@ export default function SchemaItem(props: Props) {
161
163
return undefined ;
162
164
}
163
165
166
+ function renderConstValue ( ) {
167
+ if ( constValue !== undefined ) {
168
+ if ( typeof constValue === "string" ) {
169
+ return (
170
+ < div >
171
+ < strong > Constant value: </ strong >
172
+ < span >
173
+ < code > { constValue } </ code >
174
+ </ span >
175
+ </ div >
176
+ ) ;
177
+ }
178
+ return (
179
+ < div >
180
+ < strong > Constant value: </ strong >
181
+ < span >
182
+ < code > { JSON . stringify ( constValue ) } </ code >
183
+ </ span >
184
+ </ div >
185
+ ) ;
186
+ }
187
+ return undefined ;
188
+ }
189
+
164
190
const schemaContent = (
165
191
< div >
166
192
< span className = "openapi-schema__container" >
@@ -184,6 +210,7 @@ export default function SchemaItem(props: Props) {
184
210
{ renderSchemaDescription }
185
211
{ renderEnumDescriptions }
186
212
{ renderQualifierMessage }
213
+ { renderConstValue ( ) }
187
214
{ renderDefaultValue ( ) }
188
215
{ renderExample ( ) }
189
216
{ collapsibleSchemaContent ?? collapsibleSchemaContent }
You can’t perform that action at this time.
0 commit comments