Swagger Response with Two Types of Data

30 views
Skip to first unread message

Eric Cox

unread,
Mar 23, 2015, 3:06:59 PM3/23/15
to swagger-sw...@googlegroups.com
To all,

In swagger I'm trying to model a response that has two types of data.

I need to carry a single optional key value, just a number in the Response. And I need to carry an array of Transactions. I seem to have the array of transactions modeled in the response but am not sure how to carry the key field I need.

I have this in the response and validating in editor.swagger.io.

      responses:
        '200':
          description: Account Transactions Request was processed as expected
          schema:
            items:
              $ref: '#/definitions/Transaction'

definitions:
  Transaction:
    required:
      - date
      - amount
      - balance
      - transactionType
    properties:
      date:
        type: string
        example: 2015-03-01
      description:
        type: string
        example: Burger King Store#244
      amount:
        type: number
        format: double
        example: 0.00
      balance:
        type: number
        format: double
        example: 000.00
      transactionType:
        type: string
        example: CHK

As you can see nowhere do I have the key field defined as part of the response. How do I add that to the successful response?

Thanks much,
Eric

tony tam

unread,
Mar 23, 2015, 3:40:54 PM3/23/15
to swagger-sw...@googlegroups.com
You mean you have an input (query param) and want that value to be in your output?  I would simply model the parameter and have a field in your payload for it.

I think I'm misunderstanding the question, though.

Eric Cox

unread,
Mar 23, 2015, 4:33:24 PM3/23/15
to swagger-sw...@googlegroups.com
Yes, it is an input (query param) as it needs to be passed in when more records are to be returned.

I have that modeled as such:
  /customer/account/{accountId}/transactions:
    get:
      description: Returns all checking account transaction data from the system of record
      operationId: findCheckingAccountTransactionsByAccountId
      produces:
        - application/json
        - application/xml
        - text/xml
        - text/html
      parameters:
        - name: accountId
          in: path
          description: accountId to use in the operation
          required: true
          type: integer
          format: int32
        - name: accountTypeCode
          in: query
          description: indicates IM or ST
          required: true
          type: string
        - name: filter
          in: query
          description: filter criteria
          required: false
          type: string
        - name: nextKey
          in: query
          description: used to call the next 100 records 
          required: false
          type: integer
          format: int32

The key also needs to exist in the response as it will indicate if there are more records to be returned.

So in the response we might have something like this if I'm envisioning it correctly

{key, "12345678"}     <<<<This is the one I don't feel like I have modeled properly. The response array for transactions seems to be in place similar to as shown in the petstore sample.
"transactions": [
{date: 02282015, desc: "purchase store X",amount: 1.00,balance: 19.00,transactionType: "CHECKING"},
{date: 02282015, desc: "purchase store X",amount: 2.00,balance: 17.00,transactionType: "CHECKING"},
{date: 02282015, desc: "purchase store X",amount: 3.00,balance: 14.00,transactionType: "CHECKING"},
{date: 02282015, desc: "purchase store X",amount: 4.00,balance: 10.00,transactionType: "CHECKING"},
]

Ron Ratovsky

unread,
Mar 26, 2015, 3:42:20 PM3/26/15
to swagger-sw...@googlegroups.com
Eric,

I'm not sure we get the full idea what you want to achieve.

If you want a single reply to look like:

{key, "12345678"}
"transactions": [
{date: 02282015, desc: "purchase store X",amount: 1.00,balance: 19.00,transactionType: "CHECKING"},
{date: 02282015, desc: "purchase store X",amount: 2.00,balance: 17.00,transactionType: "CHECKING"},
{date: 02282015, desc: "purchase store X",amount: 3.00,balance: 14.00,transactionType: "CHECKING"},
{date: 02282015, desc: "purchase store X",amount: 4.00,balance: 10.00,transactionType: "CHECKING"},
]


That would be odd as that's not a valid JSON structure.

If you meant it to look like this:

{key, "12345678",
"transactions": [
{date: 02282015, desc: "purchase store X",amount: 1.00,balance: 19.00,transactionType: "CHECKING"},
{date: 02282015, desc: "purchase store X",amount: 2.00,balance: 17.00,transactionType: "CHECKING"},
{date: 02282015, desc: "purchase store X",amount: 3.00,balance: 14.00,transactionType: "CHECKING"},
{date: 02282015, desc: "purchase store X",amount: 4.00,balance: 10.00,transactionType: "CHECKING"},
]}

then you can easily model that.

Keep in mind your current response representation is lacking as you should have "type": "array" alongside with the "items" property.


--
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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------
Reply all
Reply to author
Forward
0 new messages