Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Swagger Failed to load API definition. #6173


User avatar
0
kythor created

Hi, I'm getting following error message when running the API on my local machine:

Failed to load API definition: Fetch error, Not Found undefined

in the logs.txt is see this line: Request starting HTTP/1.1 GET http://localhost:22742/swagger/undefined

any help would be appreciated


7 Answer(s)
  • User Avatar
    0
    kythor created

    its an error after upgrading to the new aspnetzero version.

    in Startup.cs I had:

    options.SwaggerEndpoint(_appConfiguration["App:SwaggerEndPoint"], "xxxx API V1");
                    options.IndexStream = () => Assembly.GetExecutingAssembly()
                        .GetManifestResourceStream("xxxx.xxxx.Web.wwwroot.swagger.ui.index.html");
                    options.InjectBaseUrl(_appConfiguration["App:ServerRootAddress"]);
    

    but it should be

    options.SwaggerEndpoint("/swagger/v1/swagger.json", "xxxx API V1");
                    options.IndexStream = () => Assembly.GetExecutingAssembly()
                        .GetManifestResourceStream("xxxx.xxxx.Web.wwwroot.swagger.ui.index.html");
    
  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, the configuration App:SwaggerEndPoint should be valid. swagger/v1/swagger.json has moved to appsettings.json

    https://github.com/aspnetzero/aspnet-zero-core/blob/b2edfef64f936080e720e78052c61716a7391357/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Host/appsettings.json#L16

  • User Avatar
    0
    geertveenstra created

    Should this setting not also be added to the MVC project then ? Since in that project it is also configured in startup.cs as

    // Enable middleware to serve generated Swagger as a JSON endpoint
    app.UseSwagger();
     // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
    app.UseSwaggerUI(options =>
    {
         options.SwaggerEndpoint(_appConfiguration["App:SwaggerEndPoint"], "Portal API V1");
         options.InjectBaseUrl(_appConfiguration["App:WebSiteRootAddress"]);
     }); //URL: /swagger
    
  • User Avatar
    0
    ryancyq created
    Support Team

    you're right. we should provide example for SwaggerEndPoint in appsettings.json.

    See https://github.com/aspnetzero/aspnet-zero-core/pull/2041

  • User Avatar
    0
    ydyazilim created

    hi, links are not available.

    can you share solution again.

  • User Avatar
    0
    ydyazilim created

    hi again,

    in appsettigns.json

      "App": {
        "SwaggerEndPoint": "/swagger/v1/swagger.json",
        }
    
    

    and i take "Conflicting schemaIds: Duplicate schemaIds detected for types A and B" error for this issue update statup.cs

                {
                    options.SwaggerDoc("v1", new Info { Title = "YD API", Version = "v1" });
                    options.CustomSchemaIds(i => i.FullName);
                    options.DocInclusionPredicate((docName, description) => true);
                    
                });
    
  • User Avatar
    0
    ryancyq created
    Support Team

    Hi @ydyazilim, please open a new issue for your problem.

    also, share your ANZ version and framework in the new issue.