Move method filtering logic to Operations component
This commit is contained in:
@@ -2,6 +2,13 @@ import React from "react"
|
|||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import { createDeepLinkPath, sanitizeUrl } from "core/utils"
|
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 {
|
export default class Operations extends React.Component {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
@@ -113,6 +120,13 @@ export default class Operations extends React.Component {
|
|||||||
const path = op.get("path")
|
const path = op.get("path")
|
||||||
const method = op.get("method")
|
const method = op.get("method")
|
||||||
|
|
||||||
|
const validMethods = specSelectors.isOAS3() ?
|
||||||
|
OAS3_OPERATION_METHODS : SWAGGER2_OPERATION_METHODS
|
||||||
|
|
||||||
|
if(validMethods.indexOf(method) === -1) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return <OperationContainer
|
return <OperationContainer
|
||||||
key={`${path}-${method}`}
|
key={`${path}-${method}`}
|
||||||
op={op}
|
op={op}
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import { fromJS, Set, Map, OrderedMap, List } from "immutable"
|
|||||||
|
|
||||||
const DEFAULT_TAG = "default"
|
const DEFAULT_TAG = "default"
|
||||||
|
|
||||||
const OPERATION_METHODS = ["get", "put", "post", "delete", "options", "head", "patch"]
|
|
||||||
|
|
||||||
const state = state => {
|
const state = state => {
|
||||||
return state || Map()
|
return state || Map()
|
||||||
}
|
}
|
||||||
@@ -97,9 +95,6 @@ export const operations = createSelector(
|
|||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
path.forEach((operation, method) => {
|
path.forEach((operation, method) => {
|
||||||
if(OPERATION_METHODS.indexOf(method) === -1) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
list = list.push(fromJS({
|
list = list.push(fromJS({
|
||||||
path: pathName,
|
path: pathName,
|
||||||
method,
|
method,
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ const components = {
|
|||||||
OperationContainer: ({ path, method }) => <span className="mocked-op" id={`${path}-${method}`} />
|
OperationContainer: ({ path, method }) => <span className="mocked-op" id={`${path}-${method}`} />
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.only("<Operations/>", function(){
|
describe("<Operations/>", function(){
|
||||||
it("should render a Swagger2 `get` method, but not a `trace` or `foo` method", function(){
|
it("should render a Swagger2 `get` method, but not a `trace` or `foo` method", function(){
|
||||||
|
|
||||||
let props = {
|
let props = {
|
||||||
|
fn: {},
|
||||||
|
specActions: {},
|
||||||
|
layoutActions: {},
|
||||||
getComponent: (name)=> {
|
getComponent: (name)=> {
|
||||||
|
|
||||||
return components[name] || null
|
return components[name] || null
|
||||||
},
|
},
|
||||||
getConfigs: () => {
|
getConfigs: () => {
|
||||||
@@ -60,16 +62,17 @@ describe.only("<Operations/>", function(){
|
|||||||
|
|
||||||
let wrapper = render(<Operations {...props}/>)
|
let wrapper = render(<Operations {...props}/>)
|
||||||
|
|
||||||
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(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(){
|
it("should render an OAS3 `get` and `trace` method, but not a `foo` method", function(){
|
||||||
|
|
||||||
let props = {
|
let props = {
|
||||||
|
fn: {},
|
||||||
|
specActions: {},
|
||||||
|
layoutActions: {},
|
||||||
getComponent: (name)=> {
|
getComponent: (name)=> {
|
||||||
|
|
||||||
return components[name] || null
|
return components[name] || null
|
||||||
},
|
},
|
||||||
getConfigs: () => {
|
getConfigs: () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user