From 49d44a920f90b0d301535e2d3ce7fc9ebdf5a8c1 Mon Sep 17 00:00:00 2001 From: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> Date: Wed, 16 Mar 2022 09:24:07 -0500 Subject: [PATCH] UI: Parse OpenAPI response correctly if schema includes $ref (#14508) * Parse OpenAPI response correctly if schema includes * Add changelog * small cleanup --- changelog/14508.txt | 3 +++ ui/app/services/path-help.js | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 changelog/14508.txt diff --git a/changelog/14508.txt b/changelog/14508.txt new file mode 100644 index 0000000000..dde6b55ac8 --- /dev/null +++ b/changelog/14508.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: Parse schema refs from OpenAPI +``` \ No newline at end of file diff --git a/ui/app/services/path-help.js b/ui/app/services/path-help.js index b81334e098..cd2f346731 100644 --- a/ui/app/services/path-help.js +++ b/ui/app/services/path-help.js @@ -204,10 +204,18 @@ export default Service.extend({ }; } - // TODO: handle post endpoints without requestBody - const props = pathInfo.post - ? pathInfo.post.requestBody.content['application/json'].schema.properties - : {}; + let props = {}; + const schema = pathInfo?.post?.requestBody?.content['application/json'].schema; + if (schema.$ref) { + // $ref will be shaped like `#/components/schemas/MyResponseType + // which maps to the location of the item within the openApi response + let loc = schema.$ref.replace('#/', '').split('/'); + props = loc.reduce((prev, curr) => { + return prev[curr] || {}; + }, help.openapi).properties; + } else if (schema.properties) { + props = schema.properties; + } // put url params (e.g. {name}, {role}) // at the front of the props list const newProps = assign({}, paramProp, props);