UI: Parse OpenAPI response correctly if schema includes $ref (#14508)

* Parse OpenAPI response correctly if schema includes

* Add changelog

* small cleanup
This commit is contained in:
Chelsea Shaw 2022-03-16 09:24:07 -05:00 committed by GitHub
parent 9e18350cf4
commit a5a6d99d11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

3
changelog/14508.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
ui: Parse schema refs from OpenAPI
```

View File

@ -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);