From c1007a287b2ed3e4d1b00febcb24a13aa275559c Mon Sep 17 00:00:00 2001 From: kyle Date: Wed, 16 May 2018 22:48:44 -0700 Subject: [PATCH] feature: OAS3 object parameter support (#4563) * render suitable interface for `type: object` parameters * validate OAS3 object parameters correctly * display parameter validation errors * remove irrelevant css classes * rm comment * fix failing tests * add validateParam tests * add enzyme tests for object parameter rendering * run actual tests first --- package.json | 2 +- src/core/json-schema-components.js | 52 ++++++++++++++++ src/core/utils.js | 25 +++++++- src/style/_form.scss | 3 +- test/components/json-schema-form.js | 39 +++++++++++- test/core/utils.js | 97 ++++++++++++++++++++++++++++- 6 files changed, 209 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 7186fc61..ec00dc89 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "lint": "eslint --cache --ext '.js,.jsx' src test", "lint-errors": "eslint --cache --quiet --ext '.js,.jsx' src test", "lint-fix": "eslint --cache --ext '.js,.jsx' src test --fix", - "test": "npm run lint-errors && npm run just-test-in-node", + "test": "npm run just-test-in-node && npm run lint-errors", "test-in-node": "npm run lint-errors && npm run just-test-in-node", "just-test": "karma start --config karma.conf.js", "just-test-in-node": "mocha --require test/setup.js --recursive --compilers js:babel-core/register test/core test/components test/bugs test/swagger-ui-dist-package test/xss", diff --git a/src/core/json-schema-components.js b/src/core/json-schema-components.js index 14998feb..8d7f3a3b 100644 --- a/src/core/json-schema-components.js +++ b/src/core/json-schema-components.js @@ -1,8 +1,10 @@ import React, { PureComponent, Component } from "react" import PropTypes from "prop-types" import { List, fromJS } from "immutable" +import cx from "classnames" import ImPropTypes from "react-immutable-proptypes" import DebounceInput from "react-debounce-input" +import { getSampleSchema } from "core/utils" //import "less/json-schema-form" const noop = ()=> {} @@ -204,3 +206,53 @@ export class JsonSchema_boolean extends Component { onChange={ this.onEnumChange }/>) } } + +export class JsonSchema_object extends PureComponent { + constructor() { + super() + } + + static propTypes = JsonSchemaPropShape + static defaultProps = JsonSchemaDefaultProps + + componentDidMount() { + if(!this.props.value && this.props.schema) { + this.resetValueToSample() + } + } + + resetValueToSample = () => { + this.onChange(getSampleSchema(this.props.schema) ) + } + + onChange = (value) => { + this.props.onChange(value) + } + + handleOnChange = e => { + const inputValue = e.target.value + + this.onChange(inputValue) + } + + render() { + let { + getComponent, + value, + errors + } = this.props + + const TextArea = getComponent("TextArea") + + return ( +
+