Skip to content
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

Swagger-Editor 4.12.1 failure when using latest swagger-ui (5.17.2) as a local dependency #5000

Open
michaeljwiebe opened this issue Apr 29, 2024 · 2 comments

Comments

@michaeljwiebe
Copy link

michaeljwiebe commented Apr 29, 2024

Q&A (please complete the following information)

  • OS: macOS 12.7.4
  • Node: 18.20.2
  • Browser: Chrome
  • Version: 124.0.6367.91
  • Method of installation: npm
  • Swagger-Editor version: 4.12.1
  • Swagger-UI version:
  • Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0]

Content & configuration

src/index.js is unmodified:

import SwaggerUI from “swagger-ui-local”

const defaults = {
  // we have the `dom_id` prop for legacy reasons
  dom_id: "#swagger-editor", // eslint-disable-line camelcase
  layout: "EditorLayout",
  presets: [
    SwaggerUI.presets.apis
  ],
  plugins: [
    ...Object.values(plugins),
    () => ({ components: { EditorLayout } }),
    SwaggerUI.plugins.SafeRender({
      fullOverride: true,
      componentList: [
        "StandaloneLayout",
        "EditorLayout",
        "Topbar",
        "EditorContainer",
      ],
    })
  ],
  showExtensions: true,
  swagger2GeneratorUrl: "https://generator.swagger.io/api/swagger.json",
  oas3GeneratorUrl: "https://generator3.swagger.io/openapi.json",
  swagger2ConverterUrl: "https://converter.swagger.io/api/convert",
}

export default function SwaggerEditor(options) {
  let mergedOptions = deepMerge(defaults, options)

  mergedOptions.presets = defaults.presets.concat(options.presets || [])
  mergedOptions.plugins = defaults.plugins.concat(options.plugins || [])
  return SwaggerUI(mergedOptions)
}

SwaggerEditor.plugins = plugins

Screenshots

Screen Shot 2024-04-29 at 11 47 05 AM

How can we help?

I am unable to use a local version of Swagger-UI in place of the npm package swagger-ui with the default configuration. I get this error: TypeError Cannot set properties of undefined (setting 'runtime').

In the console I also see Uncaught TypeError: SwaggerEditorBundle is not a function at window.onload, here is the implementation that error is coming from (this was not changed, it is the default):

window.onload = function() {
    // Webpack outputs library variables with file-names-like-this
    window["SwaggerEditorBundle"] = window["SwaggerEditorBundle"] || window["swagger-editor-bundle"]
    window["SwaggerEditorStandalonePreset"] = window["SwaggerEditorStandalonePreset"] || window["swagger-editor-standalone-preset"]
    // Build a system
    const editor = SwaggerEditorBundle({
      dom_id: '#swagger-editor',
      layout: 'StandaloneLayout',
      presets: [
        SwaggerEditorStandalonePreset
      ],
      plugins: [
        SwaggerEditorStandalonePreset.plugins.TopbarNewEditorButton,
      ],
      queryConfigEnabled: true,
    })
@michaeljwiebe
Copy link
Author

We've determined the issue here was npm. Once we tried out yarn it works fine!

@michaeljwiebe
Copy link
Author

michaeljwiebe commented May 24, 2024

Reopening because this is still an issue for the repo generally, even if I'm not dealing with it anymore. I do have a PR now that fixes it though! See above ^^

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