Skip to content

Instantly share code, notes, and snippets.

@typingincolor
Last active December 18, 2015 21:38
Show Gist options
  • Save typingincolor/5848610 to your computer and use it in GitHub Desktop.
Save typingincolor/5848610 to your computer and use it in GitHub Desktop.
Bit of a odd one. I've used swagger-node-express to generate this api spec, but I've discovered an interesting problem. If you look at the Store model, you can see a storeImage attribute in the json of type Media. If you remove this, the array of Media objects in the ProductDetails model doesn't render properly in swagger-ui: the Media object is…
{
apiVersion: "0.1",
swaggerVersion: "1.1",
basePath: "http://desolate-caverns-4564.herokuapp.com",
resourcePath: "/store",
apis: [{
path: "/store/{storeName}",
description: "Store operations",
operations: [{
parameters: [{
name: "storeName",
description: "Store to be fetched",
dataType: "string",
required: true,
allowMultiple: false,
paramType: "path"
}],
httpMethod: "GET",
notes: "Returns store details based on a store name",
errorResponses: [{
code: 400,
description: "invalid storeName"
}, {
code: 404,
description: "Store not found"
}],
nickname: "getStore",
summary: "Find store by storeName",
responseClass: "Store"
}]
}, {
path: "/store/{storeName}/products",
description: "Store operations",
operations: [{
parameters: [{
name: "storeName",
description: "Store to search",
dataType: "string",
required: true,
allowMultiple: false,
paramType: "path"
}],
httpMethod: "GET",
notes: "Search for product",
errorResponses: [{
code: 404,
description: "products not found"
}],
nickname: "searchForProduct",
summary: "Product search",
responseClass: "ProductList"
}]
}, {
path: "/store/{storeName}/products/{id}",
description: "Store operations",
operations: [{
parameters: [{
name: "storeName",
description: "Store to search",
dataType: "string",
required: true,
allowMultiple: false,
paramType: "path"
}, {
name: "id",
description: "Product to be fetched",
dataType: "string",
required: true,
allowMultiple: false,
paramType: "path"
}],
httpMethod: "GET",
notes: "Returns a product based on it's ID",
errorResponses: [{
code: 404,
description: "product not found"
}],
nickname: "getProduct",
summary: "Find product by id",
responseClass: "Product"
}]
}],
models: {
Store: {
storeName: "Store",
properties: {
productsUri: {
type: "string"
},
genericUserUri: {
type: "string"
},
userUri: {
type: "string"
},
loginUri: {
type: "string"
},
storeImage: {
type: "Media"
}
}
},
ProductList: {
properties: {
productListItems: {
type: "List",
description: "list of matching products",
items: {
$ref: "ProductDetails"
}
}
}
},
Product: {
properties: {
productDetails: {
required: true,
type: "ProductDetails"
},
kiddicareSpecificProductDetails: {
type: "KiddicareSpecificProductDetails"
},
wineSpecificProductDetails: {
type: "WineSpecificProductDetails"
}
}
},
Media: {
properties: {
mediaType: {
required: true,
type: "string",
allowableValues: {
valueType: "LIST",
values: ["image", "video", "gallery"]
}
},
size: {
type: "string"
},
location: {
required: true,
type: "string"
}
}
},
ProductDetails: {
properties: {
catEntryId: {
type: "string"
},
partNumber: {
type: "string"
},
name: {
type: "string"
},
shortDescription: {
type: "string"
},
longDescription: {
type: "string"
},
media: {
type: "array",
description: "list of images",
items: {
$ref: "Media"
}
}
}
},
KiddicareSpecificProductDetails: {
properties: {
arrivalDate: {
type: "Date"
}
}
},
WineSpecificProductDetails: {
properties: {
tasteProfile: {
type: "int"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment