swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Add missing default configuration options

Open glowcloud opened this issue 1 year ago • 3 comments

There are configuration options, such as modelPropertyMacro and parameterMacro, which do not have any default values defined in: https://github.com/swagger-api/swagger-ui/blob/d5e56e5d75be4edc777fb8432a484e22af690bf1/src/core/config/defaults.js#L6 We need to identify all of the missing options and assign them default values.

glowcloud avatar May 17 '24 13:05 glowcloud

The missing configs are:

  • operationsSorter
  • tagsSorter
  • onComplete
  • modelPropertyMacro
  • parameterMacro

glowcloud avatar May 17 '24 13:05 glowcloud

I think there is additional request.curlOptions as well. But needs to be researched first.

char0n avatar May 18 '24 18:05 char0n

request.curlOptions is set inside of requestInterceptor:

This can be set on the mutated request in the requestInterceptor function. For example request.curlOptions = ["-g", "--limit-rate 20k"]

The default for it is:

 requestInterceptor: (a) => a

so perhaps it should be:

requestInterceptor: (request) => {
   request.curlOptions = null;
   return request;
}

glowcloud avatar May 20 '24 09:05 glowcloud

Potential default values for each of them:

  • onComplete: () => {} - defined as Function=NOOP in documentation, used here: https://github.com/swagger-api/swagger-ui/blob/d5e56e5d75be4edc777fb8432a484e22af690bf1/src/core/plugins/on-complete/index.js#L13-L23
  • modelPropertyMacro: null - so that we don't run visitors / plugins for these
  • parameterMacro: null
  • requestInterceptor / request.curlOptions:
    (request) => {
       request.curlOptions = [];
       return request;
    }
    
  • operationsSorter: null
  • tagsSorter: null

operationsSorter and tagsSorter are used here: https://github.com/swagger-api/swagger-ui/blob/d5e56e5d75be4edc777fb8432a484e22af690bf1/src/core/plugins/spec/selectors.js#L263-L279 Considering that they are supposed to be sorting functions, I think we should have them as null so that they don't run at all. In our configuration, it says that they are: Function=(a => a) and making that default wouldn't sort anything as well, so it's also an option.

glowcloud avatar May 20 '24 11:05 glowcloud

Yes, good choice for the defaults. I would also go for a nullable-function (typecaster) for the onComplete for consistency. There is a check in code present to assert if it's a function.

For the curlOptions, as established in the PR already, we want to go for:

requestInterceptor: (request) => {
   request.curlOptions = [];
   return request;
}

char0n avatar May 21 '24 06:05 char0n

Addressed in https://github.com/swagger-api/swagger-ui/pull/9949

char0n avatar May 21 '24 10:05 char0n