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

Extend OpenAPISpecGeneratorPlugin to include default values for parameters

Open garrytrinder opened this issue 9 months ago • 4 comments

Azure API endpoints use the api-version query string parameter to version endpoints.

When using Dev Proxy to generate an OpenAPI spec the api-version parameter in not included in the generated document. This leads to an error when issuing a request as the api-version parameter is not sent.

We should look to include this as a parameter in generated documents with a default value.

      parameters:
        - name: api-version
          in: query
          required: true
          schema:
            type: string
            default: "2024-11-01-preview"

garrytrinder avatar Apr 08 '25 15:04 garrytrinder

OK, so I can see the param included in the generated spec but it's missing the default value:

Image

We can definitely include the specified value as default. What do you think: should we do it by default, or should it be an option, like currentValueAsDefault, which is set to false by default but when set to true copies the values from the intercepted requests as defaults?

I see also that in the generated spec, the param is not marked as required. Do you know if that's necessary for agents to always include the param in the API request?

waldekmastykarz avatar Apr 09 '25 07:04 waldekmastykarz

should we do it by default, or should it be an option, like currentValueAsDefault, which is set to false by default but when set to true copies the values from the intercepted requests as defaults?

I think for ease it would be easier to use the value from the request as the default value.

Thinking about it some more, should we have an array of known parameters like api-version in the configuration, but which developers can override with their own param names?

I see also that in the generated spec, the param is not marked as required. Do you know if that's necessary for agents to always include the param in the API request?

In this case yes, not sending the param results in an error from the API.

garrytrinder avatar Apr 09 '25 13:04 garrytrinder

I think for ease it would be easier to use the value from the request as the default value.

The reason I'd prefer to expose it via an option and an explicit opt-in is because of potential PII that could end up in the spec.

Thinking about it some more, should we have an array of known parameters like api-version in the configuration, but which developers can override with their own param names?

We already have a list of standard headers. We could go about it in two ways:

  1. Allow customers to specify parameters to exclude and we include everything else
  2. Allow customers to specify parameters to include and we exclude everything else

We could offer both options and customers can decide which way they want to go about it.

waldekmastykarz avatar Apr 09 '25 13:04 waldekmastykarz

Good shout on PII, then an option makes sense.

I'd say go with an include list, option 2.

garrytrinder avatar Apr 09 '25 13:04 garrytrinder

working on it.

Summarizing, We need the following:

  • add a config property of the plugin named like ParametersWithDefaults or DefaultedParameters with an array of strings;
  • capture parameters from query string applying the case-sensitive comparison;
  • render the spec as described in the issue. The included parameter must also have two attributes required=true and default=.

@waldekmastykarz How does that sound?

Noticed that the plugin does not handle query string arrays (multiple the same parameter), in the case, the value is a string and rendered as "val1,val2,val3".

bartizan avatar Jul 08 '25 12:07 bartizan

How about we named the configuration value IncludeParameters? Other than that, agree with what you proposed. We appreciate your help!

waldekmastykarz avatar Jul 09 '25 11:07 waldekmastykarz

@waldekmastykarz, all is merged, the issue could be closed.

bartizan avatar Jul 16 '25 06:07 bartizan