Add base wrapSelectors for OAS3; implement definitions selector for OAS3

This commit is contained in:
Kyle Shockey
2017-05-17 18:42:34 -07:00
parent 1f314ddca2
commit 60934107d3
3 changed files with 47 additions and 46 deletions

View File

@@ -1,9 +1,9 @@
// import reducers from "./reducers" // import reducers from "./reducers"
// import * as actions from "./actions" // import * as actions from "./actions"
import * as selectors from "./selectors" import * as wrapSelectors from "./wrap-selectors"
// import * as wrapActions from "./wrap-actions" // import * as wrapActions from "./wrap-actions"
export default function(system) { export default function() {
return { return {
components: { components: {
@@ -13,7 +13,7 @@ export default function(system) {
// wrapActions, // wrapActions,
// reducers, // reducers,
// actions, // actions,
selectors wrapSelectors
} }
} }
} }

View File

@@ -1,43 +0,0 @@
import { createSelector } from "reselect"
// import { sorters } from "core/utils"
// import { fromJS, Set, Map, List } from "immutable"
const DEFAULT_TAG = "default"
const state = state => {
return state || Map()
}
// export const specJson = createSelector(
// state,
// spec => spec.get("json", Map())
// )
//
// export const specResolved = createSelector(
// state,
// spec => spec.get("resolved", Map())
// )
//
// export const spec = state => {
// let res = specResolved(state)
// if(res.count() < 1)
// res = specJson(state)
// return res
// }
//
// export const findDefinition = ( state, name ) => {
// return specResolved(state).getIn(["definitions", name], null)
// }
//
// export const definitions = onlyOAS3(createSelector(
// spec,
// spec => spec.getIn(["components", "schemas"]) || Map()
// ))
// helpers
function onlyOAS3(selector) {
return ( state ) => ( thing ) => {
return selector
}
}

View File

@@ -0,0 +1,44 @@
import { createSelector } from "reselect"
import { Map } from "immutable"
// Helpers
function onlyOAS3(selector) {
return (ori, system) => (...args) => {
const spec = system.getSystem().specSelectors.specJson()
const version = spec.get("openapi")
if(typeof version === "string" && version.startsWith("3.0.0")) {
return selector(...args)
} else {
return ori(...args)
}
}
}
const state = state => {
return state || Map()
}
const specJson = createSelector(
state,
spec => spec.get("json", Map())
)
const specResolved = createSelector(
state,
spec => spec.get("resolved", Map())
)
const spec = state => {
let res = specResolved(state)
if(res.count() < 1)
res = specJson(state)
return res
}
// Wrappers
export const definitions = onlyOAS3(createSelector(
spec,
spec => spec.getIn(["components", "schemas"]) || Map()
))