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

resolving references not working #124

Open
vanp33 opened this issue Sep 17, 2020 · 4 comments
Open

resolving references not working #124

vanp33 opened this issue Sep 17, 2020 · 4 comments

Comments

@vanp33
Copy link

vanp33 commented Sep 17, 2020

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

@postatum
Copy link
Contributor

Hi @vanp33.

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

Thanks!

@vanp33
Copy link
Author

vanp33 commented Sep 21, 2020

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

@planmillantti
Copy link

planmillantti commented Sep 29, 2020

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.

@StatusCode404
Copy link

Any update on this?

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

4 participants