Parser error: Parser error on line 57 end of the stream or a document separator is expected

See original GitHub issue

When I trying to use (local) swagger.json file I have got a problem with parsing/validating. Its working locally on http://localhost:8080/ but when I try to load the index.html file on browser it shown error: “Parser error: Parser error on line 57 end of the stream or a document separator is expected”. I set “validatorUrl: null,” in dist/index.html and fix CORS but problem is still exists. What is a problem here? Is there any configuration tips? It looks like Dist bug

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? V/3.13.3 (#4420)
Which Swagger-UI version?
How did you install Swagger-UI? Github download
Which browser & version? Chrome
Which operating system? Win10

Demonstration API definition - full swagger.json file

{
  "swagger": "2.0",
  "info": {
    "version": "1.0",
    "title": "tytul",
    "contact": {
      "name": "mario",
      "email": "a@b.com"
    }
  },
  "host": "127.0.0.1:8080",
  "basePath": "/datasnap/rest/TServerMethods1/",
  "schemes": [
    "http"
  ],
  "paths": {
    "/test": {
      "get": {
        "description": "Main Desc",
        "parameters": [
          {
            "in": "query",
            "name": "some name",
            "description": "desc",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "some desc"
          }
        }
      }
    }
  }
}

Configuration (dist/swagger.json)

{
  window.onload = function() {
  
  // Build a system 
  const ui = SwaggerUIBundle({
    url: "./swagger.json",
    dom_id: '#swagger-ui',
    deepLinking: true,
	validatorUrl: null,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  })
  window.ui = ui
}
}

Expected Behavior

Current Behavior

Possible Solution

Context

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
azaeng04commented, Jan 3, 2019

What is the problem?

@shockey any progress on finding a solution for this? I am experiencing the same error as @maniutek20. I loaded my swagger.json on https://editor.swagger.io/ after converting it to YAML and it displays correctly.

Solution

If you are making use of swagger-ui js. Require your JSON doc and do not use import. It complains about that for some reason.

No

import { serve, setup } from 'swagger-ui-express'; ✔︎ import swaggerDoc from ./api/swagger/swagger.json';

Yes

import { serve, setup } from 'swagger-ui-express'; ✔︎ const swaggerDoc = require('./api/swagger/swagger.json'); ✔︎

0reactions
kyle-marshallcommented, Dec 10, 2022

I was facing what appeared to be the same issue. I stumbled on something that works by modifying the “Modify swagger file on the fly before load” example from the main examples on the npm page. I had to stray from the example and use swaggerUI.serve instead of swaggerUi.serveFiles(swaggerDocument, options).

Here’s what worked for me:

let swaggerDocument: any = null;

const prepareSwaggerDoc: Handler = async (req, res, next) => {
    const path = "docs/combined.json";
    const data = await readFile(path);
    swaggerDocument = JSON.parse(data.toString("utf8"));
    (req as any).swaggerDoc = swaggerDocument;
    console.log(swaggerDocument);
    next();
};

const router = Router();
router.use("/", prepareSwaggerDoc, swaggerUI.serve, swaggerUI.setup());
Read more comments on GitHub >

github_iconTop Results From Across the Web

YAML error : end of the stream or a document separator is ...
When the second line is read, the YAML processor sees a : which is not allowed here. At this point, both lines have...
Read more >
A "Parser error" occurs in Swagger when you use GET /api ...
Errors Parser error end of the stream or a document separator is expected. The error occurs because the REST request is not returning...
Read more >
Swagger-Editor: trying to save locally (Backend)
This breaks swagger-editor and will not save the file locally, regardless of whether I set useYamlBackend to true or false. YAML Syntax Error...
Read more >
SWAGGER: Parser error on line 27 end of the stream or a ...
When i try to get the API schema from swagger for an actuve customer y get this error. Parser error on line 27...
Read more >
How to Fix the "Parse Error: Syntax Error, Unexpected" in ...
Unexpected – This means the code is missing a character and PHP reaches the end of the file without finding what it's looking...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found