Hi, I raised the issue to swagger core team. Please find the issue Id below.
Issue Id: https://github.com/swagger-api/swagger-core/issues/1964 Thank you Best Regards, Madhawa On Fri, Oct 7, 2016 at 12:28 PM, Madhawa Perera <[email protected]> wrote: > Added [email protected] and remove engineering > > On Fri, Oct 7, 2016 at 12:18 PM, Praminda Jayawardana <[email protected]> > wrote: > >> Hi All, >> >> Madhawa is having following issue with his API Implementation. >> >> He has an API Model which contains another API Model (nested). In the >> swagger definition file generated for his web app implementation, annotated >> example values are available for outer API Model's properties. But >> annotated example values for nested API Model's properties are not >> available. >> >> After an offline discussion with Madhawa we came into a conclusion that >> this might be an issue in swagger-core. >> Madhawa will raise an issue to swagger core team on this. >> >> Thanks, >> Praminda >> >> On Fri, Oct 7, 2016 at 10:46 AM, Madhawa Perera <[email protected]> >> wrote: >> >>> Hi, >>> >>> I'm trying to add example values to property object's in swagger >>> annotations. >>> >>> There I'm trying to create the following json schema with some example >>> values, on Swagger UI. In here, please note that "count" is an integer (I >>> was able to set an example value to that successfully) and "activities" is >>> an object. Both these are attributes inside the class "ListActivity". >>> >>> { >>> *"count": 1,* >>> "*activities*": [{ >>> *"activityId": "string",* >>> "code": "string", >>> "createdTimeStamp": "string", >>> "activityStatus": [{ >>> "deviceIdentifier": { >>> "id": "string", >>> "type": "string" >>> }, >>> "responses": [{ >>> "response": "string", >>> "receivedTimeStamp": "string" >>> }], >>> "updatedTimestamp": "string" >>> }] >>> }] >>> } >>> >>> In the above schema, what I wanted to do is instead of keeping "string" >>> as the values, I need to add example values. Like >>> *"activityId":"ACTIVITY_1"* instead of "activityId":"string" For that >>> I'm using following swagger annotations. >>> >>> "ListActivity" class is annotated with "@ApiModel" as below. >>> >>> @ApiModel( >>> value = "List of activities", >>> description = "This contains a set of activities that >>> matches a given criteria as a collection") >>> *public class ActivityList* >>> >>> Inside the "ListActivity" class I'm defining the model properties using >>> "@ApiModelProperty" annotation as below. >>> >>> @ApiModelProperty( >>> value = "Number of total resources.", >>> *example = "1"*) >>> @JsonProperty("count") >>> private int *count*; >>> >>> @ApiModelProperty( >>> value = "Returns the list of activities that match the >>> offset and limit parameter values that were specified.") >>> @JsonProperty("activities") >>> private List<Activity> *activities*; >>> >>> Since "Activity" is an object, I'm again creates a model inside the >>> "Activity" class. I'm annotating it as below. >>> >>> @ApiModel( >>> value = "Activity", >>> description = "An activity instance carries a unique identifier >>> that can be used to identify a particular operation instance uniquely") >>> *public class Activity* >>> >>> Inside "Activity" class, I'm again defining the model properties as >>> below. >>> >>> @ApiModelProperty( >>> name = "*activityId*", >>> value = "Activity identifier", >>> required = true, >>> *example = "ACTIVITY_1*") >>> @JsonProperty("activityId") >>> private String *activityId*; >>> >>> @ApiModelProperty( >>> name = "code", >>> value = "Activity code", >>> required = true, >>> example = "DEVICE_RING") >>> @JsonProperty("code") >>> private String code; >>> >>> After that I'm generating the swagger.json file. In the generated file, >>> example values were set to only to the attribute "count" as I gien in the >>> annotations. That means the "count" attribute's value is set to "1" as I >>> annotated. But the all the example values that I set inside the "Activity" >>> class does not come to the generated swagger.json file. Instead it only >>> shows "type": "string". Therefore in the swagger UI, i'm getting a json >>> schema as shown above (Please refer the json shown at the beginning of this >>> email) with only "count" is set to "1" and other keys are set with their >>> data types. >>> >>> The json generated has the following format. >>> >>> "*List of activities*": { >>> "type": "object", >>> "properties": { >>> "*count*": { >>> "type": "integer", >>> "format": "int32", >>> "*example": 1*, *(example values are set here as given >>> in the annotations)* >>> "description": "Number of total resources." >>> }, >>> >>> "activities": { >>> "type": "array", >>> "description": "Returns the list of activities that match >>> the offset and limit parameter values that were specified.", >>> "items": { >>> "$ref": "#/definitions/Activity" >>> } >>> } >>> }, >>> "description": "This contains a set of activities that matches >>> a given criteria as a collection" >>> }, >>> >>> >>> "*Activity*": { >>> "type": "object", >>> "properties": { >>> "*activityId*": { >>> "type": "string" *(example values are not set here >>> though I gave it in the annotations)* >>> } >>> "activityStatus": { >>> "type": "array", >>> "items": { >>> "$ref": "#/definitions/ActivityStatus" >>> } >>> } >>> } >>> }, >>> >>> The example values I gave through the annotations are not set for the >>> property "*activityId*" inside the "Activity" class. >>> >>> Is there anyway that I can set these property (example) when I go inside >>> the beans. Appreciate your thoughts and suggestions on this. >>> >>> Thank you >>> Best Regards, >>> Madhawa >>> >>> -- >>> Madhawa Perera >>> *Software Engineer* >>> Mobile : +94 (0) 773655496 >>> <%2B94%20%280%29%20773%20451194> >>> [email protected] >>> >>> >>> >> >> >> -- >> *Praminda Jayawardana* >> Software Engineer >> WSO2 Inc.; http://wso2.com >> Mobile : +94 (0) 716 590918 >> > > > > -- > Madhawa Perera > *Software Engineer* > Mobile : +94 (0) 773655496 > <%2B94%20%280%29%20773%20451194> > [email protected] > > > -- Madhawa Perera *Software Engineer* Mobile : +94 (0) 773655496 <%2B94%20%280%29%20773%20451194> [email protected]
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
