Coder Social home page Coder Social logo

Comments (5)

glowcloud avatar glowcloud commented on June 12, 2024

According to docs there are 4 settings that contain names with dots:

  1. syntaxHighlight.activated
  2. syntaxHighlight.theme
  3. urls.primaryName

It looks to me like request.curlOptions is not a separate option but something that we should set inside requestInterceptor, ex.:

requestInterceptor: (request) => {
  request.curlOptions = ["-g", "--limit-rate 20k"]
  return request
}

In case of urls.primaryName, there exists the urls setting but it's actually an array. The way we access it is correct, as in we take urls.primaryName as a name of a config and not as a path inside an object:

let primaryName = search["urls.primaryName"] || configs["urls.primaryName"]

It seems like the only settings that would need to be merged into another are to do with syntaxHighlight.

from swagger-ui.

glowcloud avatar glowcloud commented on June 12, 2024

It looks like the place to merge the options would be after merging the different configs

let mergedConfig = deepExtend({}, localConfig, constructorConfig, fetchedConfig || {}, queryConfig)

We need to take care of the precedence of the configs, which is:

From lowest to highest precedence:

The swagger-config.yaml in the project root directory, if it exists, is baked into the application
configuration object passed as an argument to Swagger UI (SwaggerUI({ ... }))
configuration document fetched from a specified configUrl
configuration items passed as key/value pairs in the URL query string

so we can't just overwrite the syntaxHighlight properties if we have syntaxHighlight.activated and/or syntaxHighlight.theme.

For example if we have:

  1. syntaxHighlight.activated: false passed to Swagger UI as an argument
  2. syntaxHighlight: { theme: "agate", activated: true } in the config fetched from the specified configUrl

The one that should take precedence is syntaxHighlight: { theme: "agate", activated: true }, so we can't simply do something like this:

if (mergedConfig["syntaxHighlight.activated"]) {
   mergedConfig.syntaxHighlight.activated = mergedConfig["syntaxHighlight.activated"]
}

as the result would be: syntaxHighlight: { theme: "agate", activated: false }.

Additionally, it's possible that we could initially set syntaxHighlight: false and then in the URL search params specify syntaxHighlight.activated=true, so trying to access mergedConfig.syntaxHighlight.activated would throw an error.

from swagger-ui.

glowcloud avatar glowcloud commented on June 12, 2024

A rough idea for setting syntaxHighlight:

const setSyntaxHighlight = (config) => {
  if (typeof config.syntaxHighlight === "object") {
    mergedConfig.syntaxHighlight = config.syntaxHighlight
  } else if (config.syntaxHighlight === false) {
    mergedConfig.syntaxHighlight = false
  } 

  if (config["syntaxHighlight.activated"]!= null) {
    mergedConfig.syntaxHighlight = !mergedConfig.syntaxHighlight 
      ? { activated: config["syntaxHighlight.activated"], theme: "agate" }
      : { ...mergedConfig.syntaxHighlight, activated: config["syntaxHighlight.activated"] }
  } 
  if (config["syntaxHighlight.theme"] != null) {
    mergedConfig.syntaxHighlight = !mergedConfig.syntaxHighlight 
      ? { theme: config["syntaxHighlight.theme"], activated: true}
      : { ...mergedConfig.syntaxHighlight, theme: config["syntaxHighlight.theme"] }
  }
}

setSyntaxHighlight(localConfig)
setSyntaxHighlight(combinedConfig)
setSyntaxHighlight(fetchedConfig)
setSyntaxHighlight(queryConfig)

delete mergedConfig["syntaxHighlight.activated"]
delete mergedConfig["syntaxHighlight.theme"]

from swagger-ui.

glowcloud avatar glowcloud commented on June 12, 2024

According to docs there are 3 settings that contain names with dots:

  1. syntaxHighlight.activated
  2. syntaxHighlight.theme
  3. urls.primaryName

We've decided that the only way to set these types of options would be through query parameters.

As such, we'll only need to check for them after getting query options and then set them inside the objects by using the immutable lodash set (from lodash/fp/set). After doing so, we can safely delete these settings from the query config.

from swagger-ui.

glowcloud avatar glowcloud commented on June 12, 2024

Addressed in 6923111

from swagger-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.