Skip to content

Commit

Permalink
fix(swagger): display request body model in execution mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Sep 2, 2024
1 parent 05ad7e8 commit d2316a6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { wrapJsonschemaStringArrayComponent } from "../form/wrap-jsonschema-stri
import OperationSummary from "../operations/operation-summary.component";
import OperationTag from "../operations/operation-tag.component";
import { updateFields } from "../operations/reducers/update-fields.reducer.js";
import { wrapRequestBody } from "../operations/request-body.component";
import { wrapResponseBody } from "../operations/response-body.component";
import { wrapClear } from "../operations/wrap-clear";
import { wrapExecute } from "../operations/wrap-execute";
Expand Down Expand Up @@ -42,6 +43,7 @@ export const BaseLayoutPlugin = (system: System) => {
execute: wrapExecute,
clear: wrapClear,
responseBody: wrapResponseBody,
RequestBody: wrapRequestBody,
JsonSchema_string: wrapJsonschemaStringComponent,
JsonSchema_array: wrapJsonschemaStringArrayComponent
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { OrderedMap } from "immutable";
import { FunctionComponent } from "react";

import type { System } from "../../interfaces/System";

export function wrapRequestBody(Base: FunctionComponent<Record<string, unknown>>) {
return (props: System & { requestBody?: any; contentType: any; specPath: any }) => {
const { getComponent, requestBody, specPath } = props;
const ModelExample = getComponent("modelExample");
const requestBodyContent = requestBody?.get("content") ?? OrderedMap();
const contentType = props.contentType || requestBodyContent.keySeq().first() || "";
const mediaTypeValue = requestBodyContent.get(contentType) ?? OrderedMap();

return (
<ModelExample
{...props}
expandDepth={1}
isExecute={true}
schema={mediaTypeValue.get("schema")}
specPath={specPath.push("content", contentType)}
example={<Base {...props} />}
includeWriteOnly={true}
/>
);
};
}

0 comments on commit d2316a6

Please sign in to comment.