Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
}),
create("ul", {
style: { marginLeft: "1rem" },
children: createNodes(firstBody),
children: createNodes(firstBody, "request"),
}),
],
}),
Expand Down Expand Up @@ -161,7 +161,7 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
}),
create("ul", {
style: { marginLeft: "1rem" },
children: createNodes(firstBody),
children: createNodes(firstBody, "request"),
}),
],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function createResponseSchema({ title, body, ...rest }: Props) {
}),
create("ul", {
style: { marginLeft: "1rem" },
children: createNodes(firstBody!),
children: createNodes(firstBody!, "response"),
}),
],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("createNodes", () => {
},
};
expect(
createNodes(schema).map((md: any) =>
createNodes(schema, "request").map((md: any) =>
prettier.format(md, { parser: "babel" })
)
).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { create, guard } from "./utils";

const jsonSchemaMergeAllOf = require("json-schema-merge-allof");

let SCHEMA_TYPE: "request" | "response";

/**
* Returns a merged representation of allOf array of schemas.
*/
Expand All @@ -29,6 +31,9 @@ export function mergeAllOf(allOf: SchemaObject[]) {
readOnly: function () {
return true;
},
writeOnly: function () {
return true;
},
example: function () {
return true;
},
Expand Down Expand Up @@ -74,7 +79,7 @@ function createAnyOneOf(schema: SchemaObject): any {
}

if (anyOneSchema.allOf !== undefined) {
anyOneChildren.push(createNodes(anyOneSchema));
anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
delete anyOneSchema.allOf;
}

Expand All @@ -89,7 +94,7 @@ function createAnyOneOf(schema: SchemaObject): any {
anyOneSchema.type === "integer" ||
anyOneSchema.type === "boolean"
) {
anyOneChildren.push(createNodes(anyOneSchema));
anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
}
if (anyOneChildren.length) {
if (schema.type === "array") {
Expand Down Expand Up @@ -304,7 +309,7 @@ function createItems(schema: SchemaObject) {
) {
return [
createOpeningArrayBracket(),
createNodes(schema.items),
createNodes(schema.items, SCHEMA_TYPE),
createClosingArrayBracket(),
].flat();
}
Expand Down Expand Up @@ -411,7 +416,7 @@ function createDetailsNode(
children: createDescription(description),
})
),
createNodes(schema),
createNodes(schema, SCHEMA_TYPE),
],
}),
],
Expand Down Expand Up @@ -565,7 +570,7 @@ function createPropertyDiscriminator(
// className: "openapi-tabs__discriminator-item",
label: label,
value: `${index}-item-discriminator`,
children: [createNodes(discriminator?.mapping[key])],
children: [createNodes(discriminator?.mapping[key], SCHEMA_TYPE)],
});
}),
}),
Expand Down Expand Up @@ -664,8 +669,16 @@ function createEdges({
);
}

if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
return undefined;
if (SCHEMA_TYPE === "request") {
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
return undefined;
}
}

if (SCHEMA_TYPE === "response") {
if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
return undefined;
}
}

return create("SchemaItem", {
Expand Down Expand Up @@ -719,8 +732,16 @@ function createEdges({
);
}

if (schema.readOnly && schema.readOnly === true) {
return undefined;
if (SCHEMA_TYPE === "request") {
if (schema.readOnly && schema.readOnly === true) {
return undefined;
}
}

if (SCHEMA_TYPE === "response") {
if (schema.writeOnly && schema.writeOnly === true) {
return undefined;
}
}

// primitives and array of non-objects
Expand All @@ -737,7 +758,11 @@ function createEdges({
/**
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
*/
export function createNodes(schema: SchemaObject): any {
export function createNodes(
schema: SchemaObject,
schemaType: "request" | "response"
): any {
SCHEMA_TYPE = schemaType;
const nodes = [];
// if (schema.discriminator !== undefined) {
// return createDiscriminator(schema);
Expand Down