Skip to content

Commit

Permalink
fix(config): define missing default options and their types (#9949)
Browse files Browse the repository at this point in the history
Refs #9945

---

Co-authored-by: Vladimír Gorej <[email protected]>
  • Loading branch information
glowcloud and char0n authored May 21, 2024
1 parent 10e1a5f commit 04bbeaa
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/core/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const defaultOptions = Object.freeze({
displayRequestDuration: false,
deepLinking: false,
tryItOutEnabled: false,
requestInterceptor: (a) => a,
requestInterceptor: (request) => {
request.curlOptions = []
return request
},
responseInterceptor: (a) => a,
showMutatedRequest: true,
defaultModelRendering: "example",
Expand Down Expand Up @@ -80,6 +83,11 @@ const defaultOptions = Object.freeze({
activated: true,
theme: "agate",
},
operationsSorter: null,
tagsSorter: null,
onComplete: null,
modelPropertyMacro: null,
parameterMacro: null,
})

export default defaultOptions
24 changes: 24 additions & 0 deletions src/core/config/type-cast/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ import arrayTypeCaster from "./type-casters/array"
import booleanTypeCaster from "./type-casters/boolean"
import domNodeTypeCaster from "./type-casters/dom-node"
import filterTypeCaster from "./type-casters/filter"
import functionTypeCaster from "./type-casters/function"
import nullableArrayTypeCaster from "./type-casters/nullable-array"
import nullableFunctionTypeCaster from "./type-casters/nullable-function"
import nullableStringTypeCaster from "./type-casters/nullable-string"
import numberTypeCaster from "./type-casters/number"
import objectTypeCaster from "./type-casters/object"
import sorterTypeCaster from "./type-casters/sorter"
import stringTypeCaster from "./type-casters/string"
import syntaxHighlightTypeCaster from "./type-casters/syntax-highlight"
import undefinedStringTypeCaster from "./type-casters/undefined-string"
import defaultOptions from "../defaults"

const mappings = {
components: { typeCaster: objectTypeCaster },
configs: { typeCaster: objectTypeCaster },
configUrl: { typeCaster: nullableStringTypeCaster },
deepLinking: {
typeCaster: booleanTypeCaster,
Expand All @@ -41,12 +46,20 @@ const mappings = {
dom_id: { typeCaster: nullableStringTypeCaster },
domNode: { typeCaster: domNodeTypeCaster },
filter: { typeCaster: filterTypeCaster },
fn: { typeCaster: objectTypeCaster },
initialState: { typeCaster: objectTypeCaster },
layout: { typeCaster: stringTypeCaster },
maxDisplayedTags: {
typeCaster: numberTypeCaster,
defaultValue: defaultOptions.maxDisplayedTags,
},
modelPropertyMacro: { typeCaster: nullableFunctionTypeCaster },
oauth2RedirectUrl: { typeCaster: undefinedStringTypeCaster },
onComplete: { typeCaster: nullableFunctionTypeCaster },
operationsSorter: {
typeCaster: sorterTypeCaster,
},
paramaterMacro: { typeCaster: nullableFunctionTypeCaster },
persistAuthorization: {
typeCaster: booleanTypeCaster,
defaultValue: defaultOptions.persistAuthorization,
Expand All @@ -59,6 +72,10 @@ const mappings = {
typeCaster: arrayTypeCaster,
defaultValue: defaultOptions.presets,
},
requestInterceptor: {
typeCaster: functionTypeCaster,
defaultValue: defaultOptions.requestInterceptor,
},
requestSnippets: {
typeCaster: objectTypeCaster,
defaultValue: defaultOptions.requestSnippets,
Expand All @@ -67,6 +84,10 @@ const mappings = {
typeCaster: booleanTypeCaster,
defaultValue: defaultOptions.requestSnippetsEnabled,
},
responseInterceptor: {
typeCaster: functionTypeCaster,
defaultValue: defaultOptions.responseInterceptor,
},
showCommonExtensions: {
typeCaster: booleanTypeCaster,
defaultValue: defaultOptions.showCommonExtensions,
Expand All @@ -93,6 +114,9 @@ const mappings = {
defaultValue: defaultOptions.syntaxHighlight.activated,
},
"syntaxHighlight.theme": { typeCaster: stringTypeCaster },
tagsSorter: {
typeCaster: sorterTypeCaster,
},
tryItOutEnabled: {
typeCaster: booleanTypeCaster,
defaultValue: defaultOptions.tryItOutEnabled,
Expand Down
7 changes: 7 additions & 0 deletions src/core/config/type-cast/type-casters/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @prettier
*/
const functionTypeCaster = (value, defaultValue) =>
typeof value === "function" ? value : defaultValue

export default functionTypeCaster
7 changes: 7 additions & 0 deletions src/core/config/type-cast/type-casters/nullable-function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @prettier
*/
const nullableFunctionTypeCaster = (value) =>
typeof value === "function" ? value : null

export default nullableFunctionTypeCaster
7 changes: 7 additions & 0 deletions src/core/config/type-cast/type-casters/sorter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @prettier
*/
const sorterTypeCaster = (value) =>
typeof value === "function" || typeof value === "string" ? value : null

export default sorterTypeCaster
5 changes: 3 additions & 2 deletions src/core/plugins/request-snippets/fn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Map } from "immutable"
import { List, Map } from "immutable"
import win from "../../window"


Expand Down Expand Up @@ -83,7 +83,8 @@ const curlify = (request, escape, newLine, ext = "") => {
let headers = request.get("headers")
curlified += "curl" + ext

if (request.has("curlOptions")) {
const curlOptions = request.get("curlOptions")
if (List.isList(curlOptions) && !curlOptions.isEmpty()) {
addWords(...request.get("curlOptions"))
}

Expand Down

0 comments on commit 04bbeaa

Please sign in to comment.