I have no knowledge of jsonschema2pojo.

 

Your Example.java is a pojo, not an array.

Your API method signature in the java code is incomplete (there’s no return 
type) so I can’t tell whether you return the array of the object, or whether 
you use the Response class.

If you just return the array of the object, it should work OOTB.

If you return a Response, you can use the @ApiOperation to set the 
responseContainer to be a List and that should describe it as an array.

 

 

 

 

From: <[email protected]> on behalf of sdav 
<[email protected]>
Reply-To: "[email protected]" 
<[email protected]>
Date: Tuesday, 16 August 2016 at 14:49
To: Swagger <[email protected]>
Subject: Re: issue with the model schema

 

Hi Ron, 

 

Thanks for the reply . I am extremely sorry for posting the wrong schema.  This 
is the schema i have defined for the api. which than i converted in to Jackson 
annotated pojo class using  plugin provided by http://www.jsonschema2pojo.org/

 

{
  "$schema": "http://json-schema.org/draft-04/schema#";,
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "storeitem": {
        "type": "string"
      },
      "description": {
        "type": "string"
      }
    },
    "required": [
      "id",
      "storeitem",
      "description"
    ]
  }
}
 

I checked my swagger.json file and it shows

  "storeitem":{

   "type":"object",

   "properties":

   {

   "id":{

   "type":"string"

   },

  "caption":{

   "type":"string"},

  "storeitem":{

  "type":"string"}

  }}

  

so its clear that swagger UI is seeing it as an object but i want that it to be 
an array type. The pojo class generated by  http://www.jsonschema2pojo.org/ is 
below, could it be that the parsing of array-type to jackson annotated pojo 
class is not correct?. In that case is there any better way i could present my 
model to the UI instead of converting from json schema to pojo and than 
pointing it.

 

-----------------------------------com.example.Example.java-----------------------------------

package com.example;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"id",
"storeitem",
"description"
})
public class Example {

/**
* 
* (Required)
* 
*/
@JsonProperty("id")
private String id;
/**
* 
* (Required)
* 
*/
@JsonProperty("storeitem")
private String storeitem;
/**
* 
* (Required)
* 
*/
@JsonProperty("description")
private String description;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, 
Object>();

/**
* 
* (Required)
* 
* @return
* The id
*/
@JsonProperty("id")
public String getId() {
return id;
}

/**
* 
* (Required)
* 
* @param id
* The id
*/
@JsonProperty("id")
public void setId(String id) {
this.id = id;
}

/**
* 
* (Required)
* 
* @return
* The storeitem
*/
@JsonProperty("storeitem")
public String getStoreitem() {
return storeitem;
}

/**
* 
* (Required)
* 
* @param storeitem
* The storeitem
*/
@JsonProperty("storeitem")
public void setStoreitem(String storeitem) {
this.storeitem = storeitem;
}

/**
* 
* (Required)
* 
* @return
* The description
*/
@JsonProperty("description")
public String getDescription() {
return description;
}

/**
* 
* (Required)
* 
* @param description
* The description
*/
@JsonProperty("description")
public void setDescription(String description) {
this.description = description;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}

 


On Tuesday, August 16, 2016 at 1:16:21 PM UTC-7, Ron wrote: 

Why would you expect to see an array of the model when you describe only the 
model?

 

 

 

From: <[email protected]> on behalf of sdav <[email protected]>
Reply-To: "[email protected]" <[email protected]>
Date: Tuesday, 16 August 2016 at 12:05
To: Swagger <[email protected]>
Subject: issue with the model schema

 

Hi  

 

I have up running project and decided to integrate swagger. 

 

I am using jersey 2 .

 

so, i got an api response that i converted in to jsonschema and generated a 
pojo class. using something like below i am able to show the model schema of 
the response 

 

 

@GET

@ApiOperation(value="Retrives all items" , response = /path/to/.class/in/the 
jar.class )                        

@Produces({MediaType.APPLICATION_JSON})

public getStoreitems(......)

Below is the schema of my response from api and along with the generated POJO 
that i am using to point in the @Apioperation(@ApiOperation(value="Retrives all 
items" , response = /path/to/.class/in/the jar.class )

{
  "$schema": "http://json-schema.org/draft-04/schema#";,
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "storeitem": {
      "type": "string"
    },
    "description": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "storeitem",
    "description"
  ]
}
 
pojo class

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"id",
"storeitem",
"description"
})
public class Example {

/**
* 
* (Required)
* 
*/
@JsonProperty("id")
private String id;
/**
* 
* (Required)
* 
*/
@JsonProperty("storeitem")
private String storeitem;
/**
* 
* (Required)
* 
*/
@JsonProperty("description")
private String description;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, 
Object>();

/**
* 
* (Required)
* 
* @return
* The id
*/
@JsonProperty("id")
public String getId() {
return id;
}

/**
* 
* (Required)
* 
* @param id
* The id
*/
@JsonProperty("id")
public void setId(String id) {
this.id = id;
}

/**
* 
* (Required)
* 
* @return
* The storeitem
*/
@JsonProperty("storeitem")
public String getStoreitem() {
return storeitem;
}

/**
* 
* (Required)
* 
* @param storeitem
* The storeitem
*/
@JsonProperty("storeitem")
public void setStoreitem(String storeitem) {
this.storeitem = storeitem;
}

/**
* 
* (Required)
* 
* @return
* The description
*/
@JsonProperty("description")
public String getDescription() {
return description;
}

/**
* 
* (Required)
* 
* @param description
* The description
*/
@JsonProperty("description")
public void setDescription(String description) {
this.description = description;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}

}
 
on the UI Model scheam, i am expecting something like this. 
[
{
  "id": "string",
  "storeitem": "string",
  "description": "string"
}
]
but what i get 
{
"id":

"string",

"storeitem":

"string",

"description":

"string"

}

 

Thanks

devin

-- 
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 [email protected].
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 [email protected].
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to