Skip to content

Commit

Permalink
fixed tsc compile & lint for previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
brymko committed Dec 5, 2023
1 parent ed46348 commit a604750
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
17 changes: 15 additions & 2 deletions packages/docusaurus-plugin-openapi/src/markdown/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

import { SchemaObject } from "../openapi/types";
import { SchemaObject, PrimitiveSchemaObjectTypes } from "../openapi/types";

function typeToString(
type: PrimitiveSchemaObjectTypes | PrimitiveSchemaObjectTypes[] | undefined
): string {
if (type === undefined) {
return "schema.type is not defined";
}
if (type instanceof Array) {
return type.reduce((acc, cur) => (acc ? `${acc} | ${cur}` : cur), "");
}

return type;
}

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

return schema.title ?? schema.type;
return schema.title ?? typeToString(schema.type);
}

export function getSchemaName(
Expand Down
11 changes: 6 additions & 5 deletions packages/docusaurus-plugin-openapi/src/openapi/createExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface OASTypeToTypeMap {
boolean: boolean;
object: any;
array: any[];
null: string;
}

type Primitives = {
Expand Down Expand Up @@ -118,17 +119,17 @@ export const sampleFromSchema = (schema: SchemaObject = {}): any => {
return primitive(schema);
};

function primitive(schema: SchemaObject = {}) {
function primitive(schema: SchemaObject = {}): string {
let { type, format } = schema;

if (type instanceof Array) {
return type
.map(type => primitive({ type, format }))
.reduce((acc, cur) => acc ? `${acc} | ${cur}` : `${cur}`, null)
.map((type) => primitive({ type, format }))
.reduce((acc, cur) => (acc ? `${acc} | ${cur}` : `${cur}`), "");
}

if (type === undefined || type === null ) {
return;
if (type === undefined || type === null) {
return "";
}

let fn = primitives[type]?.default;
Expand Down
10 changes: 9 additions & 1 deletion packages/docusaurus-plugin-openapi/src/openapi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ export interface ReferenceObject {
}

export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
export type PrimitiveSchemaObjectTypes =
| "string"
| "number"
| "integer"
| "boolean"
| "object"
| "array"
| "null";
export type SchemaObject = Omit<
JSONSchema,
| "type"
Expand All @@ -320,7 +328,7 @@ export type SchemaObject = Omit<
| "additionalProperties"
> & {
// OpenAPI specific overrides
type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
type?: PrimitiveSchemaObjectTypes | PrimitiveSchemaObjectTypes[];
allOf?: SchemaObject[];
oneOf?: SchemaObject[];
anyOf?: SchemaObject[];
Expand Down

0 comments on commit a604750

Please sign in to comment.