4

I have the following JSON that I have generated myself from code. I am basically writing code to generate swagger spec for the UI. I am writing a new one because I still use play 1.3 and the swagger module for that has not been updated in a while. However, I got this JSON from my code generator, but UI hangs at "fetching resource list: http://localhost:9100/resources.json; Please wait." The javascript console shows the error "Getting "Cannot read property 'parameters' of null" for swagger spec". I do not what to make of this and any help would be appreciated.

     {
  "swagger": "2.0",
  "info": null,
  "host": null,
  "basePath": null,
  "tags": [
    {
      "name": "payments",
      "description": null,
      "externalDocs": null
    }
  ],
  "schemes": null,
  "consumes": null,
  "produces": null,
  "paths": {
    "/": {
      "get": {
        "tags": [
          "payments"
        ],
        "summary": "/payment_methods",
        "description": "",
        "operationId": "paymentMethods",
        "schemes": null,
        "consumes": null,
        "produces": [
          "application/json"
        ],
        "parameters": [],
        "responses": {
          "default": {
            "description": "successful operation",
            "schema": null,
            "examples": null,
            "headers": null
          }
        },
        "security": null,
        "externalDocs": null,
        "deprecated": null
      },
      "head": null,
      "post": {
        "tags": [
          "payments"
        ],
        "summary": null,
        "description": null,
        "operationId": "addPaypalAccount",
        "schemes": null,
        "consumes": null,
        "produces": null,
        "parameters": [],
        "responses": {
          "default": {
            "description": "successful operation",
            "schema": null,
            "examples": null,
            "headers": null
          }
        },
        "security": null,
        "externalDocs": null,
        "deprecated": null
      },
      "put": null,
      "delete": {
        "tags": [
          "payments"
        ],
        "summary": null,
        "description": null,
        "operationId": "deletePaypalAccount",
        "schemes": null,
        "consumes": null,
        "produces": null,
        "parameters": [],
        "responses": {
          "default": {
            "description": "successful operation",
            "schema": null,
            "examples": null,
            "headers": null
          }
        },
        "security": null,
        "externalDocs": null,
        "deprecated": null
      },
      "options": null,
      "patch": null,
      "parameters": null
    }
  },
  "securityDefinitions": null,
  "definitions": null,
  "parameters": null,
  "responses": null,
  "externalDocs": null,
  "securityRequirement": null
}
  • Do you need to escape, use quotes or otherwise change the format where you have paths:{ /: { ? My Json editor forced me to change it to '/'. – Bindrid Dec 21 '15 at 19:52
  • Oh I am sorry. The quotes got removed because of a JSON view extension that I use. The quotes are there and the JSON is valid. I modified the question with the actual JSON now. What do you mean by change the format? – Abhishek Shukla Ravishankara Dec 21 '15 at 19:57

2 Answers2

3

The issue is the null values. They need to be disabled--null is different than "not present". That said, I believe you need to configure your mapper to not write nulls.

fehguy
  • 6,724
  • 25
  • 23
  • Yes, I think you are right. My code now supports jax-rs style annotations (since swagger annotations wont let me mark independent paths) and during the process of adding those, I did configure the mapper to write non nulls only. Seems to work now. – Abhishek Shukla Ravishankara Dec 24 '15 at 02:57
1

I was having this issue and it turned out to be related to the JSON formatter in my .NET web api app. I was able to get it resolved by adding this line to the BootStrap class Configure method.

config.Formatters.Clear();
PutoTropical
  • 113
  • 1
  • 9
  • I was using JsonContentNegotiator to force JSON responses from here: https://stackoverflow.com/a/18145616/647728 and needed to add `jsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;` into the WebApiConfig – agrath Oct 29 '18 at 10:01