From 328f02c4637d473269023c604e7cb8256cbd6c41 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Wed, 6 Dec 2017 13:52:06 -0800 Subject: [PATCH] Move method filtering logic to Operations component --- src/core/components/operations.jsx | 14 ++++++++++++++ src/core/plugins/spec/selectors.js | 5 ----- test/components/operations.js | 13 ++++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/core/components/operations.jsx b/src/core/components/operations.jsx index 32b15437..f1174e32 100644 --- a/src/core/components/operations.jsx +++ b/src/core/components/operations.jsx @@ -2,6 +2,13 @@ import React from "react" import PropTypes from "prop-types" import { createDeepLinkPath, sanitizeUrl } from "core/utils" +const SWAGGER2_OPERATION_METHODS = [ + "get", "put", "post", "delete", "options", "head", "patch" +] + +const OAS3_OPERATION_METHODS = SWAGGER2_OPERATION_METHODS.concat(["trace"]) + + export default class Operations extends React.Component { static propTypes = { @@ -113,6 +120,13 @@ export default class Operations extends React.Component { const path = op.get("path") const method = op.get("method") + const validMethods = specSelectors.isOAS3() ? + OAS3_OPERATION_METHODS : SWAGGER2_OPERATION_METHODS + + if(validMethods.indexOf(method) === -1) { + return null + } + return { return state || Map() } @@ -97,9 +95,6 @@ export const operations = createSelector( return {} } path.forEach((operation, method) => { - if(OPERATION_METHODS.indexOf(method) === -1) { - return - } list = list.push(fromJS({ path: pathName, method, diff --git a/test/components/operations.js b/test/components/operations.js index 7609b985..8a6a7506 100644 --- a/test/components/operations.js +++ b/test/components/operations.js @@ -11,12 +11,14 @@ const components = { OperationContainer: ({ path, method }) => } -describe.only("", function(){ +describe("", function(){ it("should render a Swagger2 `get` method, but not a `trace` or `foo` method", function(){ let props = { + fn: {}, + specActions: {}, + layoutActions: {}, getComponent: (name)=> { - return components[name] || null }, getConfigs: () => { @@ -60,16 +62,17 @@ describe.only("", function(){ let wrapper = render() - expect(wrapper.find("span.mocked-op").length).toEqual(2) + expect(wrapper.find("span.mocked-op").length).toEqual(1) expect(wrapper.find("span.mocked-op").eq(0).attr("id")).toEqual("/pets/{id}-get") - expect(wrapper.find("span.mocked-op").eq(1).attr("id")).toEqual("/pets/{id}-trace") }) it("should render an OAS3 `get` and `trace` method, but not a `foo` method", function(){ let props = { + fn: {}, + specActions: {}, + layoutActions: {}, getComponent: (name)=> { - return components[name] || null }, getConfigs: () => {