From eb88253839d6a9965561cfca98bf9d4baaabf259 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Tue, 14 Jan 2020 09:58:48 +0000 Subject: [PATCH] Feature: Render OAS3 parameter type formats --- src/core/components/parameter-row.jsx | 2 +- test/mocha/components/parameter-row.jsx | 56 +++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 test/mocha/components/parameter-row.jsx diff --git a/src/core/components/parameter-row.jsx b/src/core/components/parameter-row.jsx index 81a62b5e646..f823cbeb8dd 100644 --- a/src/core/components/parameter-row.jsx +++ b/src/core/components/parameter-row.jsx @@ -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") let type = schema.get("type") let isFormData = inType === "formData" let isFormDataSupported = "FormData" in win diff --git a/test/mocha/components/parameter-row.jsx b/test/mocha/components/parameter-row.jsx new file mode 100644 index 00000000000..9f5b4b66662 --- /dev/null +++ b/test/mocha/components/parameter-row.jsx @@ -0,0 +1,56 @@ +/* eslint-env mocha */ +import React from "react" +import { fromJS } from "immutable" +import expect from "expect" +import { render } from "enzyme" +import ParameterRow from "components/parameter-row" + +describe("", () => { + 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", () => { + 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() + + expect(wrapper.find(".parameter__type").length).toEqual(1) + expect(wrapper.find(".parameter__type").text()).toEqual("string($uuid)") + }) + + it("Can render OAS3 parameter type", () => { + 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() + + expect(wrapper.find(".parameter__type").length).toEqual(1) + expect(wrapper.find(".parameter__type").text()).toEqual("string($uuid)") + }) +})