diff --git a/src/core/components/parameter-row.jsx b/src/core/components/parameter-row.jsx
index b44f10041419abaa4e7a738809be1a2dc2d528e0..66c2d1ce7142918e49f81c55000e05f8bdeb8e17 100644
--- a/src/core/components/parameter-row.jsx
+++ b/src/core/components/parameter-row.jsx
@@ -119,17 +119,26 @@ export default class ParameterRow extends Component {
//// Find an initial value
if (specSelectors.isSwagger2()) {
- initialValue = paramWithMeta.get("x-example")
- || paramWithMeta.getIn(["schema", "example"])
- || (schema && schema.getIn(["default"]))
+ initialValue =
+ paramWithMeta.get("x-example") !== undefined
+ ? paramWithMeta.get("x-example")
+ : paramWithMeta.getIn(["schema", "example"]) !== undefined
+ ? paramWithMeta.getIn(["schema", "example"])
+ : (schema && schema.getIn(["default"]))
} else if (specSelectors.isOAS3()) {
const currentExampleKey = oas3Selectors.activeExamplesMember(...pathMethod, "parameters", this.getParamKey())
- initialValue = paramWithMeta.getIn(["examples", currentExampleKey, "value"])
- || paramWithMeta.getIn(["content", parameterMediaType, "example"])
- || paramWithMeta.get("example")
- || (schema && schema.get("example"))
- || (schema && schema.get("default"))
- || paramWithMeta.get("default") // ensures support for `parameterMacro`
+ initialValue =
+ paramWithMeta.getIn(["examples", currentExampleKey, "value"]) !== undefined
+ ? paramWithMeta.getIn(["examples", currentExampleKey, "value"])
+ : paramWithMeta.getIn(["content", parameterMediaType, "example"]) !== undefined
+ ? paramWithMeta.getIn(["content", parameterMediaType, "example"])
+ : paramWithMeta.get("example") !== undefined
+ ? paramWithMeta.get("example")
+ : (schema && schema.get("example")) !== undefined
+ ? (schema && schema.get("example"))
+ : (schema && schema.get("default")) !== undefined
+ ? (schema && schema.get("default"))
+ : paramWithMeta.get("default") // ensures support for `parameterMacro`
}
//// Process the initial value
diff --git a/test/unit/components/parameter-row.jsx b/test/unit/components/parameter-row.jsx
index 7c44cfe9a559c51da1cdbd3526f9f31f030668a3..821b457b66a67735464ac357662284dd497f25a1 100644
--- a/test/unit/components/parameter-row.jsx
+++ b/test/unit/components/parameter-row.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { fromJS } from "immutable"
+import { List, fromJS } from "immutable"
import { render } from "enzyme"
import ParameterRow from "components/parameter-row"
@@ -84,3 +84,142 @@ describe("", () => {
expect(wrapper.find(".parameter__type").text()).toEqual("string")
})
})
+
+describe("bug #5573: zero default and example values", function () {
+ it("should apply a Swagger 2.0 default value of zero", function () {
+ const paramValue = fromJS({
+ description: "a pet",
+ type: "integer",
+ default: 0
+ })
+
+ let props = {
+ getComponent: () => "div",
+ specSelectors: {
+ security() { },
+ parameterWithMetaByIdentity() { return paramValue },
+ isOAS3() { return false },
+ isSwagger2() { return true }
+ },
+ fn: {},
+ operation: { get: () => { } },
+ onChange: jest.fn(),
+ param: paramValue,
+ rawParam: paramValue,
+ onChangeConsumes: () => { },
+ pathMethod: [],
+ getConfigs: () => { return {} },
+ specPath: List([])
+ }
+
+ render()
+
+ expect(props.onChange).toHaveBeenCalled()
+ expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
+ })
+ it("should apply a Swagger 2.0 example value of zero", function () {
+ const paramValue = fromJS({
+ description: "a pet",
+ type: "integer",
+ schema: {
+ example: 0
+ }
+ })
+
+ let props = {
+ getComponent: () => "div",
+ specSelectors: {
+ security() { },
+ parameterWithMetaByIdentity() { return paramValue },
+ isOAS3() { return false },
+ isSwagger2() { return true }
+ },
+ fn: {},
+ operation: { get: () => { } },
+ onChange: jest.fn(),
+ param: paramValue,
+ rawParam: paramValue,
+ onChangeConsumes: () => { },
+ pathMethod: [],
+ getConfigs: () => { return {} },
+ specPath: List([])
+ }
+
+ render()
+
+ expect(props.onChange).toHaveBeenCalled()
+ expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
+ })
+ it("should apply an OpenAPI 3.0 default value of zero", function () {
+ const paramValue = fromJS({
+ description: "a pet",
+ schema: {
+ type: "integer",
+ default: 0
+ }
+ })
+
+ let props = {
+ getComponent: () => "div",
+ specSelectors: {
+ security() { },
+ parameterWithMetaByIdentity() { return paramValue },
+ isOAS3() { return true },
+ isSwagger2() { return false }
+ },
+ oas3Selectors: {
+ activeExamplesMember: () => null
+ },
+ fn: {},
+ operation: { get: () => { } },
+ onChange: jest.fn(),
+ param: paramValue,
+ rawParam: paramValue,
+ onChangeConsumes: () => { },
+ pathMethod: [],
+ getConfigs: () => { return {} },
+ specPath: List([])
+ }
+
+ render()
+
+ expect(props.onChange).toHaveBeenCalled()
+ expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
+ })
+ it("should apply an OpenAPI 3.0 example value of zero", function () {
+ const paramValue = fromJS({
+ description: "a pet",
+ schema: {
+ type: "integer",
+ example: 0
+ }
+ })
+
+ let props = {
+ getComponent: () => "div",
+ specSelectors: {
+ security() { },
+ parameterWithMetaByIdentity() { return paramValue },
+ isOAS3() { return true },
+ isSwagger2() { return false }
+ },
+ oas3Selectors: {
+ activeExamplesMember: () => null
+ },
+ fn: {},
+ operation: { get: () => { } },
+ onChange: jest.fn(),
+ param: paramValue,
+ rawParam: paramValue,
+ onChangeConsumes: () => { },
+ pathMethod: [],
+ getConfigs: () => { return {} },
+ specPath: List([])
+ }
+
+ render()
+
+ expect(props.onChange).toHaveBeenCalled()
+ expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
+ })
+})