Skip to content

Commit a604750

Browse files
committed
fixed tsc compile & lint for previous commit
1 parent ed46348 commit a604750

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,20 @@
55
* LICENSE file in the root directory of this source tree.
66
* ========================================================================== */
77

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+
}
922

1023
function prettyName(schema: SchemaObject, circular?: boolean) {
1124
if (schema.$ref) {
@@ -26,7 +39,7 @@ function prettyName(schema: SchemaObject, circular?: boolean) {
2639
return schema.xml?.name ?? schema.type;
2740
}
2841

29-
return schema.title ?? schema.type;
42+
return schema.title ?? typeToString(schema.type);
3043
}
3144

3245
export function getSchemaName(

packages/docusaurus-plugin-openapi/src/openapi/createExample.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface OASTypeToTypeMap {
1414
boolean: boolean;
1515
object: any;
1616
array: any[];
17+
null: string;
1718
}
1819

1920
type Primitives = {
@@ -118,17 +119,17 @@ export const sampleFromSchema = (schema: SchemaObject = {}): any => {
118119
return primitive(schema);
119120
};
120121

121-
function primitive(schema: SchemaObject = {}) {
122+
function primitive(schema: SchemaObject = {}): string {
122123
let { type, format } = schema;
123124

124125
if (type instanceof Array) {
125126
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}`), "");
128129
}
129130

130-
if (type === undefined || type === null ) {
131-
return;
131+
if (type === undefined || type === null) {
132+
return "";
132133
}
133134

134135
let fn = primitives[type]?.default;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ export interface ReferenceObject {
308308
}
309309

310310
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
311+
export type PrimitiveSchemaObjectTypes =
312+
| "string"
313+
| "number"
314+
| "integer"
315+
| "boolean"
316+
| "object"
317+
| "array"
318+
| "null";
311319
export type SchemaObject = Omit<
312320
JSONSchema,
313321
| "type"
@@ -320,7 +328,7 @@ export type SchemaObject = Omit<
320328
| "additionalProperties"
321329
> & {
322330
// OpenAPI specific overrides
323-
type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
331+
type?: PrimitiveSchemaObjectTypes | PrimitiveSchemaObjectTypes[];
324332
allOf?: SchemaObject[];
325333
oneOf?: SchemaObject[];
326334
anyOf?: SchemaObject[];

0 commit comments

Comments
 (0)