Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openapisettings.json not honored #2

Closed
bradygaster opened this issue Oct 6, 2020 · 3 comments · Fixed by #34
Closed

openapisettings.json not honored #2

bradygaster opened this issue Oct 6, 2020 · 3 comments · Fixed by #34
Assignees
Labels
documented enhancement New feature or request resolved Request has been resolved v0.3.0

Comments

@bradygaster
Copy link

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-from-visual-studio@microsoft.com",
        "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.

@spboyer
Copy link
Member

spboyer commented Oct 6, 2020

@justinyoo

@justinyoo
Copy link
Contributor

Agreed.

There are currently three options to host Open API metadata – local.settings.json and environment variables, openapisettings.json or host.json.

I also prefer using host.json, but for now, it's not in the schema definition. We should also work on that.

https://github.com/Azure/Azure-Functions/blob/main/schemas/host.json

@bradygaster
Copy link
Author

Who owns this schema? @jeffhollan or @fabiocav?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documented enhancement New feature or request resolved Request has been resolved v0.3.0
Projects
None yet
3 participants