Hi Shreejit,

I have followed this thread and the code works fine but when i generated 
object i get teh value as below.Can you tell me how to create the 
datastructure from it.

{
  "name" : "createFoldersRequest",
  "attribute" : false,
  "wrapped" : false,
  "typeName" : "object",
  "values" : {
    "folders" : {
      "name" : "createFoldersRequestArray",
      "attribute" : false,
      "wrapped" : false,
      "typeName" : "array",
      "items" : [ {
        "name" : "createFoldersRequestArrayContent",
        "attribute" : false,
        "wrapped" : false,
        "typeName" : "object",
        "values" : {
          "folder" : {
            "attribute" : false,
            "wrapped" : false,
            "typeName" : "object",
            "values" : {
              "name" : {
                "attribute" : false,
                "wrapped" : false,
                "typeName" : "string",
                "value" : "string"
              },
              "indexingDisabled" : {
                "attribute" : false,
                "wrapped" : false,
                "typeName" : "boolean",
                "value" : true
              },
              "note" : {
                "attribute" : false,
                "wrapped" : false,
                "typeName" : "string",
                "value" : "string"
              },
}

On Wednesday, 29 June 2016 23:04:41 UTC+5:30, Shreejit Nair wrote:
>
> I think it should always be a ref model or an Array model.
>
> I do not  use the ResolveFully()
>
> This is what I am doing:
>
> if (model instanceof RefModel) {
>                             System.out.println("Model was found of type 
> RefModel");
>                             RefModel ref = (RefModel) model;
>                             String simpleRef = ref.getSimpleRef();
>                             System.out.println(simpleRef);
>                             Model concreteModel = 
> swagger.getDefinitions().get(simpleRef);
>                             Object test = ExampleBuilder.fromProperty(
>                                     new 
> io.swagger.models.properties.RefProperty(simpleRef), definitionMap);
>
>                             if (test != null && consumesList != null) {
>                                 if 
> (consumesList.contains("application/json")) { // similar block if type is 
> xml and so on
>                                     jsonString = Json.pretty(test);
>
>                                   // build a data structure out of it
>
> What I am essentially doing is build some data structure that converts the 
> swagger into an object model that can be pushed to a test automation 
> framework.
> Then i use RestAssured to automatically validate it for each endpoint on 
> the spec and do some basic sanity tests on them:
>
>
> case "post":
>
>                 if (dataMap.get("validdata") != null) { // check to see if 
> we managed to pull out the example data feed it to a client automatically
>
>                     // Valid data
>                     String schema = (String) ((Map) 
> dataMap.get("validdata")).get("schema");
>                     String body = (String) ((Map) 
> dataMap.get("validdata")).get("data");
>                     String url = dataMap.get("baseURI") + endpointOutput;
>
>                     Response rep = 
> RestAssured.given().contentType(schema).when().body(body).post(url);
>                     softAssert.assertEquals(rep.getStatusCode(), 
> HttpStatus.SC_OK);
>        
>               else
>                      Assert.fail("Example data is missing or no Consumes 
> section for endpoint" + endpointOutput
>                             + " and operation " + 
> endpointOperationOutput.toLowerCase());
>
> So everything is being extracted from the swagger.
> We are essentially trying to 1. run some basic tests programmatically   2. 
> find any gaps in the swagger spec which would be a documentation failure, 
> that is we simply cannot test without this data and we dont want to work 
> around it, rather update the spec and try again
>
> We are trying to build an automation framework that uses only the swagger 
> path and nothing else and see how far we can take it.
> Input to framework: "http://petstore.swagger.io/v2/swagger.json";
>
> All the assertion points come from within the spec itself.
>
> Shreejit
>
> On Wed, Jun 29, 2016 at 10:29 AM, <subhasis...@gmail.com <javascript:>> 
> wrote:
>
>> Hi All,
>>
>> What if the model  is not instanceof RefModel or model is 
>> not instanceof ArrayModel.
>>
>> how can we get the example for other Model types.
>>
>> *Thanks*
>> *Subhasish*
>>
>>
>> On Tuesday, 28 June 2016 20:23:06 UTC+5:30, tony tam wrote:
>>>
>>> Great, thank you for following up on it
>>>
>>> On Jun 28, 2016, at 10:52 AM, Shreejit Nair <shreeji...@gmail.com> 
>>> wrote:
>>>
>>> Thank you so much Tony,
>>>
>>> I am able able to extract the sample json / sample xml / sample array 
>>> all out now to push it automatically. So everything on the swagger UI i am 
>>> able to retrieve it from the backend.
>>> Thanks for all the help and guidance.
>>>
>>> Shreejit
>>>
>>> On Mon, Jun 27, 2016 at 4:57 PM, tony tam <feh...@gmail.com> wrote:
>>>
>>>> Hi Shreejit, anywhere you have the interfaces, you may get a compatible 
>>>> concrete class.  Consider testing different definitions on your side to 
>>>> see 
>>>> what the concrete types are in the Swagger.java class.
>>>>
>>>> On Jun 27, 2016, at 1:48 PM, Shreejit Nair <shreeji...@gmail.com> 
>>>> wrote:
>>>>
>>>> Hi Tony,
>>>> I managed to do this way without the ResolveFully().
>>>> Please let me know if the model can be RefModel or ArrayModel only when 
>>>> we try to dereference $ref to feed the actual values.
>>>>
>>>> if (model instanceof RefModel) {
>>>>
>>>> System.out.println("Model was found of type RefModel");
>>>>
>>>> RefModel ref = (RefModel) model;
>>>>
>>>> String simpleRef = ref.getSimpleRef();
>>>>
>>>> System.out.println(simpleRef);
>>>>
>>>> Model concreteModel = swagger.getDefinitions().get(simpleRef);
>>>>
>>>> Object test = ExampleBuilder.fromProperty(
>>>>
>>>> new io.swagger.models.properties.RefProperty(simpleRef), definitionMap
>>>> );
>>>>
>>>> if (test != null) {
>>>>
>>>> String str = new XmlExampleSerializer().serialize((Example) test);
>>>>
>>>> System.out.println(str);
>>>>
>>>> }
>>>>
>>>>
>>>> } else if (model instanceof ArrayModel) {
>>>>
>>>> ArrayModel arrayModel = (ArrayModel) model;
>>>>
>>>> Property prop = arrayModel.getItems();
>>>>
>>>> if (prop instanceof RefProperty) {
>>>>
>>>> Object test = ExampleBuilder.fromProperty(prop, definitionMap);
>>>>
>>>>
>>>> if (test != null) {
>>>>
>>>> String str = new XmlExampleSerializer().serialize((Example) test);
>>>>
>>>> System.out.println(str);
>>>>
>>>> }
>>>>
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>> On Monday, June 27, 2016 at 8:40:34 AM UTC-4, Shreejit Nair wrote:
>>>>>
>>>>> Hi,
>>>>> I am wondering if anyone has luck trying to use ExampleBuilder to push 
>>>>> in default data that comes along with the swagger specification document 
>>>>> into one of the operations. I am automatically trying to post to an 
>>>>> endpoint with the sample data that is defined and which we can see from 
>>>>> the 
>>>>> swagger UI.
>>>>> I already have most of the object model extracted from the spec but 
>>>>> unable to find a way how to execute a certain operation with the data 
>>>>> provided in the swagger programmatically rather than from the UI.
>>>>> Any working example would be really helpful.
>>>>>
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Swagger" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to swagger-swaggersocket+unsubscr...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>>
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to a topic in the 
>>>> Google Groups "Swagger" group.
>>>> To unsubscribe from this topic, visit 
>>>> https://groups.google.com/d/topic/swagger-swaggersocket/R4dcZ2nvXCE/unsubscribe
>>>> .
>>>> To unsubscribe from this group and all its topics, send an email to 
>>>> swagger-swaggersocket+unsubscr...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Swagger" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to swagger-swaggersocket+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Swagger" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/swagger-swaggersocket/R4dcZ2nvXCE/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to 
>> swagger-swaggersocket+unsubscr...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to swagger-swaggersocket+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to