fix: gracefully handle malformed global tags array in taggedOperations selector (via #5159)
* fix: handle malformed global tags array in taggedOperations * handle non-array global tags as well * update test imports * remove stray brackets
This commit is contained in:
@@ -225,7 +225,10 @@ export const operationsWithRootInherited = createSelector(
|
||||
|
||||
export const tags = createSelector(
|
||||
spec,
|
||||
json => json.get("tags", List())
|
||||
json => {
|
||||
const tags = json.get("tags", List())
|
||||
return List.isList(tags) ? tags.filter(tag => Map.isMap(tag)) : List()
|
||||
}
|
||||
)
|
||||
|
||||
export const tagDetails = (state, tag) => {
|
||||
|
||||
@@ -9,18 +9,15 @@ import {
|
||||
operationScheme,
|
||||
specJsonWithResolvedSubtrees,
|
||||
producesOptionsFor,
|
||||
} from "corePlugins/spec/selectors"
|
||||
|
||||
import Petstore from "./assets/petstore.json"
|
||||
import {
|
||||
operationWithMeta,
|
||||
parameterWithMeta,
|
||||
parameterWithMetaByIdentity,
|
||||
parameterInclusionSettingFor,
|
||||
consumesOptionsFor
|
||||
} from "../../../../src/core/plugins/spec/selectors"
|
||||
consumesOptionsFor,
|
||||
taggedOperations
|
||||
} from "corePlugins/spec/selectors"
|
||||
|
||||
describe("spec plugin - selectors", function(){
|
||||
import Petstore from "./assets/petstore.json"
|
||||
|
||||
describe("definitions", function(){
|
||||
it("should return definitions by default", function(){
|
||||
@@ -1049,4 +1046,169 @@ describe("spec plugin - selectors", function(){
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
describe("taggedOperations", function () {
|
||||
it("should return a List of ad-hoc tagged operations", function () {
|
||||
const system = {
|
||||
getConfigs: () => ({})
|
||||
}
|
||||
const state = fromJS({
|
||||
json: {
|
||||
// tags: [
|
||||
// "myTag"
|
||||
// ],
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
produces: [],
|
||||
tags: ["myTag"],
|
||||
description: "my operation",
|
||||
consumes: [
|
||||
"operation/one",
|
||||
"operation/two",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = taggedOperations(state)(system)
|
||||
|
||||
const op = state.getIn(["json", "paths", "/", "get"]).toJS()
|
||||
|
||||
expect(result.toJS()).toEqual({
|
||||
myTag: {
|
||||
tagDetails: undefined,
|
||||
operations: [{
|
||||
id: "get-/",
|
||||
method: "get",
|
||||
path: "/",
|
||||
operation: op
|
||||
}]
|
||||
}
|
||||
})
|
||||
})
|
||||
it("should return a List of defined tagged operations", function () {
|
||||
const system = {
|
||||
getConfigs: () => ({})
|
||||
}
|
||||
const state = fromJS({
|
||||
json: {
|
||||
tags: [
|
||||
{
|
||||
name: "myTag"
|
||||
}
|
||||
],
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
produces: [],
|
||||
tags: ["myTag"],
|
||||
description: "my operation",
|
||||
consumes: [
|
||||
"operation/one",
|
||||
"operation/two",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = taggedOperations(state)(system)
|
||||
|
||||
const op = state.getIn(["json", "paths", "/", "get"]).toJS()
|
||||
|
||||
expect(result.toJS()).toEqual({
|
||||
myTag: {
|
||||
tagDetails: {
|
||||
name: "myTag"
|
||||
},
|
||||
operations: [{
|
||||
id: "get-/",
|
||||
method: "get",
|
||||
path: "/",
|
||||
operation: op
|
||||
}]
|
||||
}
|
||||
})
|
||||
})
|
||||
it("should gracefully handle a malformed global tags array", function () {
|
||||
const system = {
|
||||
getConfigs: () => ({})
|
||||
}
|
||||
const state = fromJS({
|
||||
json: {
|
||||
tags: [null],
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
produces: [],
|
||||
tags: ["myTag"],
|
||||
description: "my operation",
|
||||
consumes: [
|
||||
"operation/one",
|
||||
"operation/two",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = taggedOperations(state)(system)
|
||||
|
||||
const op = state.getIn(["json", "paths", "/", "get"]).toJS()
|
||||
|
||||
expect(result.toJS()).toEqual({
|
||||
myTag: {
|
||||
tagDetails: undefined,
|
||||
operations: [{
|
||||
id: "get-/",
|
||||
method: "get",
|
||||
path: "/",
|
||||
operation: op
|
||||
}]
|
||||
}
|
||||
})
|
||||
})
|
||||
it("should gracefully handle a non-array global tags entry", function () {
|
||||
const system = {
|
||||
getConfigs: () => ({})
|
||||
}
|
||||
const state = fromJS({
|
||||
json: {
|
||||
tags: "asdf",
|
||||
paths: {
|
||||
"/": {
|
||||
"get": {
|
||||
produces: [],
|
||||
tags: ["myTag"],
|
||||
description: "my operation",
|
||||
consumes: [
|
||||
"operation/one",
|
||||
"operation/two",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const result = taggedOperations(state)(system)
|
||||
|
||||
const op = state.getIn(["json", "paths", "/", "get"]).toJS()
|
||||
|
||||
expect(result.toJS()).toEqual({
|
||||
myTag: {
|
||||
tagDetails: undefined,
|
||||
operations: [{
|
||||
id: "get-/",
|
||||
method: "get",
|
||||
path: "/",
|
||||
operation: op
|
||||
}]
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user