fix(config): define missing default options and their types (#9949)
Refs #9945 --- Co-authored-by: Vladimír Gorej <vladimir.gorej@gmail.com>
This commit is contained in:
@@ -23,7 +23,10 @@ const defaultOptions = Object.freeze({
|
|||||||
displayRequestDuration: false,
|
displayRequestDuration: false,
|
||||||
deepLinking: false,
|
deepLinking: false,
|
||||||
tryItOutEnabled: false,
|
tryItOutEnabled: false,
|
||||||
requestInterceptor: (a) => a,
|
requestInterceptor: (request) => {
|
||||||
|
request.curlOptions = []
|
||||||
|
return request
|
||||||
|
},
|
||||||
responseInterceptor: (a) => a,
|
responseInterceptor: (a) => a,
|
||||||
showMutatedRequest: true,
|
showMutatedRequest: true,
|
||||||
defaultModelRendering: "example",
|
defaultModelRendering: "example",
|
||||||
@@ -80,6 +83,11 @@ const defaultOptions = Object.freeze({
|
|||||||
activated: true,
|
activated: true,
|
||||||
theme: "agate",
|
theme: "agate",
|
||||||
},
|
},
|
||||||
|
operationsSorter: null,
|
||||||
|
tagsSorter: null,
|
||||||
|
onComplete: null,
|
||||||
|
modelPropertyMacro: null,
|
||||||
|
parameterMacro: null,
|
||||||
})
|
})
|
||||||
|
|
||||||
export default defaultOptions
|
export default defaultOptions
|
||||||
|
|||||||
@@ -5,16 +5,21 @@ import arrayTypeCaster from "./type-casters/array"
|
|||||||
import booleanTypeCaster from "./type-casters/boolean"
|
import booleanTypeCaster from "./type-casters/boolean"
|
||||||
import domNodeTypeCaster from "./type-casters/dom-node"
|
import domNodeTypeCaster from "./type-casters/dom-node"
|
||||||
import filterTypeCaster from "./type-casters/filter"
|
import filterTypeCaster from "./type-casters/filter"
|
||||||
|
import functionTypeCaster from "./type-casters/function"
|
||||||
import nullableArrayTypeCaster from "./type-casters/nullable-array"
|
import nullableArrayTypeCaster from "./type-casters/nullable-array"
|
||||||
|
import nullableFunctionTypeCaster from "./type-casters/nullable-function"
|
||||||
import nullableStringTypeCaster from "./type-casters/nullable-string"
|
import nullableStringTypeCaster from "./type-casters/nullable-string"
|
||||||
import numberTypeCaster from "./type-casters/number"
|
import numberTypeCaster from "./type-casters/number"
|
||||||
import objectTypeCaster from "./type-casters/object"
|
import objectTypeCaster from "./type-casters/object"
|
||||||
|
import sorterTypeCaster from "./type-casters/sorter"
|
||||||
import stringTypeCaster from "./type-casters/string"
|
import stringTypeCaster from "./type-casters/string"
|
||||||
import syntaxHighlightTypeCaster from "./type-casters/syntax-highlight"
|
import syntaxHighlightTypeCaster from "./type-casters/syntax-highlight"
|
||||||
import undefinedStringTypeCaster from "./type-casters/undefined-string"
|
import undefinedStringTypeCaster from "./type-casters/undefined-string"
|
||||||
import defaultOptions from "../defaults"
|
import defaultOptions from "../defaults"
|
||||||
|
|
||||||
const mappings = {
|
const mappings = {
|
||||||
|
components: { typeCaster: objectTypeCaster },
|
||||||
|
configs: { typeCaster: objectTypeCaster },
|
||||||
configUrl: { typeCaster: nullableStringTypeCaster },
|
configUrl: { typeCaster: nullableStringTypeCaster },
|
||||||
deepLinking: {
|
deepLinking: {
|
||||||
typeCaster: booleanTypeCaster,
|
typeCaster: booleanTypeCaster,
|
||||||
@@ -41,12 +46,20 @@ const mappings = {
|
|||||||
dom_id: { typeCaster: nullableStringTypeCaster },
|
dom_id: { typeCaster: nullableStringTypeCaster },
|
||||||
domNode: { typeCaster: domNodeTypeCaster },
|
domNode: { typeCaster: domNodeTypeCaster },
|
||||||
filter: { typeCaster: filterTypeCaster },
|
filter: { typeCaster: filterTypeCaster },
|
||||||
|
fn: { typeCaster: objectTypeCaster },
|
||||||
|
initialState: { typeCaster: objectTypeCaster },
|
||||||
layout: { typeCaster: stringTypeCaster },
|
layout: { typeCaster: stringTypeCaster },
|
||||||
maxDisplayedTags: {
|
maxDisplayedTags: {
|
||||||
typeCaster: numberTypeCaster,
|
typeCaster: numberTypeCaster,
|
||||||
defaultValue: defaultOptions.maxDisplayedTags,
|
defaultValue: defaultOptions.maxDisplayedTags,
|
||||||
},
|
},
|
||||||
|
modelPropertyMacro: { typeCaster: nullableFunctionTypeCaster },
|
||||||
oauth2RedirectUrl: { typeCaster: undefinedStringTypeCaster },
|
oauth2RedirectUrl: { typeCaster: undefinedStringTypeCaster },
|
||||||
|
onComplete: { typeCaster: nullableFunctionTypeCaster },
|
||||||
|
operationsSorter: {
|
||||||
|
typeCaster: sorterTypeCaster,
|
||||||
|
},
|
||||||
|
paramaterMacro: { typeCaster: nullableFunctionTypeCaster },
|
||||||
persistAuthorization: {
|
persistAuthorization: {
|
||||||
typeCaster: booleanTypeCaster,
|
typeCaster: booleanTypeCaster,
|
||||||
defaultValue: defaultOptions.persistAuthorization,
|
defaultValue: defaultOptions.persistAuthorization,
|
||||||
@@ -59,6 +72,10 @@ const mappings = {
|
|||||||
typeCaster: arrayTypeCaster,
|
typeCaster: arrayTypeCaster,
|
||||||
defaultValue: defaultOptions.presets,
|
defaultValue: defaultOptions.presets,
|
||||||
},
|
},
|
||||||
|
requestInterceptor: {
|
||||||
|
typeCaster: functionTypeCaster,
|
||||||
|
defaultValue: defaultOptions.requestInterceptor,
|
||||||
|
},
|
||||||
requestSnippets: {
|
requestSnippets: {
|
||||||
typeCaster: objectTypeCaster,
|
typeCaster: objectTypeCaster,
|
||||||
defaultValue: defaultOptions.requestSnippets,
|
defaultValue: defaultOptions.requestSnippets,
|
||||||
@@ -67,6 +84,10 @@ const mappings = {
|
|||||||
typeCaster: booleanTypeCaster,
|
typeCaster: booleanTypeCaster,
|
||||||
defaultValue: defaultOptions.requestSnippetsEnabled,
|
defaultValue: defaultOptions.requestSnippetsEnabled,
|
||||||
},
|
},
|
||||||
|
responseInterceptor: {
|
||||||
|
typeCaster: functionTypeCaster,
|
||||||
|
defaultValue: defaultOptions.responseInterceptor,
|
||||||
|
},
|
||||||
showCommonExtensions: {
|
showCommonExtensions: {
|
||||||
typeCaster: booleanTypeCaster,
|
typeCaster: booleanTypeCaster,
|
||||||
defaultValue: defaultOptions.showCommonExtensions,
|
defaultValue: defaultOptions.showCommonExtensions,
|
||||||
@@ -93,6 +114,9 @@ const mappings = {
|
|||||||
defaultValue: defaultOptions.syntaxHighlight.activated,
|
defaultValue: defaultOptions.syntaxHighlight.activated,
|
||||||
},
|
},
|
||||||
"syntaxHighlight.theme": { typeCaster: stringTypeCaster },
|
"syntaxHighlight.theme": { typeCaster: stringTypeCaster },
|
||||||
|
tagsSorter: {
|
||||||
|
typeCaster: sorterTypeCaster,
|
||||||
|
},
|
||||||
tryItOutEnabled: {
|
tryItOutEnabled: {
|
||||||
typeCaster: booleanTypeCaster,
|
typeCaster: booleanTypeCaster,
|
||||||
defaultValue: defaultOptions.tryItOutEnabled,
|
defaultValue: defaultOptions.tryItOutEnabled,
|
||||||
|
|||||||
7
src/core/config/type-cast/type-casters/function.js
Normal file
7
src/core/config/type-cast/type-casters/function.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
|
const functionTypeCaster = (value, defaultValue) =>
|
||||||
|
typeof value === "function" ? value : defaultValue
|
||||||
|
|
||||||
|
export default functionTypeCaster
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
|
const nullableFunctionTypeCaster = (value) =>
|
||||||
|
typeof value === "function" ? value : null
|
||||||
|
|
||||||
|
export default nullableFunctionTypeCaster
|
||||||
7
src/core/config/type-cast/type-casters/sorter.js
Normal file
7
src/core/config/type-cast/type-casters/sorter.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
|
const sorterTypeCaster = (value) =>
|
||||||
|
typeof value === "function" || typeof value === "string" ? value : null
|
||||||
|
|
||||||
|
export default sorterTypeCaster
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Map } from "immutable"
|
import { List, Map } from "immutable"
|
||||||
import win from "../../window"
|
import win from "../../window"
|
||||||
|
|
||||||
|
|
||||||
@@ -83,7 +83,8 @@ const curlify = (request, escape, newLine, ext = "") => {
|
|||||||
let headers = request.get("headers")
|
let headers = request.get("headers")
|
||||||
curlified += "curl" + ext
|
curlified += "curl" + ext
|
||||||
|
|
||||||
if (request.has("curlOptions")) {
|
const curlOptions = request.get("curlOptions")
|
||||||
|
if (List.isList(curlOptions) && !curlOptions.isEmpty()) {
|
||||||
addWords(...request.get("curlOptions"))
|
addWords(...request.get("curlOptions"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user