swagger-api / swagger-api/swagger-ui

Browser hangs on httppost with (large) xml class definition.

Open
#6,676 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Clicking on the action in the Swagger ui makes that the browser hangs/ is stealth.
[HttpPost] [Consumes("application/xml")] public string OrderResponse([FromBody] OrderType order) {
The OrderType is a very large xml file based on the UBL 2.1 Order specification:

[XmlInclude(typeof(ApplicationResponseType))] [XmlRoot(Namespace = "urn:oasis:names:specification:ubl:schema:xsd:BaseDocument-2", IsNullable = false)] [XmlType("BaseDocument", Namespace = "urn:oasis:names:specification:ubl:schema:xsd:BaseDocument-2")] public class BaseDocument : IBaseDocument { public BaseDocument();

Q&A (please complete the following information)
  • OS: [e.g. macOS] windows
  • Browser: [e.g. chrome, safari] Edge, Chrome
  • Version: 5.6.3
  • Method of installation: visual studio nuget
  • Swagger-UI version: 5.6.3
  • Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0]

Swagger-UI configuration options:
`public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.AddControllers().AddXmlDataContractSerializerFormatters();
#region Api Versioning
// Add API Versioning to the Project

        //services.AddControllers(options =>
        //{
        //    options.Conventions.Add(new ApiExplorerGroupPerVersionConvention());
        //});

        services.AddApiVersioning(
            options =>
            {
                // Specify the default API Version as 1.0
                options.DefaultApiVersion = new ApiVersion(1, 0);
                // If the client hasn't specified the API version in the request, use the default API version number 
                options.AssumeDefaultVersionWhenUnspecified = true;
                // reporting api versions will return the headers "api-supported-versions" and "api-deprecated-versions"
                options.ReportApiVersions = true;
                //HTTP Header based versioning
                //config.ApiVersionReader = new HeaderApiVersionReader("x-api-version");
            });
        services.AddVersionedApiExplorer(
            options =>
            {
                // add the versioned api explorer, which also adds IApiVersionDescriptionProvider service
                // note: the specified format code will format the version as "'v'major[.minor][-status]"
                options.GroupNameFormat = "'v'VVV";

                // note: this option is only necessary when versioning by url segment. the SubstitutionFormat
                // can also be used to control the format of the API version in route templates
                options.SubstituteApiVersionInUrl = true;
            });
        services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
        services.AddSwaggerGen(
            options =>
            {
                // add a custom operation filter which sets default values
                options.OperationFilter<SwaggerDefaultValues>();

                // integrate xml comments
                //options.IncludeXmlComments(XmlCommentsFilePath);
            });
        #endregion
    }

    /// <summary>
    /// Configures the application using the provided builder, hosting environment, and API version description provider.
    /// </summary>
    /// <param name="app">The current application builder.</param>
    /// <param name="provider">The API version descriptor provider used to enumerate defined API versions.</param>
    public void Configure(IApplicationBuilder app, IApiVersionDescriptionProvider provider)
    {
        app.UseRouting();
        app.UseAuthorization();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });

        app.UseSwagger(options => options.RouteTemplate = "docs/{documentName}/docs.json");
        app.UseSwaggerUI(
            options =>
            {
                options.DefaultModelsExpandDepth(-1); // hide completely
                options.InjectStylesheet("/swagger-ui/custom.css");
                // build a swagger endpoint for each discovered API version
                foreach (var description in provider.ApiVersionDescriptions)
                {
                    options.RoutePrefix = "docs";
                    options.SwaggerEndpoint($"/docs/{description.GroupName}/docs.json", description.GroupName.ToUpperInvariant());
                }
            });

        app.UseStaticFiles();
    }
    static string XmlCommentsFilePath
    {
        get
        {
            var basePath = PlatformServices.Default.Application.ApplicationBasePath;
            var fileName = typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml";
            return Path.Combine(basePath, fileName);
        }
    }

`

Describe the bug you're encountering

browser hangs after clicking action.

Expected behavior

No hanging browser.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the hang in Swagger UI using the supplied ASP.NET Core endpoint and large UBL 2.1 OrderType schema, starting with the action triggered by clicking Execute. Compare the behavior with a smaller XML definition and establish a focused failing case; done means the browser remains responsive after submitting the request.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.