Skip to content

openapisettings.json not honored #2

@bradygaster

Description

@bradygaster

I created a new Functions project and added the NuGet package to it, then worked up some code and got it running. However, when I would try to load up the Swagger or Open API URLs or the Swagger UI page, I would get the following error message:

Hosting environment: Production
Content root path: /Users/bradygaster/source/WeatherService/WeatherService/bin/output
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.

Functions:

	RenderOpenApiDocument: [GET] http://localhost:7071/api/openapi/{version}.{extension}

	RenderSwaggerUI: [GET] http://localhost:7071/api/swagger/ui

	GetForecasts: [GET] http://localhost:7071/api/GetForecasts

	RenderSwaggerDocument: [GET] http://localhost:7071/api/swagger.{extension}

[10/6/2020 5:09:04 PM] Executing HTTP request: {
[10/6/2020 5:09:04 PM]   requestId: "a8c6a055-14a6-4d46-8465-13846e48b93a",
[10/6/2020 5:09:04 PM]   method: "GET",
[10/6/2020 5:09:04 PM]   userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 Edg/85.0.564.68",
[10/6/2020 5:09:04 PM]   uri: "/api/swagger/ui"
[10/6/2020 5:09:04 PM] }
[10/6/2020 5:09:04 PM] Executing 'RenderSwaggerUI' (Reason='This function was programmatically called via the host APIs.', Id=466cf7e3-62fc-4c78-a7f6-59bc00c9d21c)
[10/6/2020 5:09:04 PM] SwaggerUI page was requested.
[10/6/2020 5:09:04 PM] Executed 'RenderSwaggerUI' (Failed, Id=466cf7e3-62fc-4c78-a7f6-59bc00c9d21c, Duration=133ms)
[10/6/2020 5:09:04 PM] System.Private.CoreLib: Exception while executing function: RenderSwaggerUI. WeatherService: The type initializer for 'Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiHttpTrigger' threw an exception. Microsoft.Azure.WebJobs.Extensions.OpenApi.Core: Open API metadata not found.
[10/6/2020 5:09:05 PM] Executed HTTP request: {
[10/6/2020 5:09:05 PM]   requestId: "a8c6a055-14a6-4d46-8465-13846e48b93a",
[10/6/2020 5:09:05 PM]   identities: "(WebJobsAuthLevel:Admin)",
[10/6/2020 5:09:05 PM]   status: "500",
[10/6/2020 5:09:05 PM]   duration: "271"
[10/6/2020 5:09:05 PM] }

I deleted the openapisettings.json file and moved the Open API info JSON data from that file into the host.json file:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingExcludedTypes": "Request",
      "samplingSettings": {
        "isEnabled": true
      }
    }
  },
  "openApi": {
    "info": {
      "version": "1.0.0",
      "title": "Open API Sample on Azure Functions",
      "description": "An API that provides the Weather Forecast via HTTP",
      "termsOfService": "https://github.com/Azure/azure-functions-openapi-extension",
      "contact": {
        "name": "Customer Name",
        "email": "[email protected]",
        "url": "https://github.co/my-git-remote-url.git"
      },
      "license": {
        "name": "MIT",
        "url": "http://opensource.org/licenses/MIT"
      }
    }
  }
}

Once I did this, everything worked just fine - the Swagger UI page would load and the JSON/YAML URLs would also load just fine.

My personal feeling is we should have one option here, and not bifurcate the ways of offering customers the ability to customize. I would move for total deletion of the openapisettings.json file. Also not a fan of the syntax required in local.settings.json - my favorite is the host.json approach, but I truly don't think adding a new file, openapisettings.json, is a good idea - feels too bloated, like too many concepts being added.

I think the best course of action would be to support the Open API style of including the JSON as works in host.json in both that file and in local.settings.json.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions