RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.82k stars 1.3k forks source link

Could not render this component, see the console. O is undefined. #2111

Open ideafixxxer opened 5 years ago

ideafixxxer commented 5 years ago

I see the following error in OAS3

Name | Description id *integer(path) |   Could not render this component, see the console. Could not render this component, see the console.

The console:

TypeError: "O is undefined"
    value https://localhost/DonServices/api/swagger/swagger-ui-bundle.js:82
    render https://localhost/DonServices/api/swagger/swagger-ui-bundle.js:70
    _renderValidatedComponentWithoutOwnerOrContext https://localhost/DonServices/api/swagger/swagger-ui-bundle.js:70
    _renderValidatedComponent https://localhost/DonServices/api/swagger/swagger-ui-bundle.js:70
    performInitialMount https://localhost/DonServices/api/swagger/swagger-ui-bundle.js:70
    mountComponent https://localhost/DonServices/api/swagger/swagger-ui-bundle.js:70
    mountComponent https://localhost/DonServices/api/swagger/swagger-ui-bundle.js:13
    mountChildren https://localhost/DonServices/api/swagger/swagger-ui-bundle.js:70
    _createInitialChildren https://localhost/DonServices/api/swagger/swagger-ui-bundle.js:70
    mountComponent https://localhost/DonServices/api/swagger/swagger-ui-bundle.js:70
swagger-ui-bundle.js:70:61175

It works in Swagger2 though.

RicoSuter commented 5 years ago

Can you provide a sample spec/project?

ideafixxxer commented 5 years ago

It starts like this:

  "x-generator": "NSwag v12.1.0.0 (NJsonSchema v9.13.29.0 (Newtonsoft.Json v9.0.0.0))",
  "openapi": "3.0.0",
  "info": {
    "title": "My API",
    "description": "My API",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://localhost/DonServices/api"
    }
  ],
  "paths": {
    "/v2.0/alerts/{id}": {
      "get": {
        "tags": [
          "Alert"
        ],
        "operationId": "Alert_GetAlert",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "x-position": 1
          },
          {
            "type": "string",
            "name": "Auth-Provider",
            "in": "header",
            "default": "Custom1",
            "x-enumNames": [
              "Custom1",
              "Custom2"
            ]
          },
          {
            "type": "string",
            "name": "Authorization",
            "in": "header",
            "required": true,
            "description": "auth access token"
          }
        ],
jochenjonc commented 5 years ago

Having the same issue:

services.AddSwaggerDocument(document =>
{
    document.PostProcess = d =>
     {
         d.SchemaType = NJsonSchema.SchemaType.OpenApi3;
     };
};

Removing d.SchemaType = NJsonSchema.SchemaType.OpenApi3; fixes it for now, but it used to work.

RicoSuter commented 5 years ago

Can someone provide a C# ASP.NET Core sample controller where we can reproduce this?