cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Meneghino
Community Champion
Community Champion

Swagger file definiton for object/array response

I have a Swagger file for fetching exchange rates, and everything works fine except that I do not know what to do with the Response section.  The issue is with the "rates" piece: the number of items and the list of currencies is variable.

 

A sample response is something like this, which is an object or array I think (I am not a JSON expert):

{
  "base": "EUR",
  "date": "2016-01-12",
  "rates": {
    "RUB": 82.69,
    "SGD": 1.557,
    "USD": 1.0836
  }
}

 

The current response section I have actually returns both "base" and "date" but gives an empty table for "rates":

 

   "responses": {
          "200": {
            "description": "Successful response",
            "schema": {
              "title": "The response of the api.",
              "type": "object",
              "properties":{
                "base":{
                  "type": "string"
                },
                "date":{
                  "type": "string"
                },
                "rates":{
                  "type": "object"
                }
              }
             }
}

 

Any help would be really appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino
Community Champion
Community Champion

I have found the below solution (and I show the full swagger if anyone needs to fetch European Central Bank exchange rates).

The only problem is that I am limited to currencies I define in the swagger, and input/hints as to how to make this work with any list of currencies would be welcome.

 

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "Fixer"
  },
  "host": "api.fixer.io",
  "paths": {
    "/{FXdate}": {
      "get": {
        "description": "Fetches historical FX rates from fixer.io",
        "operationId": "Run",
        "parameters": [
          {
            "name": "FXdate",
            "in": "path",
            "required": true,
            "description": "FX date in yyyy-mm-dd format",
            "type": "string"
          },
          {
            "name": "base",
            "in": "query",
            "required": true,
            "description": "ISO symbol of base currency",
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "schema": {
              "title": "The response of the api.",
              "type": "object",
              "properties":{
                "base":{
                  "type": "string"
                },
                "date":{
                  "type": "string"
                },
                "rates":{
                  "type": "object",
                  "properties":{
                    "USD":{
                      "type": "number",
                      "format": "double"
                    },
                    "EUR":{
                      "type": "number",
                      "format": "double"
                    },
                    "GBP":{
                      "type": "number",
                      "format": "double"
                    },
                    "RUB":{
                      "type": "number",
                      "format": "double"
                    },
                    "CHF":{
                      "type": "number",
                      "format": "double"
                    },
                    "BRL":{
                      "type": "number",
                      "format": "double"
                    },
                    "CZK":{
                      "type": "number",
                      "format": "double"
                    },
                    "HKD":{
                      "type": "number",
                      "format": "double"
                    },
                    "SGD":{
                      "type": "number",
                      "format": "double"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

View solution in original post

6 REPLIES 6
Meneghino
Community Champion
Community Champion

I have found the below solution (and I show the full swagger if anyone needs to fetch European Central Bank exchange rates).

The only problem is that I am limited to currencies I define in the swagger, and input/hints as to how to make this work with any list of currencies would be welcome.

 

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "Fixer"
  },
  "host": "api.fixer.io",
  "paths": {
    "/{FXdate}": {
      "get": {
        "description": "Fetches historical FX rates from fixer.io",
        "operationId": "Run",
        "parameters": [
          {
            "name": "FXdate",
            "in": "path",
            "required": true,
            "description": "FX date in yyyy-mm-dd format",
            "type": "string"
          },
          {
            "name": "base",
            "in": "query",
            "required": true,
            "description": "ISO symbol of base currency",
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "schema": {
              "title": "The response of the api.",
              "type": "object",
              "properties":{
                "base":{
                  "type": "string"
                },
                "date":{
                  "type": "string"
                },
                "rates":{
                  "type": "object",
                  "properties":{
                    "USD":{
                      "type": "number",
                      "format": "double"
                    },
                    "EUR":{
                      "type": "number",
                      "format": "double"
                    },
                    "GBP":{
                      "type": "number",
                      "format": "double"
                    },
                    "RUB":{
                      "type": "number",
                      "format": "double"
                    },
                    "CHF":{
                      "type": "number",
                      "format": "double"
                    },
                    "BRL":{
                      "type": "number",
                      "format": "double"
                    },
                    "CZK":{
                      "type": "number",
                      "format": "double"
                    },
                    "HKD":{
                      "type": "number",
                      "format": "double"
                    },
                    "SGD":{
                      "type": "number",
                      "format": "double"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

View solution in original post

Hi this is cool!

So in this file I just need to put EU "paths": {
    "/{FXdate}": {

URL and it should return me the current live rates in powerapps right?

No, you need to create a custom api by uploading the swagger:

https://powerapps.microsoft.com/en-us/tutorials/register-custom-api/

 

Meneghino
Community Champion
Community Champion

You need to copy/paste the swagger in notepad or something, save as txt then change the extension to .json

Then you can upload as a custom connection file

does this mean I do not need to creat api?

 or shall I first create api, publish and then add swagger?

The steps are all described here:

https://powerapps.microsoft.com/en-us/tutorials/register-custom-api/#register-a-custom-api

 

Please be specific is what is not clear

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

Top Solution Authors
Top Kudoed Authors
Users online (88,439)