Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

TypeError: Converting circular structure to JSON #6

Open
jenschude opened this issue Feb 12, 2018 · 3 comments
Open

TypeError: Converting circular structure to JSON #6

jenschude opened this issue Feb 12, 2018 · 3 comments

Comments

@jenschude
Copy link

I'm using raml-json-enhance-node at version 0.3.2

With the following expansion script:

const {RamlJsonGenerator} = require('raml-json-enhance-node');

process.stdout.write("\n# Converting RAML to enhanced JSON ...");

const enhancer = new RamlJsonGenerator('./test.raml', {
    output: './test.json',
    prettyPrint: true
});
enhancer.generate()
    .then(function(json) {
        process.stdout.write(" \x1b[32mdone\x1b[0m.\n");
    })
    .catch((cause) => {
        process.stdout.write(" \x1b[31mfailed\x1b[0m.\n");
        console.error(cause);
    });

and the used test.raml file

#%RAML 1.0
title: Example API
types:
    CategoryReference:
        type: object
        properties:
            id: string
            obj: Category
    Category:
        type: object
        properties:
            name:
                type: string
            parent?:
                type: CategoryReference
/{id}:
  post:
    responses:
      201:
        body:
          application/json:
            type: Category

I get following type error

TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at Promise (node_modules/raml-json-enhance-node/lib/json-generator.js:104:25)
    at new Promise (<anonymous>)
    at JsonGenerator.save (node_modules/raml-json-enhance-node/lib/json-generator.js:101:12)
    at parse.then.then (node_modules/raml-json-enhance-node/lib/json-generator.js:61:26)
    at <anonymous>
@jenschude
Copy link
Author

The issue is maybe related to:

raml-org/datatype-expansion#51

@jenschude
Copy link
Author

Also the following raml without an intermediate object is not working:

#%RAML 1.0
title: Example API
types:
    Category:
        type: object
        properties:
            name:
                type: string
            parent?:
                type: Category
/{id}:
  get:
    queryParameters:
      sort:
        enum: [username, name]
    responses:
      200:
        body:
          application/json:
            type: Category

@jarrodek
Copy link
Contributor

jarrodek commented Nov 8, 2018

Thank you for issue report. Very sorry for taking so long.
This will be fixed when this PR is merged: #7

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants