I've created an Azure API App and deployed it to Azure. At first, I had no problem getting the Swagger file from the portal (i.e. by clicking the "API Definition" button on the API App blade), but at some point it stopped working.
I've enabled the Swagger UI in App_Start\SwaggerConfig.cs
. When I debug locally, I can navigate to http://localhost:12345/Swagger to get to the Swagger UI and download the Swagger file, that all works fine. When I go to the portal, I get a 500 error trying to get to https://microsoft-apiappad6cxxxxxxxxxxxx426c23a66.azurewebsites.net:443/swagger/docs/v1.
I've tried deleting the API App and redeploying it... no luck. I've tried starting a new project and creating the same interface with it and deploying that to Azure... that one works every time (of course).
I'll include the Swagger file here, in case it matters, but what I don't understand is: why would Swashbuckle work locally, but not in Azure?
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "StorefrontApi"
},
"host": "localhost:52912",
"schemes": [
"http"
],
"paths": {
"/api/v1/storefront/applications": {
"get": {
"tags": [
"GET"
],
"operationId": "Storefront_Applications",
"consumes": [],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/api/v1/storefront/aurorastatus": {
"get": {
"tags": [
"GET"
],
"operationId": "Storefront_AuroraStatus",
"consumes": [],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "auroraSerialNumber",
"in": "query",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/api/v1/storefront/order": {
"post": {
"tags": [
"POST"
],
"operationId": "Storefront_Order",
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "requestBody",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/api/v1/storefront/register": {
"post": {
"tags": [
"POST"
],
"summary": "",
"operationId": "Storefront_Register",
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "requestBody",
"in": "body",
"description": "",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/api/v1/storefront/removeapplication": {
"post": {
"tags": [
"POST"
],
"summary": "",
"operationId": "Storefront_RemoveApplication",
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "requestBody",
"in": "body",
"description": "",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/api/v1/storefront/updateserialnumber": {
"post": {
"tags": [
"POST"
],
"operationId": "Storefront_UpdateSerialNumber",
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "requestBody",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
}
},
"definitions": {
"Object": {
"type": "object",
"properties": {}
}
}
}
This, of course, limits the ability to consume the API App in a Logic App, and also to right-click / Add Azure API App client to my projects. (Yes, I can get the Swagger file locally and then modify and use it in the project, but that's not the flow we're looking for).
Does anyone have any ideas about what causes API Apps to fail to produce valid Swagger (or to execute the Swashbuckle code properly)?
Try go to the new Azure portal (preview portal), browse to your API App and set the App Service Plan/Pricing Tier to Standard.
I am having problem too when I first deployed my API App in Azure with the default App Service Plan and it seems like there is no instance created for the API App when it's the Free plan.
My API App simply works after I change the plan to Standard. Hope this helps!
My API App with Swagger in Azure
Useful references:
Edit: The answer was found in a comment below. After I updated my Swashbuckle NuGet packages, the Swagger showed up properly in the Azure Portal.