File tree Expand file tree Collapse file tree 3 files changed +30
-8
lines changed
packages/docusaurus-plugin-openapi/src Expand file tree Collapse file tree 3 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 5
5
* LICENSE file in the root directory of this source tree.
6
6
* ========================================================================== */
7
7
8
- import { SchemaObject } from "../openapi/types" ;
8
+ import { SchemaObject , PrimitiveSchemaObjectTypes } from "../openapi/types" ;
9
+
10
+ function typeToString (
11
+ type : PrimitiveSchemaObjectTypes | PrimitiveSchemaObjectTypes [ ] | undefined
12
+ ) : string {
13
+ if ( type === undefined ) {
14
+ return "schema.type is not defined" ;
15
+ }
16
+ if ( type instanceof Array ) {
17
+ return type . reduce ( ( acc , cur ) => ( acc ? `${ acc } | ${ cur } ` : cur ) , "" ) ;
18
+ }
19
+
20
+ return type ;
21
+ }
9
22
10
23
function prettyName ( schema : SchemaObject , circular ?: boolean ) {
11
24
if ( schema . $ref ) {
@@ -26,7 +39,7 @@ function prettyName(schema: SchemaObject, circular?: boolean) {
26
39
return schema . xml ?. name ?? schema . type ;
27
40
}
28
41
29
- return schema . title ?? schema . type ;
42
+ return schema . title ?? typeToString ( schema . type ) ;
30
43
}
31
44
32
45
export function getSchemaName (
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ interface OASTypeToTypeMap {
14
14
boolean : boolean ;
15
15
object : any ;
16
16
array : any [ ] ;
17
+ null : string ;
17
18
}
18
19
19
20
type Primitives = {
@@ -118,17 +119,17 @@ export const sampleFromSchema = (schema: SchemaObject = {}): any => {
118
119
return primitive ( schema ) ;
119
120
} ;
120
121
121
- function primitive ( schema : SchemaObject = { } ) {
122
+ function primitive ( schema : SchemaObject = { } ) : string {
122
123
let { type, format } = schema ;
123
124
124
125
if ( type instanceof Array ) {
125
126
return type
126
- . map ( type => primitive ( { type, format } ) )
127
- . reduce ( ( acc , cur ) => acc ? `${ acc } | ${ cur } ` : `${ cur } ` , null )
127
+ . map ( ( type ) => primitive ( { type, format } ) )
128
+ . reduce ( ( acc , cur ) => ( acc ? `${ acc } | ${ cur } ` : `${ cur } ` ) , "" ) ;
128
129
}
129
130
130
- if ( type === undefined || type === null ) {
131
- return ;
131
+ if ( type === undefined || type === null ) {
132
+ return "" ;
132
133
}
133
134
134
135
let fn = primitives [ type ] ?. default ;
Original file line number Diff line number Diff line change @@ -308,6 +308,14 @@ export interface ReferenceObject {
308
308
}
309
309
310
310
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7 ;
311
+ export type PrimitiveSchemaObjectTypes =
312
+ | "string"
313
+ | "number"
314
+ | "integer"
315
+ | "boolean"
316
+ | "object"
317
+ | "array"
318
+ | "null" ;
311
319
export type SchemaObject = Omit <
312
320
JSONSchema ,
313
321
| "type"
@@ -320,7 +328,7 @@ export type SchemaObject = Omit<
320
328
| "additionalProperties"
321
329
> & {
322
330
// OpenAPI specific overrides
323
- type ?: "string" | "number" | "integer" | "boolean" | "object" | "array" ;
331
+ type ?: PrimitiveSchemaObjectTypes | PrimitiveSchemaObjectTypes [ ] ;
324
332
allOf ?: SchemaObject [ ] ;
325
333
oneOf ?: SchemaObject [ ] ;
326
334
anyOf ?: SchemaObject [ ] ;
You can’t perform that action at this time.
0 commit comments