Swashbuckle.webapi: Invalid string length

Created on 29 Oct 2016  路  24Comments  路  Source: domaindrivendev/Swashbuckle.WebApi

I am having troubles to load the documentation using swagger-ui. I suspect that this happens because my json file is huge.

If necessary I can provide the JSON file, for debugging proposes, via private message.

If you need more information please just let me know.

Uncaught RangeError: Invalid string length
    at JSON.stringify (<anonymous>)
    at t.exports.u.getModelSampleJSON (http://localhost/api/swagger/ui/swagger-ui-min-js:9:748)
    at new t.exports (http://localhost/api/swagger/ui/swagger-ui-min-js:8:26467)
    at http://localhost/api/swagger/ui/swagger-ui-min-js:7:17315
    at r (http://localhost/api/swagger/ui/swagger-ui-min-js:11:12853)
    at Object.forEach (http://localhost/api/swagger/ui/swagger-ui-min-js:11:24144)
    at http://localhost/api/swagger/ui/swagger-ui-min-js:7:17041
    at http://localhost/api/swagger/ui/swagger-ui-min-js:11:22737
    at r (http://localhost/api/swagger/ui/swagger-ui-min-js:11:16261)
    at http://localhost/api/swagger/ui/swagger-ui-min-js:11:22408

Most helpful comment

yes @andrenpt that is normal.. but sometimes it makes the json huge.. the way to filter the json document is using the DocumentFilter.. check this url and let me know http://stackoverflow.com/a/31159468/2144426

All 24 comments

this problem may be caused because your json is too large, due to looped entities (entities calling same entities..). I had the same trouble and after fixing it no problem.

Hello @srebella but that is normal. Entities may have other entities as properties.
More specifically how did you solve the problem?
Did you add any extra configuration ?
Swashbuckle generates that JSON file.

yes @andrenpt that is normal.. but sometimes it makes the json huge.. the way to filter the json document is using the DocumentFilter.. check this url and let me know http://stackoverflow.com/a/31159468/2144426

@andrenpt we use circular reference and it works just fine. I am keen to understand what is the issue, as we depend on swaschbuckle heavily. Would you be able to share your json file? Try renaming definitions and properties, it would be good if you could upload it here.

Hello @dariusdamalakas I do not mind of sharing the file with you but it needs to be via private message because it has sensitive information.

@andrenpt Due to my huge circular references I had to create some special APImodel for the API so the documentator can create the JSON file.

@andrenpt - can you remove that sensitive information? remove properties / rename, change structure around. I am sure it should be possible to trim that file down a little bit. Otherwise, yes, you can send via private message.

@dariusdamalakas here it is. If you need anything else just tell me please. Thanks
json.zip

@andrenpt thanks, but this does not look like a valid swager file.

For example, here what lines 99 to 105 look. the path "/webs/sometime/" is not defined correctly, it is missing operations, etc.

"/webs/someitem/" { "someitemId" }
    "/user/",
    { "userId" },
    : {
      "get": {
        "tags": [
          "web"

Sorry about that @dariusdamalakas . Can you please try this one and let me know ?
json.zip

@andrenpt , that still looks wrong. I've pasted this json here, you should the validation error there.

http://www.jsoneditoronline.org/?id=914441c5039ad57bb3b1d5ab54f32e74

eg.:

paths: {
/Webs: {
get: {

Hello @dariusdamalakas
I have an extension in my browser that was interfering with the JSON.
Now it should be working perfect. Just tested in the website you gave me to test.
json.zip

Hello @dariusdamalakas is the file ok now for you ?

Thanks

@andrenpt , yes, that looks better now. You have duplicate mappings in your swagger file. "Company.Software.Part.SomeLayer.Models.Product" is defined twice under definitions section.

I've used swagger-cli to validate this, worked like a charm.

$ swagger validate swagger.json
SyntaxError: Error parsing "c:/work/swagger.json"
duplicated mapping key at line 4050, column 4:
                },
       ^
    at Function.ono [as syntax] (C:\Users\ddama\AppData\Roaming\npm\node_modules\swagger-cli\node_modules\swagger-parser\node_modules\ono\lib\index.js:67:20)
    at parse (C:\Users\ddama\AppData\Roaming\npm\node_modules\swagger-cli\node_modules\swagger-parser\node_modules\json-schema-ref-parser\lib\parse.js:47:17)
    at C:\Users\ddama\AppData\Roaming\npm\node_modules\swagger-cli\node_modules\swagger-parser\node_modules\json-schema-ref-parser\lib\read.js:70:23

YAMLException: duplicated mapping key at line 4050, column 4:
                },

Once again @dariusdamalakas thanks for your answer.

I think this was due to renaming the class names before sending you the .json example.

I have now tested the file using that same swagger-cli and it does not throw any error. However it does not show any success message as well so I am not sure what is going on here.
I am attaching the file to this comment.
example.zip

Hello @dariusdamalakas
Did you manage to reproduce the problem ?

Thanks for all your help with this.

swagger-cli does indeed not finish validating your schema. Can't really help more here. I'd probably start by cleaning up your swagger file.

Hello @dariusdamalakas,
Unfortunately, I will need to abandon this amazing project. I can't spend more time on trying to fix this.

Many thanks for your help! I really appreciate it.

This looks like an issue in SwaggerUI not in Swashbuckle...

@andrenpt - I'm going to close this issue for now. If you've confirmed that the Swagger JSON being generated by Swashbuckle is indeed valid Swagger, then I would have to agree with @heldersepu in saying this is really a Swagger UI issue and should be posted to that project.

If you do get a chance to look at this again, and feel it's due to an issue with Swagger that Swashbuckle generates, please feel free to reopen. Thanks

I got the same Issue on Swagger UI. Error mention below.

swagger-ui-min-js:9 Uncaught RangeError: Invalid string length
at JSON.stringify ()
at t.exports.u.getModelSampleJSON (swagger-ui-min-js:9)
at new t.exports (swagger-ui-min-js:8)
at swagger-ui-min-js:7
at r (swagger-ui-min-js:11)
at Object.forEach (swagger-ui-min-js:11)
at swagger-ui-min-js:7
at swagger-ui-min-js:11
at r (swagger-ui-min-js:11)
at swagger-ui-min-js:11

please help me, how to solve this issue.

I am using nuget package Swashbuckle on MVC Web Api Project.

yes @andrenpt that is normal.. but sometimes it makes the json huge.. the way to filter the json document is using the DocumentFilter.. check this url and let me know http://stackoverflow.com/a/31159468/2144426

Solved here! 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rautsik picture rautsik  路  4Comments

qwertykeith picture qwertykeith  路  5Comments

calexandre picture calexandre  路  5Comments

djem3000 picture djem3000  路  5Comments

josephearl picture josephearl  路  4Comments