ramldt2jsonschema icon indicating copy to clipboard operation
ramldt2jsonschema copied to clipboard

resolving references not working

Open vanp33 opened this issue 4 years ago • 4 comments

Hi, at our project we have a bunch of raml-files, which have references to other ramls. Something like this:

uses:
    market: market_raml_file
type:
    position:
        market:
            type: market.market

I tried the example code but it didn't work. I don't know if there is something need to be configured in order to work? js:

const r2j = require('ramldt2jsonschema')
const join = require('path').join
const fs = require('fs')

const filePath = join(__dirname, 'NC$AFP_TYPE_OBJ_POS.RAML')
const ramlData = fs.readFileSync(filePath).toString()

const basePath = './'

async function main () {
    let schema
    try {
        schema = await r2j.dt2js(ramlData, 'position', { basePath })
    } catch (err) {
        console.log(err)
        return
    }
    console.log(JSON.stringify(schema, null, 2))
}

main()

Best regards

vanp33 avatar Sep 17 '20 09:09 vanp33

Hi @vanp33.

How exactly didn't it work? Please describe what's the expected and actual output.

Thanks!

postatum avatar Sep 21 '20 07:09 postatum

Hi @postatum , the type, which is referenced by market_raml_file is not resolved. In the json file I got

"market": {
      "description": "A Market"
      // type is missing
} 

It is expected that the type of market is resolved with the schema defined in the market_raml_file

vanp33 avatar Sep 21 '20 07:09 vanp33

References do work with command line, but they do not work in the javascript library.

I have two small RAML files. account.raml:

mediaType: application/json
properties:
  id:
    type: integer
    description: Internal ID of an account

And linktest.raml:

mediaType: application/json

types:
  account: !include account.raml

/accounts:
  get:
    responses:
      200:
        body:                  
          application/json: 
            type: account  

when I run in command line

dt2js linktest.raml account

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/account",
  "definitions": {
    "account": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "type": "integer",
          "description": "Internal ID of an account"
        }
      }
    }
  }
}

This is correct.

However, when I use the following server file:


const r2j = require("ramldt2jsonschema");
const join = require("path").join;
const fs = require("fs");
const currentDir = __dirname;
const ramlData = fs.readFileSync(join(currentDir, 'linktest.raml')).toString()
const main = async function () {
	let schema;
			try {
				let schema = await r2j.dt2js(ramlData, "account");
				console.log(JSON.stringify(schema, null, 2));
					  } catch (e) {
			  console.log(e);
			  }	
		return;
    };
main();

And I launch from command line

node server.js

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/account",
  "definitions": {
    "account": true
  }
}

The JSON Schema output is broken.

planmillantti avatar Sep 29 '20 07:09 planmillantti

Any update on this?

StatusCode404 avatar Apr 28 '21 02:04 StatusCode404