dev-proxy icon indicating copy to clipboard operation
dev-proxy copied to clipboard

Simplify config by removing default values

Open waldekmastykarz opened this issue 9 months ago • 3 comments

@svrooij proposed an idea to simplify config by removing default values. Specifically, for each plugin, we repeat the assembly name and "enabled: true". We could simplify the config by assuming default values and only specify them explicitly if they're different (eg. a custom plugin from a different assembly or plugin disabled).

waldekmastykarz avatar May 08 '24 06:05 waldekmastykarz

What do you think @garrytrinder?

waldekmastykarz avatar May 08 '24 06:05 waldekmastykarz

But you cannot name it enabled, because the default value for a bool is false.

svrooij avatar May 08 '24 06:05 svrooij

But you cannot name it enabled, because the default value for a bool is false.

If we define the value as nullable bool then we can default to null when it's not set and fallback to our default of true.

waldekmastykarz avatar May 08 '24 07:05 waldekmastykarz

To give some more context, here's before and after for two of our presets.

Default

Before

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.18.0/rc.schema.json",
  "plugins": [
    {
      "name": "RetryAfterPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
    },
    {
      "name": "GenericRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "genericRandomErrorPlugin"
    }
  ],
  "urlsToWatch": [
    "https://jsonplaceholder.typicode.com/*"
  ],
  "genericRandomErrorPlugin": {
    "errorsFile": "devproxy-errors.json"
  },
  "rate": 50,
  "logLevel": "information",
  "newVersionNotification": "stable"
}

After

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.18.0/rc.schema.json",
  "plugins": [
    {
      "name": "RetryAfterPlugin"
    },
    {
      "name": "GenericRandomErrorPlugin",
      "configSection": "genericRandomErrorPlugin"
    }
  ],
  "urlsToWatch": [
    "https://jsonplaceholder.typicode.com/*"
  ],
  "genericRandomErrorPlugin": {
    "errorsFile": "devproxy-errors.json"
  },
  "rate": 50,
  "logLevel": "information",
  "newVersionNotification": "stable"
}

M365 preset

Before

{
    "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.18.0/rc.schema.json",
    "plugins": [
      {
        "name": "DevToolsPlugin",
        "enabled": false,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "configSection": "devTools"
      },
      {
        "name": "LatencyPlugin",
        "enabled": false,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "configSection": "latencyPlugin"
      },
      {
        "name": "RetryAfterPlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
      },
      {
        "name": "GraphSelectGuidancePlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "urlsToWatch": [
          "https://graph.microsoft.com/v1.0/*",
          "https://graph.microsoft.com/beta/*",
          "https://graph.microsoft.us/v1.0/*",
          "https://graph.microsoft.us/beta/*",
          "https://dod-graph.microsoft.us/v1.0/*",
          "https://dod-graph.microsoft.us/beta/*",
          "https://microsoftgraph.chinacloudapi.cn/v1.0/*",
          "https://microsoftgraph.chinacloudapi.cn/beta/*"
        ]
      },
      {
        "name": "ODSPSearchGuidancePlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "urlsToWatch": [
          "https://graph.microsoft.com/v1.0/*",
          "https://graph.microsoft.com/beta/*",
          "https://graph.microsoft.us/v1.0/*",
          "https://graph.microsoft.us/beta/*",
          "https://dod-graph.microsoft.us/v1.0/*",
          "https://dod-graph.microsoft.us/beta/*",
          "https://microsoftgraph.chinacloudapi.cn/v1.0/*",
          "https://microsoftgraph.chinacloudapi.cn/beta/*"
        ]
      },
      {
        "name": "GraphBetaSupportGuidancePlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "urlsToWatch": [
          "https://graph.microsoft.com/beta/*",
          "https://graph.microsoft.us/beta/*",
          "https://dod-graph.microsoft.us/beta/*",
          "https://microsoftgraph.chinacloudapi.cn/beta/*"
        ]
      },
      {
        "name": "GraphConnectorGuidancePlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "urlsToWatch": [
          "https://graph.microsoft.com/*/external/connections/*/schema",
          "https://graph.microsoft.us/*/external/connections/*/schema",
          "https://dod-graph.microsoft.us/*/external/connections/*/schema",
          "https://microsoftgraph.chinacloudapi.cn/*/external/connections/*/schema"
        ]
      },
      {
        "name": "GraphSdkGuidancePlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "urlsToWatch": [
          "https://graph.microsoft.com/v1.0/*",
          "https://graph.microsoft.com/beta/*",
          "https://graph.microsoft.us/v1.0/*",
          "https://graph.microsoft.us/beta/*",
          "https://dod-graph.microsoft.us/v1.0/*",
          "https://dod-graph.microsoft.us/beta/*",
          "https://microsoftgraph.chinacloudapi.cn/v1.0/*",
          "https://microsoftgraph.chinacloudapi.cn/beta/*"
        ]
      },
      {
        "name": "ODataPagingGuidancePlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
      },
      {
        "name": "GraphClientRequestIdGuidancePlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "urlsToWatch": [
          "https://graph.microsoft.com/v1.0/*",
          "https://graph.microsoft.com/beta/*",
          "https://graph.microsoft.us/v1.0/*",
          "https://graph.microsoft.us/beta/*",
          "https://dod-graph.microsoft.us/v1.0/*",
          "https://dod-graph.microsoft.us/beta/*",
          "https://microsoftgraph.chinacloudapi.cn/v1.0/*",
          "https://microsoftgraph.chinacloudapi.cn/beta/*"
        ]
      },
      {
        "name": "CachingGuidancePlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "configSection": "cachingGuidance"
      },
      {
        "name": "RateLimitingPlugin",
        "enabled": false,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "configSection": "rateLimiting"
      },
      {
        "name": "MockResponsePlugin",
        "enabled": false,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "configSection": "mocksPlugin"
      },
      {
        "name": "GraphMockResponsePlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "configSection": "mocksPlugin"
      },
      {
        "name": "GraphRandomErrorPlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "configSection": "graphRandomErrorsPlugin"
      },
      {
        "name": "ExecutionSummaryPlugin",
        "enabled": false,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "configSection": "executionSummaryPlugin"
      },
      {
        "name": "MinimalPermissionsPlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "configSection": "minimalPermissionsPlugin"
      },
      {
        "name": "MinimalPermissionsGuidancePlugin",
        "enabled": false,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
      },
      {
        "name": "MockGeneratorPlugin",
        "enabled": false,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
      }      
    ],
    "urlsToWatch": [
      "https://graph.microsoft.com/v1.0/*",
      "https://graph.microsoft.com/beta/*",
      "https://graph.microsoft.us/v1.0/*",
      "https://graph.microsoft.us/beta/*",
      "https://dod-graph.microsoft.us/v1.0/*",
      "https://dod-graph.microsoft.us/beta/*",
      "https://microsoftgraph.chinacloudapi.cn/v1.0/*",
      "https://microsoftgraph.chinacloudapi.cn/beta/*",
      "https://*.sharepoint.*/*_api/*",
      "https://*.sharepoint.*/*_vti_bin/*",
      "https://*.sharepoint-df.*/*_api/*",
      "https://*.sharepoint-df.*/*_vti_bin/*"
    ],
    "mocksPlugin": {
      "mocksFile": "m365-mocks.json"
    },
    "graphRandomErrorsPlugin": {
      "allowedErrors": [ 429, 500, 502, 503, 504, 507 ]
    },
    "executionSummaryPlugin": {
      "groupBy": "url"
    },
    "minimalPermissionsPlugin": {
      "type": "delegated"
    },
    "cachingGuidance": {
      "cacheThresholdSeconds": 5
    },
    "latencyPlugin": {
      "minMs": 200,
      "maxMs": 10000
    },
    "devTools": {
      "preferredBrowser": "Edge"
    },
    "rateLimiting": {
      "costPerRequest": 2,
      "rateLimit": 120,
      "retryAfterSeconds": 5
    },
    "rate": 50,
    "labelMode": "text",
    "logLevel": "information"
  }
  

After

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.18.0/rc.schema.json",
  "plugins": [
    {
      "name": "DevToolsPlugin",
      "enabled": false,
      "configSection": "devTools"
    },
    {
      "name": "LatencyPlugin",
      "enabled": false,
      "configSection": "latencyPlugin"
    },
    {
      "name": "RetryAfterPlugin"
    },
    {
      "name": "GraphSelectGuidancePlugin",
      "urlsToWatch": [
        "https://graph.microsoft.com/v1.0/*",
        "https://graph.microsoft.com/beta/*",
        "https://graph.microsoft.us/v1.0/*",
        "https://graph.microsoft.us/beta/*",
        "https://dod-graph.microsoft.us/v1.0/*",
        "https://dod-graph.microsoft.us/beta/*",
        "https://microsoftgraph.chinacloudapi.cn/v1.0/*",
        "https://microsoftgraph.chinacloudapi.cn/beta/*"
      ]
    },
    {
      "name": "ODSPSearchGuidancePlugin",
      "urlsToWatch": [
        "https://graph.microsoft.com/v1.0/*",
        "https://graph.microsoft.com/beta/*",
        "https://graph.microsoft.us/v1.0/*",
        "https://graph.microsoft.us/beta/*",
        "https://dod-graph.microsoft.us/v1.0/*",
        "https://dod-graph.microsoft.us/beta/*",
        "https://microsoftgraph.chinacloudapi.cn/v1.0/*",
        "https://microsoftgraph.chinacloudapi.cn/beta/*"
      ]
    },
    {
      "name": "GraphBetaSupportGuidancePlugin",
      "urlsToWatch": [
        "https://graph.microsoft.com/beta/*",
        "https://graph.microsoft.us/beta/*",
        "https://dod-graph.microsoft.us/beta/*",
        "https://microsoftgraph.chinacloudapi.cn/beta/*"
      ]
    },
    {
      "name": "GraphConnectorGuidancePlugin",
      "urlsToWatch": [
        "https://graph.microsoft.com/*/external/connections/*/schema",
        "https://graph.microsoft.us/*/external/connections/*/schema",
        "https://dod-graph.microsoft.us/*/external/connections/*/schema",
        "https://microsoftgraph.chinacloudapi.cn/*/external/connections/*/schema"
      ]
    },
    {
      "name": "GraphSdkGuidancePlugin",
      "urlsToWatch": [
        "https://graph.microsoft.com/v1.0/*",
        "https://graph.microsoft.com/beta/*",
        "https://graph.microsoft.us/v1.0/*",
        "https://graph.microsoft.us/beta/*",
        "https://dod-graph.microsoft.us/v1.0/*",
        "https://dod-graph.microsoft.us/beta/*",
        "https://microsoftgraph.chinacloudapi.cn/v1.0/*",
        "https://microsoftgraph.chinacloudapi.cn/beta/*"
      ]
    },
    {
      "name": "ODataPagingGuidancePlugin"
    },
    {
      "name": "GraphClientRequestIdGuidancePlugin",
      "urlsToWatch": [
        "https://graph.microsoft.com/v1.0/*",
        "https://graph.microsoft.com/beta/*",
        "https://graph.microsoft.us/v1.0/*",
        "https://graph.microsoft.us/beta/*",
        "https://dod-graph.microsoft.us/v1.0/*",
        "https://dod-graph.microsoft.us/beta/*",
        "https://microsoftgraph.chinacloudapi.cn/v1.0/*",
        "https://microsoftgraph.chinacloudapi.cn/beta/*"
      ]
    },
    {
      "name": "CachingGuidancePlugin",
      "configSection": "cachingGuidance"
    },
    {
      "name": "RateLimitingPlugin",
      "configSection": "rateLimiting"
    },
    {
      "name": "MockResponsePlugin",
      "enabled": false,
      "configSection": "mocksPlugin"
    },
    {
      "name": "GraphMockResponsePlugin",
      "configSection": "mocksPlugin"
    },
    {
      "name": "GraphRandomErrorPlugin",
      "configSection": "graphRandomErrorsPlugin"
    },
    {
      "name": "ExecutionSummaryPlugin",
      "enabled": false,
      "configSection": "executionSummaryPlugin"
    },
    {
      "name": "MinimalPermissionsPlugin",
      "configSection": "minimalPermissionsPlugin"
    },
    {
      "name": "MinimalPermissionsGuidancePlugin"
    },
    {
      "name": "MockGeneratorPlugin",
      "enabled": false
    }      
  ],
  "urlsToWatch": [
    "https://graph.microsoft.com/v1.0/*",
    "https://graph.microsoft.com/beta/*",
    "https://graph.microsoft.us/v1.0/*",
    "https://graph.microsoft.us/beta/*",
    "https://dod-graph.microsoft.us/v1.0/*",
    "https://dod-graph.microsoft.us/beta/*",
    "https://microsoftgraph.chinacloudapi.cn/v1.0/*",
    "https://microsoftgraph.chinacloudapi.cn/beta/*",
    "https://*.sharepoint.*/*_api/*",
    "https://*.sharepoint.*/*_vti_bin/*",
    "https://*.sharepoint-df.*/*_api/*",
    "https://*.sharepoint-df.*/*_vti_bin/*"
  ],
  "mocksPlugin": {
    "mocksFile": "m365-mocks.json"
  },
  "graphRandomErrorsPlugin": {
    "allowedErrors": [ 429, 500, 502, 503, 504, 507 ]
  },
  "executionSummaryPlugin": {
    "groupBy": "url"
  },
  "minimalPermissionsPlugin": {
    "type": "delegated"
  },
  "cachingGuidance": {
    "cacheThresholdSeconds": 5
  },
  "latencyPlugin": {
    "minMs": 200,
    "maxMs": 10000
  },
  "devTools": {
    "preferredBrowser": "Edge"
  },
  "rateLimiting": {
    "costPerRequest": 2,
    "rateLimit": 120,
    "retryAfterSeconds": 5
  },
  "rate": 50,
  "labelMode": "text",
  "logLevel": "information"
}

waldekmastykarz avatar May 16 '24 12:05 waldekmastykarz

We decided, that the little gain of brevity is not worth trading it off for less clarity. If we remove default options, it's for example no longer self explanatory that you can turn a plugin off or that you need to specify the assembly path when loading a custom plugin. We'll keep the current setup as-is.

waldekmastykarz avatar May 22 '24 12:05 waldekmastykarz