Parser error: Parser error on line 57 end of the stream or a document separator is expected
See original GitHub issueWhen 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:
- Created 5 years ago
- Reactions:4
- Comments:12 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.jsonon 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');✔︎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.serveinstead ofswaggerUi.serveFiles(swaggerDocument, options).Here’s what worked for me: