Instantiation of recursive generic types slows down exponentially the deeper they are nested. Why?

Accessing a new type causes the runtime to recompile it from IL to native code (x86 etc). The runtime also optimizes the code, which will also produce different results for value types and reference types. And List<int> clearly will be optimized differently than List<List<int>>. Thus also EmptyStack<int> and NonEmptyStack<int, EmptyStack<int>> and so on will be … Read more

How to refer to enclosing type definition recursively in OpenAPI / Swagger?

Your definition is perfectly fine. It’s a known issue with rendering recursive schemas in Swagger Editor and Swagger UI: https://github.com/swagger-api/swagger-ui/issues/3325 To work around the “Example Value” showing null/”string”/undefined instead of a recursive element, you can add a custom example to your schema: definitions: TreeNode: type: object properties: name: type: string description: The name of the … Read more