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

Resolver error at requestBody.content.application/json.schema.$ref #9891

Closed
edmond-d opened this issue Apr 29, 2024 · 1 comment
Closed

Resolver error at requestBody.content.application/json.schema.$ref #9891

edmond-d opened this issue Apr 29, 2024 · 1 comment

Comments

@edmond-d
Copy link

edmond-d commented Apr 29, 2024

Q&A

  • OS: Windows 10 Enterprise
  • Browser: Firefox 115.10.0esr (64Bit)
  • Method of installation: dist
  • Swagger-UI version: 5.17.2
  • Swagger/OpenAPI version: OpenAPI 3.1.0]

Content & configuration

Example Swagger/OpenAPI definition:
Swagger Petstore OpenAPI 3.1 release 1.0.6 - openapi.json

Swagger-UI configuration options:

window.onload = function() {
  //<editor-fold desc="Changeable Configuration Block">

  // the following lines will be replaced by docker/configurator, when it runs in a docker-container
  window.ui = SwaggerUIBundle({
    //url: "https://petstore.swagger.io/v2/swagger.json",
    
    spec: {
    "openapi": "3.1.0",
    "info": {
        "title": "Swagger Petstore - OpenAPI 3.1",
    ...
},
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  });

  //</editor-fold>
};

Describe the bug you're encountering

Dear swagger-ui team,
there occurs the error „Resolver error at requestBody.content.application/json.schema.$ref“ when using swagger-ui as standalone without server, withe "spec" core parameter istead of "url".

To reproduce...

Steps to reproduce the behavior:

  1. Download Swagger UI v5.17.2 Released! (Source code (zip) ) and unpack zip file on a Windows machine
  2. Download Swagger Petstore OpenAPI 3.1 release 1.0.6 (Source code (zip) ) and unpack
  3. Make a copy from file „\swagger-ui-5.17.2\swagger-ui-5.17.2\dist\swagger-initializer.js“ and label the new file „swagger-initializer-test.js“
  4. Open the new file „\swagger-ui-5.17.2\swagger-ui-5.17.2\dist\ swagger-initializer-test.js“ in an editor.
  5. Make the line url: "https://petstore.swagger.io/v2/swagger.json, as comment -> //url: "https://petstore.swagger.io/v2/swagger.json,
  6. Add underneath the comment line spec: – See also swagger-ui configuration – Core – Parameters name spec
  7. Copy file content from„\swagger-petstore-swagger-petstore-v31-1.0.6\src\main\webapp\code-first\ openapi.json“ behind spec:
  8. Add the character , after it
  9. Save „swagger-initializer-test.js“
  10. Edit „\swagger-ui-5.17.2\swagger-ui-5.17.2\dist\index.html“ -> change „swagger-initializer.js“ to „swagger-initializer-test.js“
  11. Open „index.html“ in a Web-Browser (i.e. Firefox) and fold out the method „pet“ PUT /pet
    • The error occurs: Resolver error at requestBody.content.application/json.schema.$ref
    • The Request body – „Example Value“ is not shown correct

Expected behavior

No error

Screenshots

screenshot

@char0n
Copy link
Member

char0n commented May 7, 2024

Hi @edmond-d,

The reason that you're seeing this is that you use the index.html as a file instead serving it under HTTP server.

It is possible to put following path to browser URL bar:

file:///home/char0n/Documents/GitHub/swagger-ui/dist/index.html

This means that the dereference/resolution will now work in file system mode. baseURI is estabilished as file:///home/char0n/Documents/GitHub/swagger-ui/dist/index.html and from security reasons, SwaggerUI will NOT try to read any additional files from your filesystem due to the security reasons.

You need to serve your index.html under some HTTP server to have something like this in your browser URL bar (it needs to be served under HTTP or HTTPS protocol):

http://localhost:3200/

Now the baseURI is established as http://localhost:3200/ which dereference/resolution can and will access.


Hope this explanation helped.

@char0n char0n closed this as completed May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants