From 2674241549cbd3116bdd0a27635f0fd3effc4b89 Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Mon, 20 May 2024 14:48:54 +0200 Subject: [PATCH 1/3] fix(config): define missing default options Refs #9945 --- src/core/config/defaults.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/config/defaults.js b/src/core/config/defaults.js index bee47f04cdd..d5b2050379a 100644 --- a/src/core/config/defaults.js +++ b/src/core/config/defaults.js @@ -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", @@ -80,6 +83,11 @@ const defaultOptions = Object.freeze({ activated: true, theme: "agate", }, + operationsSorter: null, + tagsSorter: null, + onComplete: () => {}, + modelPropertyMacro: null, + parameterMacro: null, }) export default defaultOptions From 2fc35a1ab2401b6da6c34474110ad4e7ab7518d9 Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Tue, 21 May 2024 12:03:45 +0200 Subject: [PATCH 2/3] add type casters and curlOptions check --- src/core/config/type-cast/mappings.js | 20 +++++++++++++++++++ .../config/type-cast/type-casters/function.js | 7 +++++++ .../type-casters/nullable-function.js | 7 +++++++ .../config/type-cast/type-casters/sorter.js | 7 +++++++ src/core/plugins/request-snippets/fn.js | 5 +++-- 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/core/config/type-cast/type-casters/function.js create mode 100644 src/core/config/type-cast/type-casters/nullable-function.js create mode 100644 src/core/config/type-cast/type-casters/sorter.js diff --git a/src/core/config/type-cast/mappings.js b/src/core/config/type-cast/mappings.js index b085f5ec8ce..4b4853aea06 100644 --- a/src/core/config/type-cast/mappings.js +++ b/src/core/config/type-cast/mappings.js @@ -5,10 +5,13 @@ 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" @@ -46,7 +49,13 @@ const mappings = { 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, @@ -59,6 +68,10 @@ const mappings = { typeCaster: arrayTypeCaster, defaultValue: defaultOptions.presets, }, + requestInterceptor: { + typeCaster: functionTypeCaster, + defaultValue: defaultOptions.requestInterceptor, + }, requestSnippets: { typeCaster: objectTypeCaster, defaultValue: defaultOptions.requestSnippets, @@ -67,6 +80,10 @@ const mappings = { typeCaster: booleanTypeCaster, defaultValue: defaultOptions.requestSnippetsEnabled, }, + responseInterceptor: { + typeCaster: functionTypeCaster, + defaultValue: defaultOptions.responseInterceptor, + }, showCommonExtensions: { typeCaster: booleanTypeCaster, defaultValue: defaultOptions.showCommonExtensions, @@ -93,6 +110,9 @@ const mappings = { defaultValue: defaultOptions.syntaxHighlight.activated, }, "syntaxHighlight.theme": { typeCaster: stringTypeCaster }, + tagsSorter: { + typeCaster: sorterTypeCaster, + }, tryItOutEnabled: { typeCaster: booleanTypeCaster, defaultValue: defaultOptions.tryItOutEnabled, diff --git a/src/core/config/type-cast/type-casters/function.js b/src/core/config/type-cast/type-casters/function.js new file mode 100644 index 00000000000..35ace3cfaa5 --- /dev/null +++ b/src/core/config/type-cast/type-casters/function.js @@ -0,0 +1,7 @@ +/** + * @prettier + */ +const functionTypeCaster = (value, defaultValue) => + typeof value === "function" ? value : defaultValue + +export default functionTypeCaster diff --git a/src/core/config/type-cast/type-casters/nullable-function.js b/src/core/config/type-cast/type-casters/nullable-function.js new file mode 100644 index 00000000000..23832ae1204 --- /dev/null +++ b/src/core/config/type-cast/type-casters/nullable-function.js @@ -0,0 +1,7 @@ +/** + * @prettier + */ +const nullableFunctionTypeCaster = (value) => + typeof value === "function" ? value : null + +export default nullableFunctionTypeCaster diff --git a/src/core/config/type-cast/type-casters/sorter.js b/src/core/config/type-cast/type-casters/sorter.js new file mode 100644 index 00000000000..5773a7172ef --- /dev/null +++ b/src/core/config/type-cast/type-casters/sorter.js @@ -0,0 +1,7 @@ +/** + * @prettier + */ +const sorterTypeCaster = (value) => + typeof value === "function" || typeof value === "string" ? value : null + +export default sorterTypeCaster diff --git a/src/core/plugins/request-snippets/fn.js b/src/core/plugins/request-snippets/fn.js index 8fe7f539ccd..4e71454cc6c 100644 --- a/src/core/plugins/request-snippets/fn.js +++ b/src/core/plugins/request-snippets/fn.js @@ -1,4 +1,4 @@ -import { Map } from "immutable" +import { List, Map } from "immutable" import win from "../../window" @@ -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")) } From 57bb6d6952c83b90a97783c71fc460a6a0f5bde1 Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Tue, 21 May 2024 12:40:44 +0200 Subject: [PATCH 3/3] update default value and type casters --- src/core/config/defaults.js | 2 +- src/core/config/type-cast/mappings.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/config/defaults.js b/src/core/config/defaults.js index d5b2050379a..8fe7a53a629 100644 --- a/src/core/config/defaults.js +++ b/src/core/config/defaults.js @@ -85,7 +85,7 @@ const defaultOptions = Object.freeze({ }, operationsSorter: null, tagsSorter: null, - onComplete: () => {}, + onComplete: null, modelPropertyMacro: null, parameterMacro: null, }) diff --git a/src/core/config/type-cast/mappings.js b/src/core/config/type-cast/mappings.js index 4b4853aea06..b025fb1295e 100644 --- a/src/core/config/type-cast/mappings.js +++ b/src/core/config/type-cast/mappings.js @@ -18,6 +18,8 @@ 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, @@ -44,6 +46,8 @@ const mappings = { dom_id: { typeCaster: nullableStringTypeCaster }, domNode: { typeCaster: domNodeTypeCaster }, filter: { typeCaster: filterTypeCaster }, + fn: { typeCaster: objectTypeCaster }, + initialState: { typeCaster: objectTypeCaster }, layout: { typeCaster: stringTypeCaster }, maxDisplayedTags: { typeCaster: numberTypeCaster,