summaryrefslogtreecommitdiff
path: root/src/core/config/factorization/system.js
blob: 864c1406fdac796160fe02e27d28d05ed721ea3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
 * @prettier
 */
import deepExtend from "deep-extend"

const systemFactorization = (options) => {
  const state = deepExtend(
    {
      layout: {
        layout: options.layout,
        filter: options.filter,
      },
      spec: {
        spec: "",
        url: options.url,
      },
      requestSnippets: options.requestSnippets,
    },
    options.initialState
  )

  if (options.initialState) {
    /**
     * If the user sets a key as `undefined`, that signals to us that we
     * should delete the key entirely.
     * known usage: Swagger-Editor validate plugin tests
     */
    for (const [key, value] of Object.entries(options.initialState)) {
      if (value === undefined) {
        delete state[key]
      }
    }
  }

  return {
    system: {
      configs: options.configs,
    },
    plugins: options.presets,
    state,
  }
}

export default systemFactorization