package com.livngds.gds.api.model;
@javax.xml.bind.annotation.XmlRootElement(name="cart")@javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.FIELD)@org.codehaus.jackson.map.annotate.JsonRootName("cart")@io.swagger.annotations.ApiModelpublic class Cart {
@javax.xml.bind.annotation.XmlElement private Long id;
@javax.xml.bind.annotation.XmlElementWarapper(name="cartItems", required=true) @javax.xml.bind.annotation.XmlElement(name="cartItem") private java.util.List<com.livngds.gds.api.model.CartItem> cartItems; //more fields, getters & setters }
package com.livngds.gds.api.model;
@javax.xml.bind.annotation.XmlRootElement(name="cartItem")@javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.FIELD)@org.codehaus.jackson.map.annotate.JsonRootName("cartItem")@io.swagger.annotations.ApiModelpublic class CartItem {
//this is the API model class we want Swagger to use
@javax.xml.bind.annotation.XmlElement private Long id; @javax.xml.bind.annotation.XmlElement private String productName; //just an exemplary field we want and need in the API model //more fields, getters & setters}
package com.livngds.gds.persistence.sales.master;
@javax.persistence.Entity//more JPA/Hibernate annotationspublic class Cart {
//This is our Hibernate entity class. It is never used as an API model type. Neither as parameter or return type in our resources, nor as a property anywhere else in our API model
private Long id; private List<com.livngds.gds.persistence.sales.master.CartItem> cartItems; }
package com.livngds.gds.persistence.sales.master;
@javax.persistence.Entity//more JPA/Hibernate annotationspublic class CartItem {
//This is our Hibernate entity class. It is never used as an API model type. Neither as parameter or return type in our resources, nor as a property anywhere else in our API model
private Long id; private String productName; private String secretNotIntendedForAPI;}
package com.livngds.gds.api.server.resource; //This is the package we let Swagger scan for resources
@javax.ws.rs.Path("/carts")@io.swagger.annotations.Api(value = "carts")public class CartsResource {
@javax.ws.rs.GET @javax.ws.rs.Produces({javax.ws.rs.core.MediaType.APPLICATION_JSON, javax.ws.rs.core.MediaType.APPLICATION_XML}) @javax.annotation.security.RolesAllowed(com.livngds.gds.persistence.master.enums.ApiUserRoleConstantString.READ) @javax.ws.rs.Path("{cartId:\\d+}") @io.swagger.annotations.ApiOperation(value = "Retrieves a specific cart.", response = com.livngds.gds.api.model.Cart.class) @io.swagger.annotations.ApiResponses(value = { @io.swagger.annotations.ApiResponse(code = 400, message = "Invalid id supplied.", response=com.livngds.gds.api.exceptions.WebApplicationExceptionBody.class), @io.swagger.annotations.ApiResponse(code = 401, message = "Missing API authorisation.", response=com.livngds.gds.api.exceptions.WebApplicationExceptionBody.class), @io.swagger.annotations.ApiResponse(code = 404, message = "Cart not found.", response=com.livngds.gds.api.exceptions.WebApplicationExceptionBody.class) }) public com.livngds.gds.api.model.Cart getCart(@io.swagger.annotations.ApiParam(value="Cart ID") @javax.ws.rs.PathParam("cartId") long cartId) { com.livngds.gds.api.model.Cart apiCartToReturn; //We retrieve a com.livngds.gds.persistence.sales.master.Cart from our database using the specified cartId and convert it to a com.livngds.gds.api.model.Cart using only the fields that are intended for the API //com.livngds.gds.persistence.sales.master.CartItem instances likewise are translated into com.livngds.gds.api.model.CartItem and so on return apiCartToReturn; }}
{ "swagger": "2.0", "info": { "version": "1.0", "title": "Development GDS API Documentation" }, "basePath": "/livngds-web/api", "tags": [{ "name": "carts" }], "schemes": ["https"], "paths": { "/carts/{cartId}": { "get": { "tags": ["carts"], "summary": "Retrieves a specific cart.", "description": "", "operationId": "getCart", "produces": ["application/json", "application/xml"], "parameters": [{ "name": "cartId", "in": "path", "description": "Cart ID", "required": true, "type": "integer", "pattern": "\\d+", "format": "int64" }], "responses": { "404": { "description": "Cart not found.", "schema": { "$ref": "#/definitions/WebApplicationExceptionBody" } }, "200": { "description": "successful operation", "schema": { "$ref": "#/definitions/Cart" } }, "401": { "description": "Missing API authorisation.", "schema": { "$ref": "#/definitions/WebApplicationExceptionBody" } }, "400": { "description": "Invalid id supplied.", "schema": { "$ref": "#/definitions/WebApplicationExceptionBody" } } } } } }, "definitions": { "CartItem": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "productName": { "type": "string" }, "secretNotIntendedForAPI": { "type": "string" } } }, "Cart": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "cartItems": { "type": "array", "xml": { "name": "cartItem", "wrapped": true }, "items": { "$ref": "#/definitions/CartItem" } } }, "xml": { "name": "cart" } }, "WebApplicationExceptionBody": { "type": "object", "properties": { "status": { "type": "integer", "format": "int32" }, "message": { "type": "string" } } } }}
@ApiModelProperty(dataType="com.livngds.gds.api.model.CartItem")
@ApiModelProperty(dataType="[com.livngds.gds.api.model.CartItem]")@ApiModelProperty(dataType="java.util.List[com.livngds.gds.api.model.CartItem]")@ApiModelProperty(dataType="java.util.List<com.livngds.gds.api.model.CartItem>")@ApiModelProperty(dataType="array[com.livngds.gds.api.model.CartItem]")
@XmlElementWrapper(name="cartItems", required=true) @XmlElement(name="cartItem", type=com.livngds.gds.api.model.CartItem.class) private List<CartItem> cartItems;
Resolver.prototype.resolveTo = function (root, property, resolutionTable, location) { var ref = property.$ref;
if (ref) { if(ref.indexOf('#') >= 0) { location = ref.split('#')[1]; } resolutionTable.push({ obj: property, resolveAs: 'ref', root: root, key: ref, location: location }); } else if (property.type === 'array') { var items = property.items; this.resolveTo(root, items, resolutionTable, location); }};
Resolver.prototype.resolveTo = function (root, property, resolutionTable, location) { var ref = property.$ref;
if (ref) { if(ref.indexOf('#') >= 0) { location = ref.split('#')[1]; } resolutionTable.push({ obj: property, resolveAs: 'ref', root: root, key: ref, location: location }); } else if (property.type === 'array') { var items = property.items; if (typeof items != 'undefined') { this.resolveTo(root, items, resolutionTable, location); } else { this.resolveTo(root, 'string', resolutionTable, location); } }};
--
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-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Also, for Throwable, feel free to open an issue about it on the project (would be great if you could include a sample class). We may want to ignore it by default.Hi Andreas,Just wanted to make sure - did you resolve all the non-conversion-related issues you had? I've replied the conversion in the other thread.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
ModelConverters.getInstance().addPackageToSkip("com.my.avro.model");
--
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-swaggers...@googlegroups.com.