Skip to content

Bug with parameterMacro in 3.1.0 in returns #10448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mclei-asw opened this issue May 15, 2025 · 1 comment
Open

Bug with parameterMacro in 3.1.0 in returns #10448

mclei-asw opened this issue May 15, 2025 · 1 comment

Comments

@mclei-asw
Copy link

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.

@mclei-asw mclei-asw changed the title Bug with parameterMacro in 3.1.0 with returns Bug with parameterMacro in 3.1.0 in returns May 15, 2025
@mclei-asw
Copy link
Author

I have fixed it by attached patch. I don't know whether all occurrences are required, but at least one of them solves the problem when parameterMacro does not return any value.

swagger-client_parameterMacro.patch.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant