Convert from definiton to json payload for POST/PUT operation

19 views
Skip to first unread message

shreeji...@gmail.com

unread,
May 26, 2016, 11:41:46 PM5/26/16
to Swagger
Hi,

1. Does anyone know a way to convert a fully resolved definition to a json data payload that can be used in a post operation in Java?

Essentially go from:

Pet
{
  "type" : "object",
  "required" : [ "name", "photoUrls" ],
  "properties" : {
    "id" : {
      "type" : "integer",
      "format" : "int64"
    },
    "category" : {
      "type" : "object",
      "xml" : {
        "name" : "Category"
      },
      "properties" : {
        "id" : {
          "type" : "integer",
          "format" : "int64"
        },
        "name" : {
          "type" : "string"
        }
      }
    },
    "name" : {
      "type" : "string",
      "example" : "doggie"
    },
    "photoUrls" : {
      "type" : "array",
      "xml" : {
        "name" : "photoUrl",
        "wrapped" : true
      },
      "items" : {
        "type" : "string"
      }
    },
    "tags" : {
      "type" : "array",
      "xml" : {
        "name" : "tag",
        "wrapped" : true
      },
      "items" : {
        "type" : "object",
        "xml" : {
          "name" : "Tag"
        },
        "properties" : {
          "id" : {
            "type" : "integer",
            "format" : "int64"
          },
          "name" : {
            "type" : "string"
          }
        }
      }
    },
    "status" : {
      "type" : "string",
      "description" : "pet status in the store",
      "enum" : [ "available", "pending", "sold" ]
    }
  },
  "xml" : {
    "name" : "Pet"
  },
  "x-swagger-router-model" : "Pet"
}

to the actual data payload that needs to be used within a POST / PUT operation:

{
  "id": 0,
  "category": {
    "id": 0,
    "name": "string"
  },
  "name": "doggie",
  "photoUrls": [
    "string"
  ],
  "tags": [
    {
      "id": 0,
      "name": "string"
    }
  ],
  "status": "available"
}


2. Is there a way to fake data into the payload using Java? By faking I mean replacing data types with random data for subsequent test runs


Regards
Shreejit
Reply all
Reply to author
Forward
0 new messages