FastEndpoints: Swagger - Schema becoming "invalid" overnight

Quite lost on this one and I can’t find anything else similar in the git issues.

My api is working fine with swagger etc but after leaving it running overnight attempting to go back to the swagger page the next day it produces a swagger.json error caused by a NullReferenceException with the below call stack. Simply restarting the service it works correctly. Any advice is appreciated!

Exception:

System.NullReferenceException: Object reference not set to an instance of an object.
   at FastEndpoints.Swagger.ValidationSchemaProcessor.Process(SchemaProcessorContext context)
   at NJsonSchema.Generation.JsonSchemaGenerator.ApplySchemaProcessors(JsonSchema schema, ContextualType contextualType, JsonSchemaResolver schemaResolver)
   at NJsonSchema.Generation.JsonSchemaGenerator.Generate[TSchemaType](TSchemaType schema, ContextualType contextualType, JsonSchemaResolver schemaResolver)
   at NJsonSchema.Generation.JsonSchemaGenerator.Generate[TSchemaType](ContextualType contextualType, JsonSchemaResolver schemaResolver)
   at NJsonSchema.Generation.JsonSchemaGenerator.GenerateWithReferenceAndNullability[TSchemaType](ContextualType contextualType, Boolean isNullable, JsonSchemaResolver schemaResolver, Action`2 transformation)
   at NSwag.Generation.OpenApiSchemaGenerator.GenerateWithReferenceAndNullability[TSchemaType](ContextualType contextualType, Boolean isNullable, JsonSchemaResolver schemaResolver, Action`2 transformation)
   at NSwag.Generation.AspNetCore.Processors.OperationResponseProcessor.Process(OperationProcessorContext operationProcessorContext)
   at NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.RunOperationProcessors(OpenApiDocument document, ApiDescription apiDescription, Type controllerType, MethodInfo methodInfo, OpenApiOperationDescription operationDescription, List`1 allOperations, OpenApiDocumentGenerator swaggerGenerator, OpenApiSchemaResolver schemaResolver)
   at NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.AddOperationDescriptionsToDocument(OpenApiDocument document, Type controllerType, List`1 operations, OpenApiDocumentGenerator swaggerGenerator, OpenApiSchemaResolver schemaResolver)
   at NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.GenerateApiGroups(OpenApiDocument document, IGrouping`2[] apiGroups, OpenApiSchemaResolver schemaResolver)
   at NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.GenerateAsync(ApiDescriptionGroupCollection apiDescriptionGroups)
   at NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.GenerateDocumentAsync(HttpContext context)
   at NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.GetDocumentAsync(HttpContext context)
   at NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 27 (19 by maintainers)

Commits related to this issue

Most upvoted comments

Since I deployed with v4.5.0-beta1 it seems to be ok for me at least, this morning there are no issues and the swagger ui is working correctly.

Done! Will send through logs tomorrow.

@Conway6288 @OFark pls upgrade to 4.5.0-beta6 when you can. also check the logs to see if there’s any failures there and let us know.

I too failed to see it fall over after 4.5.0-beta1. Though I’ve been on annual leave this week, I’ll check in with the team on Monday.

@wjax yeah let’s look in to that…

It may be related, yes.

NSwag generates swagger.json at runtime and keep it in memory. Maybe it could help to generate swagger.json at build time and persist it to storage and serve it from there. What do you think @dj-nitehawk ?

If swagger.json is done at build time, it could also speed up start up time

Like explained here: https://khalidabuhakmeh.com/generate-aspnet-core-openapi-spec-at-build-time?utm_source=pocket_mylist

El jue, 4 ago 2022 a las 13:18, Juan Carlos Torres (< @.***>) escribió:

Hello, I have a similar problem. I have an api deployed in azure that uses Fast Endpoints and after some time passes without activity, it throws a 500 error “Failed to load api definition” in swagger. The service is restarted in azure and the problem is solved. Any idea what could happen? Thanks!

— Reply to this email directly, view it on GitHub https://github.com/FastEndpoints/Library/issues/173#issuecomment-1205119251, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACLVHRIZDWJHWWTZ224URTVXORI5ANCNFSM545TX6OQ . You are receiving this because you were mentioned.Message ID: @.***>

Our IIS was set to Terminate after 20 minutes, I’ve just set it to suspend instead. See what happens.

It happens in release with the server running overnight without load. As soon as you try and access the /swagger endpoint the next day you are shown a /swagger/v1/swagger.json error. Going to the page details the stack trace from my original post.

Over the weekend I have had it setup to restart the service at 2am, seems to have “fixed” the issue we were having as I was able to access swagger no problem this morning but I will disable that restart to get you some extra information. I have republished the api with the pdb files included.

Will send the stack through tomorrow morning.

I’ll set up a test to try to catch it