scttcper / koa2-swagger-ui

Swagger UI as Koa v2 middleware
MIT License
103 stars 32 forks source link

[bug] failed to parse Circular structures #215

Closed TechQuery closed 3 years ago

TechQuery commented 3 years ago

What happened?

Sample code

import { Type } from 'class-transformer';
import { ValidateNested } from 'class-validator';

export class Test {
    @Type(() => Test)
    @ValidateNested()
    sub: Test;
}

Error thrown

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'properties' -> object with constructor 'Object'
    --- property 'sub' closes the circle
    at JSON.stringify (<anonymous>)
    at Object.<anonymous> (node_modules/koa2-swagger-ui/dist/index.js:59:57)
    at Object.wrapper (node_modules/handlebars/dist/cjs/handlebars/internal/wrapHelper.js:15:19)      
    at Object.eval [as main] (eval at createFunctionContext (node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:262:23), <anonymous>:21:102)
    at main (node_modules/handlebars/dist/cjs/handlebars/runtime.js:208:32)
    at ret (node_modules/handlebars/dist/cjs/handlebars/runtime.js:212:12)
    at ret (node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:519:21)
    at koaSwaggerUi (node_modules/koa2-swagger-ui/dist/index.js:73:24)
    at dispatch (node_modules/koa-compose/index.js:42:32)
    at node_modules/koa-compose/index.js:34:12

What I want?

Render 2 levels for Nested structure based on JSON.stringify() replacer.

scttcper commented 3 years ago

pass formatted json to spec

TechQuery commented 3 years ago

@scttcper my JSON is generated by routing-controllers libraries: https://github.com/TechQuery/Koagger/blob/main/source/Swagger.ts