Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

The minimum and maximum fields of type disappears #105

Open
psixdev opened this issue Sep 27, 2018 · 1 comment
Open

The minimum and maximum fields of type disappears #105

psixdev opened this issue Sep 27, 2018 · 1 comment
Assignees

Comments

@psixdev
Copy link

psixdev commented Sep 27, 2018

I use raml-js-parser-2, it returns types as arrays (type: ['integer'] instead type: 'integer). So, I have the following types context:

const typesContext = {
	Int: {
		name: 'Int',
		type: ['integer'],
		minimum: 0,
		maximum: 0,
		default: 0
	},
	Arr: {
		name: 'Arr',
		type: ['array'],
		items: ['Int']
	}
};

After following code executing:

const expandedArr = tools.expandedForm(typesContext.Arr, typesContext)
console.log(JSON.stringify(expandedArr, null, 2));

const canonicalArr = tools.canonicalForm(expandedArr)
console.log(JSON.stringify(canonicalArr, null, 2));

I get the result:

{
  "name": "Arr",
  "type": [
    {
      "type": "array"
    }
  ],
  "items": {
    "type": [
      {
        "name": "Int",
        "type": [
          {
            "type": "integer"
          }
        ],
        "minimum": 0,
        "maximum": 0,
        "default": 0
      }
    ]
  }
}
{
  "type": "array",
  "items": {
    "type": "integer",
    "name": "Int",
    "default": 0
  },
  "name": "Arr"
}

Minimum and maximum simply disappeared.

If the types were not arrays, I would get a different result:

{
  "name": "Arr",
  "type": "array",
  "items": {
    "name": "Int",
    "type": "integer",
    "minimum": 0,
    "maximum": 0,
    "default": 0
  }
}
{
  "name": "Arr",
  "type": "array",
  "items": {
    "name": "Int",
    "type": "integer",
    "minimum": 0,
    "maximum": 0,
    "default": 0
  }
}

Is this a bug in the library or should I manually convert all types after parsing?

@psixdev
Copy link
Author

psixdev commented Sep 27, 2018

This looks exactly like an error in the library, here are examples of types and canonical forms:

Correct
typesContext

{
	Int1: {
		name: 'Int1',
		type: 'integer',
		minimum: 1
	},
	Int2: {
		name: 'Int2',
		type: 'integer',
		maximum: 2
	},
	Arr: {
		name: 'Arr',
		type: 'array',
		items: ['Int1', 'Int2']
	}
};

canonical

{
  "name": "Arr",
  "type": "array",
  "items": {
    "name": "Int1",
    "type": "integer",
    "maximum": 2,
    "minimum": 1
  }
}

Incorrect
typesContext

{
	Int1: {
		name: 'Int1',
		type: 'integer',
		minimum: 0
	},
	Int2: {
		name: 'Int2',
		type: 'integer',
		maximum: 0
	},
	Arr: {
		name: 'Arr',
		type: 'array',
		items: ['Int1', 'Int2']
	}
};

canonical

{
  "name": "Arr",
  "type": "array",
  "items": {
    "name": "Int1",
    "type": "integer"
  }
}

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