Swashbuckle.webapi: Uncaught TypeError: Cannot read property 'parameters' of null

Created on 25 Dec 2016  Â·  14Comments  Â·  Source: domaindrivendev/Swashbuckle.WebApi

Hi There,
Does anyone know about this error? It happened within my Asp.net web api 2 project.

image

I don't know what's going on...

Most helpful comment

I found the issue. I use Newtonsoft for serialization. By default, it appears not to ignore nulls and this has the adverse affect we see here. So...

  // simplify content negotiation to just always use json
  var jsonFormatter = new JsonMediaTypeFormatter
  {
      SerializerSettings =
      {
          ContractResolver = new CamelCasePropertyNamesContractResolver(),
          //NullValueHandling = NullValueHandling.Ignore
      }
  };
  config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter));

To fix, uncomment the NullValueHandling = NullValueHandling.Ignore

All 14 comments

+1

+1

It looks like that is a SwaggerUI issue...
Can anyone post a link to a project that reproduces this issue?

@cocogorilla
How about the source code?

Looking & Comparing the docs:
http://ssrsportal.healthsafetyinstitute.com/swagger/docs/v1
http://swashbuckletest.azurewebsites.net/swagger/docs/v1

We can see that yours have something strange:

"paths": {
    "/v1/ping": {
        "$ref": null,
        "get": null,
        "put": null,
        "post": {...},
        "delete": null,
        "options": null,
        "head": null,
        "patch": null,
        "parameters": null,
        "vendorExtensions": {}
    },
    ...
}

There should not be any nulls, you can look at mine, those are not there...

@cocogorilla
I will recommend you to create a simple WebApi project (only one controller) and add Swashbuckle with default configuration, it should work just fine....

Then start adding some of the fancy stuff you are doing on your project and test every step as you go, something is injecting those "get": null to the docs

I found the issue. I use Newtonsoft for serialization. By default, it appears not to ignore nulls and this has the adverse affect we see here. So...

  // simplify content negotiation to just always use json
  var jsonFormatter = new JsonMediaTypeFormatter
  {
      SerializerSettings =
      {
          ContractResolver = new CamelCasePropertyNamesContractResolver(),
          //NullValueHandling = NullValueHandling.Ignore
      }
  };
  config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter));

To fix, uncomment the NullValueHandling = NullValueHandling.Ignore

Just a comment... it feels like this shouldn't be an issue... that either serialization setting should be supported... but anyway, there's a workaround.

We use an old version of swagger-ui...
Maybe the new version handles this correctly.

On May 31, 2017 12:31 PM, "Ethan Nelson" notifications@github.com wrote:

Just a comment... it feels like this shouldn't be an issue... that
either serialization setting should be supported... but anyway, there's a
workaround.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/domaindrivendev/Swashbuckle/issues/967#issuecomment-305242945,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAhSwnDfKOfdCnTr1ha3t46QMQktvfDpks5r_ZX4gaJpZM4LVbVW
.

Have the same issue with the same reason that mentioned @cocogorilla.

Sorry, I didn't mention that I fixed it adding configuration

NullValueHandling = NullValueHandling.Ignore

Can I ask where i make this change?

@ventil8 try it in your WebApiConfig.cs file. There you can access the config object mentioned on @cocogorilla `s answer

Was this page helpful?
0 / 5 - 0 ratings