Procházet zdrojové kódy

fix: multipart array sample generation for items (#6461)

* json schema array component should use schema to generate example in case of array items.
* empty value checkbox should be disabled if not empty => not empty list || not empty string
* curl should also check for not empty list
bubble
Mahtis Michel před 4 roky
committed by GitHub
rodič
revize
f4bdf2f953
V databázi nebyl nalezen žádný známý klíč pro tento podpis ID GPG klíče: 4AEE18F83AFDEB23
6 změnil soubory, kde provedl 35 přidání a 19 odebrání
  1. +8
    -3
      src/core/json-schema-components.jsx
  2. +9
    -5
      src/core/plugins/oas3/components/request-body.jsx
  3. +4
    -1
      src/core/plugins/spec/actions.js
  4. +4
    -0
      test/e2e-cypress/tests/features/oas3-request-body-allow-empty-values.js
  5. +1
    -1
      test/e2e-cypress/tests/features/oas3-request-body-required.js
  6. +9
    -9
      test/e2e-cypress/tests/features/schema-form.js

+ 8
- 3
src/core/json-schema-components.jsx Zobrazit soubor

@@ -4,7 +4,7 @@ import { List, fromJS } from "immutable"
import cx from "classnames"
import ImPropTypes from "react-immutable-proptypes"
import DebounceInput from "react-debounce-input"
import { stringify } from "core/utils"
import { stringify, getSampleSchema } from "core/utils"
//import "less/json-schema-form"

const noop = ()=> {}
@@ -125,12 +125,15 @@ export class JsonSchema_array extends PureComponent {

constructor(props, context) {
super(props, context)
this.state = { value: valueOrEmptyList(props.value) }
this.state = { value: valueOrEmptyList(props.value), schema: props.schema}
}

componentWillReceiveProps(props) {
if(props.value !== this.state.value)
this.setState({ value: props.value })

if(props.schema !== this.state.schema)
this.setState({ schema: props.schema })
}

onChange = () => {
@@ -152,7 +155,9 @@ export class JsonSchema_array extends PureComponent {
addItem = () => {
let newValue = valueOrEmptyList(this.state.value)
this.setState(() => ({
value: newValue.push("")
value: newValue.push(getSampleSchema(this.state.schema.get("items"), false, {
includeWriteOnly: true
}))
}), this.onChange)
}



+ 9
- 5
src/core/plugins/oas3/components/request-body.jsx Zobrazit soubor

@@ -145,10 +145,14 @@ const RequestBody = ({

let initialValue = prop.get("default") || prop.get("example") || ""

if (initialValue === "" && type === "object") {
initialValue = getSampleSchema(prop, false, {
includeWriteOnly: true
})
if (initialValue === "") {
if(type === "object") {
initialValue = getSampleSchema(prop, false, {
includeWriteOnly: true
})
} else if(type === "array") {
initialValue = []
}
}

if (typeof initialValue !== "string" && type === "object") {
@@ -193,7 +197,7 @@ const RequestBody = ({
onChange={(value) => onChangeIncludeEmpty(key, value)}
isIncluded={requestBodyInclusionSetting.get(key) || false}
isIncludedOptions={setIsIncludedOptions(key)}
isDisabled={!isEmptyValue(currentValue)}
isDisabled={Array.isArray(currentValue) ? currentValue.length !== 0 : !isEmptyValue(currentValue)}
/>
)}
</div> : null }


+ 4
- 1
src/core/plugins/spec/actions.js Zobrazit soubor

@@ -416,7 +416,10 @@ export const executeRequest = (req) =>
}
)
.filter(
(value, key) => !isEmptyValue(value) || requestBodyInclusionSetting.get(key)
(value, key) => (Array.isArray(value)
? value.length !== 0
: !isEmptyValue(value)
) || requestBodyInclusionSetting.get(key)
)
.toJS()
} else{


+ 4
- 0
test/e2e-cypress/tests/features/oas3-request-body-allow-empty-values.js Zobrazit soubor

@@ -97,6 +97,8 @@ describe("OpenAPI 3.0 Allow Empty Values in Request Body", () => {
// add item to pass required validation
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button")
.click()
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) input")
.clear()
// Execute
.get(".execute.opblock-control__btn")
.click()
@@ -127,6 +129,8 @@ describe("OpenAPI 3.0 Allow Empty Values in Request Body", () => {
// add item to pass required validation
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button")
.click()
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) input")
.clear()
// Execute
.get(".execute.opblock-control__btn")
.click()


+ 1
- 1
test/e2e-cypress/tests/features/oas3-request-body-required.js Zobrazit soubor

@@ -149,7 +149,7 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
.should("have.value", "doggie")
.should("not.have.class", "invalid")
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description input")
.should("have.value", "")
.should("have.value", "string")
.should("not.have.class", "invalid")
// cURL component should exist
.get(".responses-wrapper .curl-command")


+ 9
- 9
test/e2e-cypress/tests/features/schema-form.js Zobrazit soubor

@@ -305,7 +305,7 @@ describe("OpenAPI 3.0 Additional JsonSchemaForm in a Parameter", () => {
.get(".json-schema-form-item-add")
.click()
.get(".json-schema-form-item > input")
.type("spotted")
.type("{selectall}spotted")
// Assert against the input fields
.get(".json-schema-form-item > input")
.then(inputs => {
@@ -327,7 +327,7 @@ describe("OpenAPI 3.0 Additional JsonSchemaForm in a Parameter", () => {
.get(".json-schema-form-item-add")
.click()
.get(".json-schema-form-item:last-of-type > input")
.type("spotted")
.type("{selectall}spotted")
// Assert against the input fields
.get(".json-schema-form-item > input")
.then(inputs => {
@@ -354,7 +354,7 @@ describe("OpenAPI 3.0 Additional JsonSchemaForm in a Parameter", () => {
.get(".json-schema-form-item-add")
.click()
.get(".json-schema-form-item:last-of-type > input")
.type("spotted")
.type("{selectall}spotted")
// Assert against the input fields
.get(".json-schema-form-item > input")
.then(inputs => {
@@ -366,7 +366,7 @@ describe("OpenAPI 3.0 Additional JsonSchemaForm in a Parameter", () => {
.get(".json-schema-form-item-add")
.click()
.get(".json-schema-form-item:last-of-type > input")
.type("large")
.type("{selectall}large")
// Assert against the input fields
.get(".json-schema-form-item > input")
.then(inputs => {
@@ -379,7 +379,7 @@ describe("OpenAPI 3.0 Additional JsonSchemaForm in a Parameter", () => {
.get(".json-schema-form-item-add")
.click()
.get(".json-schema-form-item:last-of-type > input")
.type("puppy")
.type("{selectall}puppy")
// Assert against the input fields
.get(".json-schema-form-item > input")
.then(inputs => {
@@ -454,7 +454,7 @@ describe("OpenAPI 3.0 Additional JsonSchemaForm in a Parameter", () => {
.get(".json-schema-form-item-add")
.click()
.get(".json-schema-form-item > input")
.type("spotted")
.type("{selectall}spotted")
// Assert against the input fields
.get(".json-schema-form-item > input")
.then(inputs => {
@@ -485,7 +485,7 @@ describe("OpenAPI 3.0 Additional JsonSchemaForm in a Parameter", () => {
.get(".json-schema-form-item-add")
.click()
.get(".json-schema-form-item:last-of-type > input")
.type("spotted")
.type("{selectall}spotted")
// Assert against the input fields
.get(".json-schema-form-item > input")
.then(inputs => {
@@ -497,7 +497,7 @@ describe("OpenAPI 3.0 Additional JsonSchemaForm in a Parameter", () => {
.get(".json-schema-form-item-add")
.click()
.get(".json-schema-form-item:last-of-type > input")
.type("large")
.type("{selectall}large")
// Assert against the input fields
.get(".json-schema-form-item > input")
.then(inputs => {
@@ -510,7 +510,7 @@ describe("OpenAPI 3.0 Additional JsonSchemaForm in a Parameter", () => {
.get(".json-schema-form-item-add")
.click()
.get(".json-schema-form-item:last-of-type > input")
.type("puppy")
.type("{selectall}puppy")
// Assert against the input fields
.get(".json-schema-form-item > input")
.then(inputs => {


Načítá se…
Zrušit
Uložit