Skip to content

Bug with parameterMacro in 3.1.0 in returns #10448

Open
@mclei-asw

Description

@mclei-asw

Q&A

  • OS: Debian 12
  • Browser: Chome
  • Version: 135
  • Method of installation: dist assets
  • Swagger-UI version: 5.21.0
  • Swagger/OpenAPI version: OpenAPI 3.1.0

Content & configuration

  window.ui = SwaggerUIBundle({
    urls: JSON.parse(request.responseText),
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout",

    parameterMacro: function (operation, parameter) {
      if (parameter.name === "MYPARAM") {
        return "test";
      }
    },

Describe the bug you're encountering

This configuration with parameterMacro works correctly with 3.0.0 definition and this is added to each MYPARAM parameter:

Default value : test

But when I change the API definition to 3.1.0 the list of methods does not load completely and this error occurs in the console:

swagger-ui-bundle.js:2 TypeError: Invalid value used as weak map key
    at WeakMap.set (<anonymous>)
    at computeEdges (swagger-ui-bundle.js:2:783849)
    at swagger-ui-bundle.js:2:783924
    at Array.forEach (<anonymous>)
    at ArraySlice.forEach (swagger-ui-bundle.js:2:510902)
    at computeEdges (swagger-ui-bundle.js:2:783900)
    at swagger-ui-bundle.js:2:783924
    at Array.forEach (<anonymous>)
    at ArraySlice.forEach (swagger-ui-bundle.js:2:510902)
    at computeEdges (swagger-ui-bundle.js:2:783900)

The whole problem seems in expected result of the function. When the parameterMacro function "does not return", then this error occurs. When I remove the condition and always return something, it loads OK and every parameter default is set to the returned value.

    parameterMacro: function (operation, parameter) {
        return "test";
    }

I have not found what value to return when I do not want to set the default value. I have also tried returning "null", but it is also used as a default value to all parameters:

    parameterMacro: function (operation, parameter) {
      return null;
    },

then in the UI I see this for all params:

Default value : null

Expected behavior

It should be possible to return values only for selected parameters. When the function does not return anything or maybe when it returns null, it should not raise the error above and properly load the definition and fill the "default value" only when the function returns something.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions