Add base wrapSelectors for OAS3; implement definitions selector for OAS3
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
44
src/core/plugins/oas3/wrap-selectors.js
Normal file
44
src/core/plugins/oas3/wrap-selectors.js
Normal 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()
|
||||||
|
))
|
||||||
Reference in New Issue
Block a user