Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Render OAS3 parameter type formats #5796

Merged
2 changes: 1 addition & 1 deletion src/core/components/parameter-row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export default class ParameterRow extends Component {
let { schema } = getParameterSchema(param, { isOAS3 })
let paramWithMeta = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam) || Map()

let format = param.get("format")
let format = param.get("format") || schema.get("format")
shockey marked this conversation as resolved.
Show resolved Hide resolved
let type = schema.get("type")
let isFormData = inType === "formData"
let isFormDataSupported = "FormData" in win
Expand Down
88 changes: 88 additions & 0 deletions test/mocha/components/parameter-row.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* eslint-env mocha */
import React from "react"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job on these tests! 👍

import { fromJS } from "immutable"
import expect from "expect"
import { render } from "enzyme"
import ParameterRow from "components/parameter-row"

describe("<ParameterRow/>", () => {
const createProps = ({ param, isOAS3 }) => ({
getComponent: () => "div",
specSelectors: {
parameterWithMetaByIdentity: () => param,
isOAS3: () => isOAS3,
isSwagger2: () => !isOAS3
},
oas3Selectors: { activeExamplesMember: () => {} },
param,
rawParam: param,
pathMethod: [],
getConfigs: () => ({})
})

it("Can render Swagger 2 parameter type with format", () => {
const param = fromJS({
name: "petUuid",
in: "path",
description: "UUID that identifies a pet",
type: "string",
format: "uuid"
})

const props = createProps({ param, isOAS3: false })
const wrapper = render(<ParameterRow {...props}/>)

expect(wrapper.find(".parameter__type").length).toEqual(1)
expect(wrapper.find(".parameter__type").text()).toEqual("string($uuid)")
})

it("Can render Swagger 2 parameter type without format", () => {
const param = fromJS({
name: "petId",
in: "path",
description: "ID that identifies a pet",
type: "string"
})

const props = createProps({ param, isOAS3: false })
const wrapper = render(<ParameterRow {...props}/>)

expect(wrapper.find(".parameter__type").length).toEqual(1)
expect(wrapper.find(".parameter__type").text()).toEqual("string")
})

it("Can render OAS3 parameter type with format", () => {
const param = fromJS({
name: "petUuid",
in: "path",
description: "UUID that identifies a pet",
schema: {
type: "string",
format: "uuid"
}
})

const props = createProps({ param, isOAS3: true })
const wrapper = render(<ParameterRow {...props}/>)

expect(wrapper.find(".parameter__type").length).toEqual(1)
expect(wrapper.find(".parameter__type").text()).toEqual("string($uuid)")
})

it("Can render OAS3 parameter type without format", () => {
const param = fromJS({
name: "petId",
in: "path",
description: "ID that identifies a pet",
schema: {
type: "string"
}
})

const props = createProps({ param, isOAS3: true })
const wrapper = render(<ParameterRow {...props}/>)

expect(wrapper.find(".parameter__type").length).toEqual(1)
expect(wrapper.find(".parameter__type").text()).toEqual("string")
})
})