Swagger API which is having query string - swagger

I want to deploy an API which is having query string.This is the API
v1/products?q=circuit breaker&locale=en-GB&pageSize=8&pageNo=1&project=GLOBAL
Here is how i am implementing
"/v1/products?q={searchText}&locale={ctrCode}&pageSize={pageSize}&pageNo={pageNo}&project={project}&country={country}":{
"get":{
"tags":[
"Search Text"
],
"summary":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)",
"description":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)",
"operationId":"getProductName",
"produces":[
"application/json",
"application/xml"
],
"parameters":[
{
"name":"searchText",
"in":"path",
"description":"The Product that needs to be fetched",
"required":true,
"type":"string"
},
{
"name":"ctrCode",
"in":"path",
"description":"The Product locale needs to be fetched. Example=en-GB, fr-FR, etc.",
"required":true,
"type":"string"
},
{
"name":"pageSize",
"in":"path",
"description":"The Product PageSize that needs to be fetched. Example=10, 20 etc.",
"required":true,
"type":"number"
},
{
"name":"pageNo",
"in":"path",
"description":"The Product pageNo that needs to be fetched. Example=1,2 etc.",
"required":true,
"type":"number"
},
{
"name":"project",
"in":"path",
"description":"The Project that needs to be fetched. Example=Mypact, DSL etc.",
"required":true,
"type":"string"
},
{
"name":"country",
"in":"header",
"description":"The Country that needs to be fetched. Example=France, India etc.",
"required":false,
"type":"string"
}
],
"responses":{
"200":{
"description":"successful operation",
"schema":{
"$ref":"#/definitions/Products"
}
},
"400":{
"description":"Invalid Product_id supplied"
},
"404":{
"description":"Product not found"
}
}
}
}
The country is optional parameter in this. I want the URL should display country only when if user enter some value, else it should not be displayed in the URL.

You can't describe query parameters as part of the path in Swagger. You have to declare those explicitly as query parameters.
"/v1/products":{
"get":{
"tags":[
"Search Text"
],
"summary":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)",
"description":"Get Products by searching text, countrycode, page number, pagesize, project and country(optional)",
"operationId":"getProductName",
"produces":[
"application/json",
"application/xml"
],
"parameters":[
{
"name":"searchText",
"in":"query",
"description":"The Product that needs to be fetched",
"required":true,
"type":"string"
},
{
"name":"ctrCode",
"in":"query",
"description":"The Product locale needs to be fetched. Example=en-GB, fr-FR, etc.",
"required":true,
"type":"string"
},
{
"name":"pageSize",
"in":"query",
"description":"The Product PageSize that needs to be fetched. Example=10, 20 etc.",
"required":true,
"type":"number"
},
{
"name":"pageNo",
"in":"query",
"description":"The Product pageNo that needs to be fetched. Example=1,2 etc.",
"required":true,
"type":"number"
},
{
"name":"project",
"in":"query",
"description":"The Project that needs to be fetched. Example=Mypact, DSL etc.",
"required":true,
"type":"string"
},
{
"name":"country",
"in":"query",
"description":"The Country that needs to be fetched. Example=France, India etc.",
"required":false,
"type":"string"
}
],
"responses":{
"200":{
"description":"successful operation",
"schema":{
"$ref":"#/definitions/Products"
}
},
"400":{
"description":"Invalid Product_id supplied"
},
"404":{
"description":"Product not found"
}
}
}
}

Your IN parameter needs to be "query" not "path"
This should work:
"parameters": [
{
"name":"country",
"in":"query",
"description":"The Country that needs to be fetched. Example=France, India etc.",
"required":false,
"type":"string"
}
]

In editor.swagger.io you can do it like that:
no params in your routing
params' attribute 'in' has to be 'query'
/v1/products:
get:
tags:
- Search Text
summary: Get Products by searching text, countrycode, page number, pagesize, project and country(optional)
description: Get Products by searching text, countrycode, page number, pagesize, project and country(optional)
operationId: getProductName
parameters:
- name: searchText
in: query
description: The Product that needs to be fetched
required: true
schema:
type: string
- name: ctrCode
in: query
description: The Product locale needs to be fetched. Example=en-GB, fr-FR, etc.
required: true
schema:
type: string
- name: pageSize
in: query
description: The Product PageSize that needs to be fetched. Example=10, 20 etc.
required: true
schema:
type: number
- name: pageNo
in: query
description: The Product pageNo that needs to be fetched. Example=1,2 etc.
required: true
schema:
type: number
- name: project
in: query
description: The Project that needs to be fetched. Example=Mypact, DSL etc.
required: true
schema:
type: string

Related

How to query all eventMessages from a specific event on Microsoft Graph API

I'm trying to get all the eventMessages that belongs to a specific event. However I'm not being able to.
I'm querying the me/messages with the $expand=microsoft.graph.eventMessage/event and trying to filter on this relationship:
https://graph.microsoft.com/v1.0/me/messages?$expand=microsoft.graph.eventMessage/event&filter=event/id eq 'eventID'
However, I'm getting the following error
{
"error": {
"code": "RequestBroker--ParseUri",
"message": "Could not find a property named 'event' on type 'Microsoft.OutlookServices.Message'.",
"innerError": {
"request-id": "cb211061-802b-4657-a191-f06c449897d1",
"date": "2019-05-16T14:01:43"
}
}
}
But looking at their example of expanding the message with the event, there is an event property on the return of the API (see returned JSON below).
HTTP/1.1 200 OK
Content-type: application/json
{
"#odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('8fd6e83b-3cc0-4bf0-8b26-950f4d7110f6')/messages/$entity",
"#odata.type":"#microsoft.graph.eventMessage",
"#odata.etag":"W/\"CwAAABYAAABXlB/SL0N4Q6g6o+jSYAEuAAAImkVF\"",
"id":"AAMkADYAAAImV_jAAA=",
"createdDateTime":"2017-12-27T21:54:55Z",
"lastModifiedDateTime":"2017-12-27T23:26:38Z",
"changeKey":"CwAAABYAAABXlB/SL0N4Q6g6o+jSYAEuAAAImkVF",
"categories":[
],
"receivedDateTime":"2017-12-27T21:54:55Z",
"sentDateTime":"2017-12-27T21:54:54Z",
"hasAttachments":false,
"internetMessageId":"<MWHPR1301MB211042CF#MWHPR1301MB2110.namprd13.prod.outlook.com>",
"subject":"Kick off planning",
"bodyPreview":"Let's collect opinions from our teams and organize action items.",
"importance":"normal",
"parentFolderId":"AQMkADYAS4AAAIBDAAAAA==",
"conversationId":"AAQkADYRuffB3wDlPn-ReFZarI60=",
"isDeliveryReceiptRequested":null,
"isReadReceiptRequested":false,
"isRead":false,
"isDraft":false,
"webLink":"https://outlook.office365.com/owa/?ItemID=AAMkADYAAAImV%2BjAAA%3D&exvsurl=1&viewmodel=ReadMessageItem",
"inferenceClassification":"focused",
"meetingMessageType":"meetingRequest",
"body":{
"contentType":"html",
"content":"<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n<style type=\"text/css\" style=\"display:none\">\r\n<!--\r\np\r\n\t{margin-top:0;\r\n\tmargin-bottom:0}\r\n-->\r\n</style>\r\n</head>\r\n<body dir=\"ltr\">\r\n<div id=\"divtagdefaultwrapper\" dir=\"ltr\" style=\"font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif\">\r\n<p style=\"margin-top:0; margin-bottom:0\">Let's collect opinions from our teams and organize action items.<br>\r\n</p>\r\n</div>\r\n</body>\r\n</html>\r\n"
},
"sender":{
"emailAddress":{
"name":"Administrator",
"address":"admin#contoso.onmicrosoft.com"
}
},
"from":{
"emailAddress":{
"name":"Administrator",
"address":"admin#contoso.onmicrosoft.com"
}
},
"toRecipients":[
{
"emailAddress":{
"name":"Alex Wilber",
"address":"AlexW#contoso.onmicrosoft.com"
}
}
],
"ccRecipients":[
],
"bccRecipients":[
],
"replyTo":[
],
"event#odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('8fd6e83b-3cc0-4bf0-8b26-950f4d7110f6')/messages('AAMkADYAAAImV_jAAA%3D')/microsoft.graph.eventMessage/event/$entity",
"event":{
"#odata.etag":"W/\"V5Qf0i9DeEOoOqPo0mABLgAACJpBWg==\"",
"id":"AAMkADYAAAImVu6AAA=",
"createdDateTime":"2017-12-27T21:54:55.2624551Z",
"lastModifiedDateTime":"2017-12-27T22:19:16.6667889Z",
"changeKey":"V5Qf0i9DeEOoOqPo0mABLgAACJpBWg==",
"categories":[
],
"originalStartTimeZone":"Pacific Standard Time",
"originalEndTimeZone":"Pacific Standard Time",
"iCalUId":"040000008200E00074C5B7101A82E00800000000A2A6F3535D7FD3010000000000000000100000003D770E2E8974F44B9471BDB348097FE3",
"reminderMinutesBeforeStart":15,
"isReminderOn":true,
"hasAttachments":false,
"subject":"Kick off planning",
"bodyPreview":"Let's collect opinions from our teams and organize action items.",
"importance":"normal",
"sensitivity":"normal",
"isAllDay":false,
"isCancelled":false,
"isOrganizer":false,
"responseRequested":true,
"seriesMasterId":null,
"showAs":"tentative",
"type":"singleInstance",
"webLink":"https://outlook.office365.com/owa/?itemid=AAMkADYAAAImVu6AAA%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl":null,
"responseStatus":{
"response":"tentativelyAccepted",
"time":"2017-12-27T22:19:12.6197462Z"
},
"body":{
"contentType":"html",
"content":"<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n<style type=\"text/css\" style=\"display:none\">\r\n<!--\r\np\r\n\t{margin-top:0;\r\n\tmargin-bottom:0}\r\n-->\r\n</style>\r\n</head>\r\n<body dir=\"ltr\">\r\n<div id=\"divtagdefaultwrapper\" dir=\"ltr\" style=\"font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif\">\r\n<p style=\"margin-top:0; margin-bottom:0\">Let's collect opinions from our teams and organize action items.<br>\r\n</p>\r\n</div>\r\n</body>\r\n</html>\r\n"
},
"start":{
"dateTime":"2018-02-02T22:00:00.0000000",
"timeZone":"UTC"
},
"end":{
"dateTime":"2018-02-02T23:00:00.0000000",
"timeZone":"UTC"
},
"location":{
"displayName":"Mt. Hood"
},
"recurrence":null,
"attendees":[
{
"type":"required",
"status":{
"response":"none",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Administrator",
"address":"admin#contoso.onmicrosoft.com"
}
},
{
"type":"required",
"status":{
"response":"tentativelyAccepted",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Alex Wilber",
"address":"AlexW#contoso.onmicrosoft.com"
}
}
],
"organizer":{
"emailAddress":{
"name":"Administrator",
"address":"admin#contoso.onmicrosoft.com"
}
}
}
}
I would expect that the above filter would make the API return only the messages belonging to that event. However, it's giving me a 400 and I think it might be because of the syntax on how to filter in this specific case, but I can't find anything on their documentation about this. Does anybody know how to perform this kind of filter on the graph API?

Webix not showing the kids data on dynamic loading

I am using webix to show some tree table data.
webix.ready(function () {
grida = webix.ui({
container: "testB",
view: "treetable",
columns: [
{ id: "id", header: "", css: { "text-align": "right" } },
{
id: "SerialNo", header: "Serial No", width: 250,
template: "{common.treetable()} #SerialNo#"
}
],
url: "/Test/GetTreeItem",
autoheight: true,
});
});
This loads the items perfectly.
Parents;
[{"id":11583,"Id":11583,"SerialNo":"12476127654","webix_kids":1},{"id":11584,"Id":11584,"SerialNo":"125235463","webix_kids":1},{"id":11585,"Id":11585,"SerialNo":"21385423348956","webix_kids":1},{"id":11586,"Id":11586,"SerialNo":"253346346346","webix_kids":1},{"id":11587,"Id":11587,"SerialNo":"123123","webix_kids":1},{"id":11588,"Id":11588,"SerialNo":"52354263","webix_kids":1},{"id":11589,"Id":11589,"SerialNo":"12344444","webix_kids":1},{"id":11590,"Id":11590,"SerialNo":"12344444","webix_kids":1},{"id":11591,"Id":11591,"SerialNo":"12344444","webix_kids":1},{"id":11592,"Id":11592,"SerialNo":"151515","webix_kids":1}]
However when I click the plus button, server returns (I can see the json string when I debug the code) the json but webix not appending the data underneath the parent.
Kids of parent "id":11587;
[{"id":11583,"Id":11583,"SerialNo":"12476127654","webix_kids":1},{"id":11592,"Id":11592,"SerialNo":"151515","webix_kids":1}]
id of data object must be unique per component.
Currently, you have for top level
{
"id": 11583,
"Id": 11583,
"SerialNo": "12476127654",
"webix_kids": 1
},
and in kids data you have
{
"id": 11583,
"Id": 11583,
"SerialNo": "12476127654",
"webix_kids": 1
},
both items share the same id, so treetable doesn't add a new item.
Correcting the JSON output solved my problem.
For the parents;
{
"parent":"0",
"data":[
{
"Id":11584,
"id":11584,
"SerialNo":"125235463",
"webix_kids":1
},
{
"Id":11599,
"id":11599,
"SerialNo":"3444",
"webix_kids":1
}
]
}
For the kids;
{
"parent":11599,
"data":[
{
"id":11583,
"Id":11583,
"SerialNo":"12476127654",
"webix_kids":1
},
{
"id":11592,
"Id":11592,
"SerialNo":"151515",
"webix_kids":1
}
]
}

Invalid Reference Id : Line.SalesItemLineDetail.ItemRef

I have tried to create sales receipt in quickbook using quickbook api. My most of sales receipt has successfully created at quick book without any issue. But quickbook api throw exception for one order. I have got below error:
{
"Fault": {
"Error": [
{
"Message": "Invalid Reference Id",
"Detail": "Invalid Reference Id : Line.SalesItemLineDetail.ItemRef",
"code": "2500",
"element": "Line.SalesItemLineDetail.ItemRef"
}
],
"type": "ValidationFault"
},
"time": "2017-05-04T03:32:18.942-07:00"
}
Below are json that I have tried with API :
{
"SalesReceiptEx":null,
"AutoDocNumber":null,
"CustomerRef":{
"name":"Alexander",
"type":null,
"value":"325"
},
"CustomerMemo":null,
"BillAddr":{
"Id":"1",
"Line1":"Alexander Kryukov",
"Line2":"22 Chester Terrace",
"Line3":"London",
"Line4":"United Kingdom,GB",
"Line5":"NW1 4ND",
"City":null,
"Country":null,
"CountryCode":null,
"CountrySubDivisionCode":null,
"PostalCode":null,
"PostalCodeSuffix":null,
"Lat":null,
"Long":null,
"Tag":null,
"Note":null
},
"ShipAddr":{
"Id":"2",
"Line1":"Alexander Kryukov",
"Line2":"22 Chester Terrace",
"Line3":null,
"Line4":null,
"Line5":null,
"City":"London",
"Country":"United Kingdom",
"CountryCode":null,
"CountrySubDivisionCode":"GB",
"PostalCode":"NW1 4ND",
"PostalCodeSuffix":null,
"Lat":null,
"Long":null,
"Tag":null,
"Note":null
},
"RemitToRef":null,
"ClassRef":null,
"SalesTermRef":null,
"DueDate":null,
"SalesRepRef":null,
"PONumber":null,
"FOB":null,
"ShipMethodRef":null,
"ShipDate":null,
"TrackingNum":null,
"GlobalTaxCalculation":null,
"TotalAmt":"136.90000",
"HomeTotalAmt":null,
"ApplyTaxAfterDiscount":null,
"TemplateRef":null,
"PrintStatus":null,
"EmailStatus":null,
"BillEmail":{
"Id":null,
"Address":"sash_300#hotmail.com",
"Default":null,
"Tag":null
},
"ARAccountRef":null,
"Balance":null,
"HomeBalance":null,
"FinanceCharge":null,
"PaymentMethodRef":null,
"PaymentRefNum":null,
"PaymentType":null,
"CheckPayment":null,
"CreditCardPayment":null,
"DepositToAccountRef":{
"name":"Business Bank Account HSBC",
"type":null,
"value":58
},
"DeliveryInfo":null,
"DiscountRate":null,
"DiscountAmt":null,
"GovtTxnRefIdentifier":null,
"DocNumber":1163080716,
"TxnDate":"2017-05-04",
"DepartmentRef":null,
"CurrencyRef":null,
"ExchangeRate":null,
"PrivateNote":null,
"TxnStatus":null,
"LinkedTxn":null,
"Line":[
{
"Id":1,
"LineNum":1,
"Description":"Flowery Floater Birthday Number",
"Amount":"43.29167",
"LinkedTxn":null,
"DetailType":"SalesItemLineDetail",
"PaymentLineDetail":null,
"DiscountLineDetail":null,
"TaxLineDetail":null,
"SalesItemLineDetail":{
"ServiceDate":null,
"TaxInclusiveAmt":null,
"DiscountRate":null,
"DiscountAmt":null,
"SalesItemLineDetailEx":null,
"ItemRef":{
"name":"Flowery Floater Birthday Number",
"type":null,
"value":"1"
},
"ClassRef":null,
"UnitPrice":"43.29167",
"RatePercent":null,
"PriceLevelRef":null,
"MarkupInfo":null,
"Qty":"1",
"UOMRef":null,
"ItemAccountRef":null,
"InventorySiteRef":null,
"TaxCodeRef":{
"name":null,
"type":null,
"value":2
}
},
"DescriptionLineDetail":null,
"ItemBasedExpenseLineDetail":null,
"AccountBasedExpenseLineDetail":null,
"DepositLineDetail":null,
"PurchaseOrderItemLineDetail":null,
"ItemReceiptLineDetail":null,
"JournalEntryLineDetail":null,
"GroupLineDetail":null,
"SubTotalLineDetail":null,
"TDSLineDetail":null,
"CustomField":null,
"LineEx":null
},
{
"Id":2,
"LineNum":2,
"Description":"Custom Product",
"Amount":"37.50000",
"LinkedTxn":null,
"DetailType":"SalesItemLineDetail",
"PaymentLineDetail":null,
"DiscountLineDetail":null,
"TaxLineDetail":null,
"SalesItemLineDetail":{
"ServiceDate":null,
"TaxInclusiveAmt":null,
"DiscountRate":null,
"DiscountAmt":null,
"SalesItemLineDetailEx":null,
"ItemRef":{
"name":"Custom Product",
"type":null,
"value":"10"
},
"ClassRef":null,
"UnitPrice":"3.75000",
"RatePercent":null,
"PriceLevelRef":null,
"MarkupInfo":null,
"Qty":"10",
"UOMRef":null,
"ItemAccountRef":null,
"InventorySiteRef":null,
"TaxCodeRef":{
"name":null,
"type":null,
"value":2
}
},
"DescriptionLineDetail":null,
"ItemBasedExpenseLineDetail":null,
"AccountBasedExpenseLineDetail":null,
"DepositLineDetail":null,
"PurchaseOrderItemLineDetail":null,
"ItemReceiptLineDetail":null,
"JournalEntryLineDetail":null,
"GroupLineDetail":null,
"SubTotalLineDetail":null,
"TDSLineDetail":null,
"CustomField":null,
"LineEx":null
},
{
"Id":3,
"LineNum":3,
"Description":"Additional Delivery Charge",
"Amount":"30.00000",
"LinkedTxn":null,
"DetailType":"SalesItemLineDetail",
"PaymentLineDetail":null,
"DiscountLineDetail":null,
"TaxLineDetail":null,
"SalesItemLineDetail":{
"ServiceDate":null,
"TaxInclusiveAmt":null,
"DiscountRate":null,
"DiscountAmt":null,
"SalesItemLineDetailEx":null,
"ItemRef":{
"name":"Additional Delivery Charge",
"type":null,
"value":"1"
},
"ClassRef":null,
"UnitPrice":"30.00000",
"RatePercent":null,
"PriceLevelRef":null,
"MarkupInfo":null,
"Qty":"1",
"UOMRef":null,
"ItemAccountRef":null,
"InventorySiteRef":null,
"TaxCodeRef":{
"name":null,
"type":null,
"value":2
}
},
"DescriptionLineDetail":null,
"ItemBasedExpenseLineDetail":null,
"AccountBasedExpenseLineDetail":null,
"DepositLineDetail":null,
"PurchaseOrderItemLineDetail":null,
"ItemReceiptLineDetail":null,
"JournalEntryLineDetail":null,
"GroupLineDetail":null,
"SubTotalLineDetail":null,
"TDSLineDetail":null,
"CustomField":null,
"LineEx":null
},
{
"Id":4,
"LineNum":4,
"Description":"Shipping Cost",
"Amount":"3.29167",
"LinkedTxn":null,
"DetailType":"SalesItemLineDetail",
"PaymentLineDetail":null,
"DiscountLineDetail":null,
"TaxLineDetail":null,
"SalesItemLineDetail":{
"ServiceDate":null,
"TaxInclusiveAmt":null,
"DiscountRate":null,
"DiscountAmt":null,
"SalesItemLineDetailEx":null,
"ItemRef":{
"name":"Shipping Cost",
"type":null,
"value":"1"
},
"ClassRef":null,
"UnitPrice":"3.29167",
"RatePercent":null,
"PriceLevelRef":null,
"MarkupInfo":null,
"Qty":"1",
"UOMRef":null,
"ItemAccountRef":null,
"InventorySiteRef":null,
"TaxCodeRef":{
"name":null,
"type":null,
"value":2
}
},
"DescriptionLineDetail":null,
"ItemBasedExpenseLineDetail":null,
"AccountBasedExpenseLineDetail":null,
"DepositLineDetail":null,
"PurchaseOrderItemLineDetail":null,
"ItemReceiptLineDetail":null,
"JournalEntryLineDetail":null,
"GroupLineDetail":null,
"SubTotalLineDetail":null,
"TDSLineDetail":null,
"CustomField":null,
"LineEx":null
}
],
"TxnTaxDetail":null,
"TxnSource":null,
"TaxFormType":null,
"TaxFormNum":null,
"TransactionLocationType":null,
"Id":null,
"SyncToken":null,
"MetaData":null,
"CustomField":null,
"AttachableRef":null,
"domain":null,
"status":null,
"sparse":null
}
Could anyone suggest, what is actual problem with this request?
The error message indicates exactly what the problem is:
"Message": "Invalid Reference Id",
"Detail": "Invalid Reference Id : Line.SalesItemLineDetail.ItemRef",
"code": "2500",
"element": "Line.SalesItemLineDetail.ItemRef"
Based on your request, it looks like you're just inventing these values, rather than actually querying these from QuickBooks.
I'm assuming this because in one place your item is called one thing, and in another it's called something totally different:
"ItemRef":{
"name":"Shipping Cost",
"type":null,
"value":"1"
},
Even though the Id values are identical (1) in both cases:
"ItemRef":{
"name":"Additional Delivery Charge",
"type":null,
"value":"1"
},
You can't just invent these numbers. They are Id values that you have to query from Intuit.
https://developer.intuit.com/docs/api/accounting/item
Query them by doing:
SELECT * FROM Item
I got this error when trying to submit an invoice line item with an ID outside the range of available IDs in the QuickBooks Sandbox.
For example, my production app has ~50 categories and the Sandbox only has ~20, so trying to use ID 40 in the Sandbox caused this error.
To resolve the issue I simply reduced the ID number for testing.

Couchdb Reference Document

I'm new to CouchDB and struggling to implement a basic example. I have three documents Customer, Contact, Address and I want join them into a single document.
Account Document
{
"_id": "CST-1",
"_rev": "8-089da95f148b446bd3b33a3182de709f",
"name": "Customer",
"code": "CST-001",
"contact_Key": "CNT-001",
"address_Key": "ADD-001",
"type": "Customer"
}
Contact Document
{
"_id": "CNT-001",
"_rev": "8-079da95f148b446bd3b33a3182de709g",
"fullname": "Happy Swan",
"type": "Contact"
}
Address Document
{
"_id": "ADD-001",
"_rev": "8-179da95f148b446bd3b33a3182de709c",
"street1": "9 Glass View",
"street2": "Street 2",
"city": "USA",
"type": "Address"
}
Map/Query:
var map= function (doc) {
if (doc.type === 'Customer') {
emit(doc.id, { contact_Key: doc.contact_Key, address_Key: doc.address_Key })
}
};
db.query({ map: map }, { include_docs: true }, function (err, res) {
});
I want all 3 documents in a single document when I query account e.g.
Expected result
{
"_id": "CST-1",
"_rev": "8-089da95f148b446bd3b33a3182de709f",
"name": "Customer",
"code": "CST-001",
"contact_Key": "CNT-001",
"address_Key": "ADD-001",
"type": "Customer",
"Contact: {
"_id": "CNT-001",
"_rev": "8-079da95f148b446bd3b33a3182de709g",
"fullname": "Happy Swan",
"type": "Contact"
}",
"Address: {
"_id": "ADD-001",
"_rev": "8-179da95f148b446bd3b33a3182de709c",
"street1": "9 Glass View",
"street2": "Street 2",
"city": "USA",
"type": "Address"
}"
}
I don't see any better solution than querying the account document first and then querying the other two once you know their IDs. If you think about it, it makes sense because the only link between these documents is the IDs stored in the account document, so to get all three at the same time, internally the DB would have to do two queries: first the account document, then the other two. And by design CouchDB only does one query at a time.
If you had the account doc ID stored into the contact and address documents however, you could use a list function to merge them all into one.
First you would need a view:
function(doc) {
if (doc.type === 'Customer') {
emit(doc._id, doc);
}
if (doc.type === 'Contact' || doc.type === 'Address') {
emit(doc.account_id, doc);
}
}
Then a list function:
function(head, req) {
var row, account, contact, address;
while (row = getRow()) {
if (row.value.type === 'Customer') {
account = row.value;
} else if (row.value.type === 'Contact') {
contact = row.value;
} else if (row.value.type === 'Address') {
address = row.value;
}
}
account['Contact'] = contact;
account['Address'] = address;
provides("json", function() {
return { 'json': account };
});
}
And you would query it with:
GET /db/_design/foo/_list/the-list/the-view?key="CST-1"

Static API docs with source2swagger

source2swagger generates a swagger spec with all apis in one json file. Can swagger-ui actually use that? When I explore the generated json file with swagger-ui, it tries to read the api descriptions from their paths in the spec, instead of using the descriptions/operations right there in the single json file.
Swagger-UI will handle putting all the json in one file. I'm not sure yet if there can be multiple top-level resource listings though.
Here's a working example:
{"basePath":"http://localhost:3001/", "resourcePath":"/", "swaggerVersion":"1.1", "apiVersion":"1.0", "apis":[
{
"path":"/pay",
"format":"json",
"description":"Create a transaction with the given amount and token.",
"operations":[
{
"httpMethod":"GET",
"tags":["production"],
"nickname":"pay",
"deprecated":false,
"summary":"Create a transaction with the given amount and token.",
"parameters":[
{
"name":"token",
"description":"The token representing the pay card",
"dataType":"string",
"allowMultiple":false,
"required":true,
"paramType":"query"
},
{
"name":"amount",
"description":"The amount to pay",
"dataType":"string",
"allowMultiple":false,
"required":true,
"paramType":"query"
}
]
}
]
},
{
"path":"/customer",
"format":"json",
"description":"Create an HTML form for adding a customer.",
"operations":[
{
"httpMethod":"GET",
"tags":["production"],
"nickname":"createCustomerForm",
"deprecated":false,
"summary":"Create an HTML form for adding a customer.",
"parameters":[
{
"name":"customerId",
"description":"Your customer id",
"dataType":"string",
"allowMultiple":false,
"required":true,
"paramType":"query"
}
]
}
]
},
{
"path":"/customer/{customerId}",
"format":"json",
"description":"Delete the customer info for given id.",
"operations":[
{
"httpMethod":"DELETE",
"tags":["production"],
"nickname":"deleteCustomer",
"deprecated":false,
"summary":"Delete the customer info for given id.",
"parameters":[
{
"name":"customerId",
"description":"the customer id to delete",
"dataType":"string",
"allowMultiple":false,
"required":true,
"paramType":"path"
}
]
}
]
},
{
"path":"/card",
"format":"json",
"description":"Create an HTML form for adding a credit card.",
"operations":[
{
"httpMethod":"GET",
"tags":["production"],
"nickname":"createCardForm",
"deprecated":false,
"summary":"Create an HTML form for the given customer to add a credit card.",
"parameters":[
{
"name":"customerId",
"description":"Your customer id",
"dataType":"string",
"allowMultiple":false,
"required":true,
"paramType":"query"
}
]
}
]
},
{
"path":"/card/{token}",
"format":"json",
"description":"Delete a card record by token.",
"operations":[
{
"httpMethod":"DELETE",
"tags":["production"],
"nickname":"deleteCard",
"deprecated":false,
"summary":"Delete the card info for given token.",
"parameters":[
{
"name":"token",
"description":"the token to delete",
"dataType":"string",
"allowMultiple":false,
"required":true,
"paramType":"path"
}
]
}
]
}
]}

Resources