Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/core/plugins/spec/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
178 changes: 170 additions & 8 deletions test/core/plugins/spec/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down Expand Up @@ -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
}]
}
})
})
})