committed by
Vladimír Gorej
parent
1ce9ce0cda
commit
2ce9d08af7
@@ -175,7 +175,7 @@ const RequestBody = ({
|
|||||||
}
|
}
|
||||||
if (type === "object" || useInitialValue) {
|
if (type === "object" || useInitialValue) {
|
||||||
// TODO: what about example or examples from requestBody could be passed as exampleOverride
|
// TODO: what about example or examples from requestBody could be passed as exampleOverride
|
||||||
initialValue = getSampleSchema(prop, false, {
|
initialValue = fn.getSampleSchema(prop, false, {
|
||||||
includeWriteOnly: true
|
includeWriteOnly: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -242,6 +242,7 @@ const RequestBody = ({
|
|||||||
requestBody,
|
requestBody,
|
||||||
contentType,
|
contentType,
|
||||||
activeExamplesKey,
|
activeExamplesKey,
|
||||||
|
fn,
|
||||||
)
|
)
|
||||||
let language = null
|
let language = null
|
||||||
let testValueForJson = getKnownSyntaxHighlighterLanguage(sampleRequestBody)
|
let testValueForJson = getKnownSyntaxHighlighterLanguage(sampleRequestBody)
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export const selectDefaultRequestBodyValue =
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const hasUserEditedBody = onlyOAS3((state, path, method) => (system) => {
|
export const hasUserEditedBody = onlyOAS3((state, path, method) => (system) => {
|
||||||
const { oas3Selectors, specSelectors } = system
|
const { oas3Selectors, specSelectors, fn } = system
|
||||||
|
|
||||||
let userHasEditedBody = false
|
let userHasEditedBody = false
|
||||||
const currentMediaType = oas3Selectors.requestContentType(path, method)
|
const currentMediaType = oas3Selectors.requestContentType(path, method)
|
||||||
@@ -147,7 +147,8 @@ export const hasUserEditedBody = onlyOAS3((state, path, method) => (system) => {
|
|||||||
method,
|
method,
|
||||||
"requestBody",
|
"requestBody",
|
||||||
"requestBody"
|
"requestBody"
|
||||||
)
|
),
|
||||||
|
fn
|
||||||
)
|
)
|
||||||
userHasEditedBody =
|
userHasEditedBody =
|
||||||
!!userEditedRequestBody &&
|
!!userEditedRequestBody &&
|
||||||
|
|||||||
@@ -1,78 +1,128 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { List, fromJS } from "immutable"
|
import { List, fromJS } from "immutable"
|
||||||
|
|
||||||
import { render } from "enzyme"
|
import { render } from "enzyme"
|
||||||
|
|
||||||
import ParameterRow from "components/parameter-row"
|
import ParameterRow from "components/parameter-row"
|
||||||
|
import {
|
||||||
|
memoizedSampleFromSchema,
|
||||||
|
memoizedCreateXMLExample,
|
||||||
|
} from "core/plugins/samples/fn/index"
|
||||||
|
import makeGetSampleSchema from "core/plugins/samples/fn/get-sample-schema"
|
||||||
|
import makeGetJsonSampleSchema from "core/plugins/samples/fn/get-json-sample-schema"
|
||||||
|
import makeGetYamlSampleSchema from "core/plugins/samples/fn/get-yaml-sample-schema"
|
||||||
|
import makeGetXmlSampleSchema from "core/plugins/samples/fn/get-xml-sample-schema"
|
||||||
|
|
||||||
describe("bug #4557: default parameter values", function () {
|
describe("bug #4557: default parameter values", function () {
|
||||||
it("should apply a Swagger 2.0 default value", function () {
|
it("should apply a Swagger 2.0 default value", function () {
|
||||||
|
|
||||||
const paramValue = fromJS({
|
const paramValue = fromJS({
|
||||||
description: "a pet",
|
description: "a pet",
|
||||||
type: "string",
|
type: "string",
|
||||||
default: "MyDefaultValue"
|
default: "MyDefaultValue",
|
||||||
})
|
})
|
||||||
|
const getSystem = () => ({
|
||||||
let props = {
|
|
||||||
getComponent: () => "div",
|
getComponent: () => "div",
|
||||||
specSelectors: {
|
specSelectors: {
|
||||||
security() {},
|
security() {},
|
||||||
parameterWithMetaByIdentity(){ return paramValue },
|
parameterWithMetaByIdentity() {
|
||||||
isOAS3(){ return false },
|
return paramValue
|
||||||
isSwagger2(){ return true }
|
|
||||||
},
|
},
|
||||||
fn: {},
|
isOAS3() {
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
isSwagger2() {
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
getConfigs: () => {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
fn: {
|
||||||
|
memoizedSampleFromSchema,
|
||||||
|
memoizedCreateXMLExample,
|
||||||
|
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
|
||||||
|
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
|
||||||
|
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
|
||||||
|
getSampleSchema: makeGetSampleSchema(getSystem),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const props = {
|
||||||
|
...getSystem(),
|
||||||
operation: { get: () => {} },
|
operation: { get: () => {} },
|
||||||
onChange: jest.fn(),
|
onChange: jest.fn(),
|
||||||
param: paramValue,
|
param: paramValue,
|
||||||
rawParam: paramValue,
|
rawParam: paramValue,
|
||||||
onChangeConsumes: () => {},
|
onChangeConsumes: () => {},
|
||||||
pathMethod: [],
|
pathMethod: [],
|
||||||
getConfigs: () => { return {} },
|
specPath: List([]),
|
||||||
specPath: List([])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render(<ParameterRow {...props} />)
|
render(<ParameterRow {...props} />)
|
||||||
|
|
||||||
expect(props.onChange).toHaveBeenCalled()
|
expect(props.onChange).toHaveBeenCalled()
|
||||||
expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue", false)
|
expect(props.onChange).toHaveBeenCalledWith(
|
||||||
|
paramValue,
|
||||||
|
"MyDefaultValue",
|
||||||
|
false
|
||||||
|
)
|
||||||
})
|
})
|
||||||
it("should apply an OpenAPI 3.0 default value", function () {
|
it("should apply an OpenAPI 3.0 default value", function () {
|
||||||
|
|
||||||
const paramValue = fromJS({
|
const paramValue = fromJS({
|
||||||
description: "a pet",
|
description: "a pet",
|
||||||
schema: {
|
schema: {
|
||||||
type: "string",
|
type: "string",
|
||||||
default: "MyDefaultValue"
|
default: "MyDefaultValue",
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
const getSystem = () => ({
|
||||||
let props = {
|
|
||||||
getComponent: () => "div",
|
getComponent: () => "div",
|
||||||
specSelectors: {
|
specSelectors: {
|
||||||
security() {},
|
security() {},
|
||||||
parameterWithMetaByIdentity(){ return paramValue },
|
parameterWithMetaByIdentity() {
|
||||||
isOAS3(){ return true },
|
return paramValue
|
||||||
isSwagger2() { return false }
|
},
|
||||||
|
isOAS3() {
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
isSwagger2() {
|
||||||
|
return false
|
||||||
|
},
|
||||||
},
|
},
|
||||||
oas3Selectors: {
|
oas3Selectors: {
|
||||||
activeExamplesMember: () => null
|
activeExamplesMember: () => null,
|
||||||
},
|
},
|
||||||
fn: {},
|
getConfigs: () => {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
fn: {
|
||||||
|
memoizedSampleFromSchema,
|
||||||
|
memoizedCreateXMLExample,
|
||||||
|
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
|
||||||
|
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
|
||||||
|
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
|
||||||
|
getSampleSchema: makeGetSampleSchema(getSystem),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const props = {
|
||||||
|
...getSystem(),
|
||||||
operation: { get: () => {} },
|
operation: { get: () => {} },
|
||||||
onChange: jest.fn(),
|
onChange: jest.fn(),
|
||||||
param: paramValue,
|
param: paramValue,
|
||||||
rawParam: paramValue,
|
rawParam: paramValue,
|
||||||
onChangeConsumes: () => {},
|
onChangeConsumes: () => {},
|
||||||
pathMethod: [],
|
pathMethod: [],
|
||||||
getConfigs: () => { return {} },
|
specPath: List([]),
|
||||||
specPath: List([])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render(<ParameterRow {...props} />)
|
render(<ParameterRow {...props} />)
|
||||||
|
|
||||||
expect(props.onChange).toHaveBeenCalled()
|
expect(props.onChange).toHaveBeenCalled()
|
||||||
expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue", false)
|
expect(props.onChange).toHaveBeenCalledWith(
|
||||||
|
paramValue,
|
||||||
|
"MyDefaultValue",
|
||||||
|
false
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,22 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { List, fromJS } from "immutable"
|
import { List, fromJS } from "immutable"
|
||||||
import { render } from "enzyme"
|
import { render } from "enzyme"
|
||||||
|
|
||||||
import ParameterRow from "components/parameter-row"
|
import ParameterRow from "components/parameter-row"
|
||||||
|
import {
|
||||||
|
memoizedSampleFromSchema,
|
||||||
|
memoizedCreateXMLExample,
|
||||||
|
} from "core/plugins/samples/fn/index"
|
||||||
|
import makeGetSampleSchema from "core/plugins/samples/fn/get-sample-schema"
|
||||||
|
import makeGetJsonSampleSchema from "core/plugins/samples/fn/get-json-sample-schema"
|
||||||
|
import makeGetYamlSampleSchema from "core/plugins/samples/fn/get-yaml-sample-schema"
|
||||||
|
import makeGetXmlSampleSchema from "core/plugins/samples/fn/get-xml-sample-schema"
|
||||||
|
|
||||||
describe("<ParameterRow/>", () => {
|
describe("<ParameterRow/>", () => {
|
||||||
const createProps = ({ param, isOAS3 }) => ({
|
const createProps = ({ param, isOAS3 }) => {
|
||||||
|
const getSystem = () => ({
|
||||||
getComponent: () => "div",
|
getComponent: () => "div",
|
||||||
specSelectors: {
|
specSelectors: {
|
||||||
parameterWithMetaByIdentity: () => param,
|
parameterWithMetaByIdentity: () => param,
|
||||||
isOAS3: () => isOAS3,
|
isOAS3: () => isOAS3,
|
||||||
isSwagger2: () => !isOAS3
|
isSwagger2: () => !isOAS3,
|
||||||
|
},
|
||||||
|
fn: {
|
||||||
|
memoizedSampleFromSchema,
|
||||||
|
memoizedCreateXMLExample,
|
||||||
|
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
|
||||||
|
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
|
||||||
|
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
|
||||||
|
getSampleSchema: makeGetSampleSchema(getSystem),
|
||||||
},
|
},
|
||||||
oas3Selectors: { activeExamplesMember: () => {} },
|
oas3Selectors: { activeExamplesMember: () => {} },
|
||||||
|
getConfigs: () => ({}),
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
...getSystem(),
|
||||||
param,
|
param,
|
||||||
rawParam: param,
|
rawParam: param,
|
||||||
pathMethod: [],
|
pathMethod: [],
|
||||||
getConfigs: () => ({})
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
it("Can render Swagger 2 parameter type with format", () => {
|
it("Can render Swagger 2 parameter type with format", () => {
|
||||||
const param = fromJS({
|
const param = fromJS({
|
||||||
@@ -24,7 +50,7 @@ describe("<ParameterRow/>", () => {
|
|||||||
in: "path",
|
in: "path",
|
||||||
description: "UUID that identifies a pet",
|
description: "UUID that identifies a pet",
|
||||||
type: "string",
|
type: "string",
|
||||||
format: "uuid"
|
format: "uuid",
|
||||||
})
|
})
|
||||||
|
|
||||||
const props = createProps({ param, isOAS3: false })
|
const props = createProps({ param, isOAS3: false })
|
||||||
@@ -39,7 +65,7 @@ describe("<ParameterRow/>", () => {
|
|||||||
name: "petId",
|
name: "petId",
|
||||||
in: "path",
|
in: "path",
|
||||||
description: "ID that identifies a pet",
|
description: "ID that identifies a pet",
|
||||||
type: "string"
|
type: "string",
|
||||||
})
|
})
|
||||||
|
|
||||||
const props = createProps({ param, isOAS3: false })
|
const props = createProps({ param, isOAS3: false })
|
||||||
@@ -54,7 +80,7 @@ describe("<ParameterRow/>", () => {
|
|||||||
name: "hasId",
|
name: "hasId",
|
||||||
in: "path",
|
in: "path",
|
||||||
description: "boolean value to indicate if the pet has an id",
|
description: "boolean value to indicate if the pet has an id",
|
||||||
type: "boolean"
|
type: "boolean",
|
||||||
})
|
})
|
||||||
|
|
||||||
const props = createProps({ param, isOAS3: false })
|
const props = createProps({ param, isOAS3: false })
|
||||||
@@ -71,8 +97,8 @@ describe("<ParameterRow/>", () => {
|
|||||||
description: "UUID that identifies a pet",
|
description: "UUID that identifies a pet",
|
||||||
schema: {
|
schema: {
|
||||||
type: "string",
|
type: "string",
|
||||||
format: "uuid"
|
format: "uuid",
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const props = createProps({ param, isOAS3: true })
|
const props = createProps({ param, isOAS3: true })
|
||||||
@@ -88,8 +114,8 @@ describe("<ParameterRow/>", () => {
|
|||||||
in: "path",
|
in: "path",
|
||||||
description: "ID that identifies a pet",
|
description: "ID that identifies a pet",
|
||||||
schema: {
|
schema: {
|
||||||
type: "string"
|
type: "string",
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const props = createProps({ param, isOAS3: true })
|
const props = createProps({ param, isOAS3: true })
|
||||||
@@ -105,8 +131,8 @@ describe("<ParameterRow/>", () => {
|
|||||||
in: "path",
|
in: "path",
|
||||||
description: "boolean value to indicate if the pet has an id",
|
description: "boolean value to indicate if the pet has an id",
|
||||||
schema: {
|
schema: {
|
||||||
type: "boolean"
|
type: "boolean",
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const props = createProps({ param, isOAS3: true })
|
const props = createProps({ param, isOAS3: true })
|
||||||
@@ -122,26 +148,42 @@ describe("bug #5573: zero default and example values", function () {
|
|||||||
const paramValue = fromJS({
|
const paramValue = fromJS({
|
||||||
description: "a pet",
|
description: "a pet",
|
||||||
type: "integer",
|
type: "integer",
|
||||||
default: 0
|
default: 0,
|
||||||
})
|
})
|
||||||
|
const getSystem = () => ({
|
||||||
let props = {
|
|
||||||
getComponent: () => "div",
|
getComponent: () => "div",
|
||||||
specSelectors: {
|
specSelectors: {
|
||||||
security() {},
|
security() {},
|
||||||
parameterWithMetaByIdentity() { return paramValue },
|
parameterWithMetaByIdentity() {
|
||||||
isOAS3() { return false },
|
return paramValue
|
||||||
isSwagger2() { return true }
|
|
||||||
},
|
},
|
||||||
fn: {},
|
isOAS3() {
|
||||||
operation: { get: () => { } },
|
return false
|
||||||
|
},
|
||||||
|
isSwagger2() {
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fn: {
|
||||||
|
memoizedSampleFromSchema,
|
||||||
|
memoizedCreateXMLExample,
|
||||||
|
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
|
||||||
|
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
|
||||||
|
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
|
||||||
|
getSampleSchema: makeGetSampleSchema(getSystem),
|
||||||
|
},
|
||||||
|
getConfigs: () => {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const props = {
|
||||||
|
...getSystem(),
|
||||||
onChange: jest.fn(),
|
onChange: jest.fn(),
|
||||||
param: paramValue,
|
param: paramValue,
|
||||||
rawParam: paramValue,
|
rawParam: paramValue,
|
||||||
onChangeConsumes: () => {},
|
onChangeConsumes: () => {},
|
||||||
pathMethod: [],
|
pathMethod: [],
|
||||||
getConfigs: () => { return {} },
|
specPath: List([]),
|
||||||
specPath: List([])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render(<ParameterRow {...props} />)
|
render(<ParameterRow {...props} />)
|
||||||
@@ -154,27 +196,44 @@ describe("bug #5573: zero default and example values", function () {
|
|||||||
description: "a pet",
|
description: "a pet",
|
||||||
type: "integer",
|
type: "integer",
|
||||||
schema: {
|
schema: {
|
||||||
example: 0
|
example: 0,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
const getSystem = () => ({
|
||||||
let props = {
|
|
||||||
getComponent: () => "div",
|
getComponent: () => "div",
|
||||||
specSelectors: {
|
specSelectors: {
|
||||||
security() {},
|
security() {},
|
||||||
parameterWithMetaByIdentity() { return paramValue },
|
parameterWithMetaByIdentity() {
|
||||||
isOAS3() { return false },
|
return paramValue
|
||||||
isSwagger2() { return true }
|
|
||||||
},
|
},
|
||||||
fn: {},
|
isOAS3() {
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
isSwagger2() {
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
getConfigs: () => {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
fn: {
|
||||||
|
memoizedSampleFromSchema,
|
||||||
|
memoizedCreateXMLExample,
|
||||||
|
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
|
||||||
|
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
|
||||||
|
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
|
||||||
|
getSampleSchema: makeGetSampleSchema(getSystem),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const props = {
|
||||||
|
...getSystem(),
|
||||||
operation: { get: () => {} },
|
operation: { get: () => {} },
|
||||||
onChange: jest.fn(),
|
onChange: jest.fn(),
|
||||||
param: paramValue,
|
param: paramValue,
|
||||||
rawParam: paramValue,
|
rawParam: paramValue,
|
||||||
onChangeConsumes: () => {},
|
onChangeConsumes: () => {},
|
||||||
pathMethod: [],
|
pathMethod: [],
|
||||||
getConfigs: () => { return {} },
|
specPath: List([]),
|
||||||
specPath: List([])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render(<ParameterRow {...props} />)
|
render(<ParameterRow {...props} />)
|
||||||
@@ -187,30 +246,47 @@ describe("bug #5573: zero default and example values", function () {
|
|||||||
description: "a pet",
|
description: "a pet",
|
||||||
schema: {
|
schema: {
|
||||||
type: "integer",
|
type: "integer",
|
||||||
default: 0
|
default: 0,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
const getSystem = () => ({
|
||||||
let props = {
|
|
||||||
getComponent: () => "div",
|
getComponent: () => "div",
|
||||||
specSelectors: {
|
specSelectors: {
|
||||||
security() {},
|
security() {},
|
||||||
parameterWithMetaByIdentity() { return paramValue },
|
parameterWithMetaByIdentity() {
|
||||||
isOAS3() { return true },
|
return paramValue
|
||||||
isSwagger2() { return false }
|
},
|
||||||
|
isOAS3() {
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
isSwagger2() {
|
||||||
|
return false
|
||||||
|
},
|
||||||
},
|
},
|
||||||
oas3Selectors: {
|
oas3Selectors: {
|
||||||
activeExamplesMember: () => null
|
activeExamplesMember: () => null,
|
||||||
},
|
},
|
||||||
fn: {},
|
getConfigs: () => {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
fn: {
|
||||||
|
memoizedSampleFromSchema,
|
||||||
|
memoizedCreateXMLExample,
|
||||||
|
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
|
||||||
|
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
|
||||||
|
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
|
||||||
|
getSampleSchema: makeGetSampleSchema(getSystem),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const props = {
|
||||||
|
...getSystem(),
|
||||||
operation: { get: () => {} },
|
operation: { get: () => {} },
|
||||||
onChange: jest.fn(),
|
onChange: jest.fn(),
|
||||||
param: paramValue,
|
param: paramValue,
|
||||||
rawParam: paramValue,
|
rawParam: paramValue,
|
||||||
onChangeConsumes: () => {},
|
onChangeConsumes: () => {},
|
||||||
pathMethod: [],
|
pathMethod: [],
|
||||||
getConfigs: () => { return {} },
|
specPath: List([]),
|
||||||
specPath: List([])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render(<ParameterRow {...props} />)
|
render(<ParameterRow {...props} />)
|
||||||
@@ -223,30 +299,47 @@ describe("bug #5573: zero default and example values", function () {
|
|||||||
description: "a pet",
|
description: "a pet",
|
||||||
schema: {
|
schema: {
|
||||||
type: "integer",
|
type: "integer",
|
||||||
example: 0
|
example: 0,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
const getSystem = () => ({
|
||||||
let props = {
|
|
||||||
getComponent: () => "div",
|
getComponent: () => "div",
|
||||||
specSelectors: {
|
specSelectors: {
|
||||||
security() {},
|
security() {},
|
||||||
parameterWithMetaByIdentity() { return paramValue },
|
parameterWithMetaByIdentity() {
|
||||||
isOAS3() { return true },
|
return paramValue
|
||||||
isSwagger2() { return false }
|
},
|
||||||
|
isOAS3() {
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
isSwagger2() {
|
||||||
|
return false
|
||||||
|
},
|
||||||
},
|
},
|
||||||
oas3Selectors: {
|
oas3Selectors: {
|
||||||
activeExamplesMember: () => null
|
activeExamplesMember: () => null,
|
||||||
},
|
},
|
||||||
fn: {},
|
getConfigs: () => {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
fn: {
|
||||||
|
memoizedSampleFromSchema,
|
||||||
|
memoizedCreateXMLExample,
|
||||||
|
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
|
||||||
|
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
|
||||||
|
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
|
||||||
|
getSampleSchema: makeGetSampleSchema(getSystem),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const props = {
|
||||||
|
...getSystem(),
|
||||||
operation: { get: () => {} },
|
operation: { get: () => {} },
|
||||||
onChange: jest.fn(),
|
onChange: jest.fn(),
|
||||||
param: paramValue,
|
param: paramValue,
|
||||||
rawParam: paramValue,
|
rawParam: paramValue,
|
||||||
onChangeConsumes: () => {},
|
onChangeConsumes: () => {},
|
||||||
pathMethod: [],
|
pathMethod: [],
|
||||||
getConfigs: () => { return {} },
|
specPath: List([]),
|
||||||
specPath: List([])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render(<ParameterRow {...props} />)
|
render(<ParameterRow {...props} />)
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { shallow } from "enzyme"
|
import { shallow } from "enzyme"
|
||||||
import { fromJS, List } from "immutable"
|
import { fromJS, List } from "immutable"
|
||||||
|
|
||||||
import Response from "components/response"
|
import Response from "components/response"
|
||||||
import ModelExample from "components/model-example"
|
import ModelExample from "components/model-example"
|
||||||
import { inferSchema } from "corePlugins/samples/fn"
|
import {
|
||||||
|
inferSchema,
|
||||||
|
memoizedSampleFromSchema,
|
||||||
|
memoizedCreateXMLExample,
|
||||||
|
} from "core/plugins/samples/fn/index"
|
||||||
|
import makeGetSampleSchema from "core/plugins/samples/fn/get-sample-schema"
|
||||||
|
import makeGetJsonSampleSchema from "core/plugins/samples/fn/get-json-sample-schema"
|
||||||
|
import makeGetYamlSampleSchema from "core/plugins/samples/fn/get-yaml-sample-schema"
|
||||||
|
import makeGetXmlSampleSchema from "core/plugins/samples/fn/get-xml-sample-schema"
|
||||||
|
|
||||||
describe("<Response />", function () {
|
describe("<Response />", function () {
|
||||||
const dummyComponent = () => null
|
const dummyComponent = () => null
|
||||||
@@ -13,21 +25,30 @@ describe("<Response />", function () {
|
|||||||
modelExample: ModelExample,
|
modelExample: ModelExample,
|
||||||
Markdown: dummyComponent,
|
Markdown: dummyComponent,
|
||||||
operationLink: dummyComponent,
|
operationLink: dummyComponent,
|
||||||
contentType: dummyComponent
|
contentType: dummyComponent,
|
||||||
}
|
}
|
||||||
const props = {
|
const getSystem = () => ({
|
||||||
getComponent: c => components[c],
|
getComponent: (c) => components[c],
|
||||||
getConfigs: () => {
|
getConfigs: () => {
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
specSelectors: {
|
specSelectors: {
|
||||||
isOAS3() {
|
isOAS3() {
|
||||||
return false
|
return false
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
fn: {
|
fn: {
|
||||||
inferSchema
|
inferSchema,
|
||||||
|
memoizedSampleFromSchema,
|
||||||
|
memoizedCreateXMLExample,
|
||||||
|
getJsonSampleSchema: makeGetJsonSampleSchema(getSystem),
|
||||||
|
getYamlSampleSchema: makeGetYamlSampleSchema(getSystem),
|
||||||
|
getXmlSampleSchema: makeGetXmlSampleSchema(getSystem),
|
||||||
|
getSampleSchema: makeGetSampleSchema(getSystem),
|
||||||
},
|
},
|
||||||
|
})
|
||||||
|
const props = {
|
||||||
|
...getSystem(),
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
className: "for-test",
|
className: "for-test",
|
||||||
specPath: List(),
|
specPath: List(),
|
||||||
@@ -36,19 +57,19 @@ describe("<Response />", function () {
|
|||||||
type: "object",
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
// Note reverse order: c, b, a
|
// Note reverse order: c, b, a
|
||||||
"c": {
|
c: {
|
||||||
type: "integer"
|
type: "integer",
|
||||||
|
},
|
||||||
|
b: {
|
||||||
|
type: "boolean",
|
||||||
|
},
|
||||||
|
a: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"b": {
|
|
||||||
type: "boolean"
|
|
||||||
},
|
},
|
||||||
"a": {
|
|
||||||
type: "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
code: "200"
|
code: "200",
|
||||||
}
|
}
|
||||||
|
|
||||||
it("renders the model-example schema properties in order", function () {
|
it("renders the model-example schema properties in order", function () {
|
||||||
@@ -57,7 +78,9 @@ describe("<Response />", function () {
|
|||||||
expect(renderedModelExample.length).toEqual(1)
|
expect(renderedModelExample.length).toEqual(1)
|
||||||
|
|
||||||
// Assert the schema's properties have maintained their order
|
// Assert the schema's properties have maintained their order
|
||||||
const modelExampleSchemaProperties = renderedModelExample.props().schema.toJS().properties
|
const modelExampleSchemaProperties = renderedModelExample
|
||||||
|
.props()
|
||||||
|
.schema.toJS().properties
|
||||||
expect(Object.keys(modelExampleSchemaProperties)).toEqual(["c", "b", "a"])
|
expect(Object.keys(modelExampleSchemaProperties)).toEqual(["c", "b", "a"])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user