raml-org/ramldt2jsonschema

JSON schema to RAML not converting arrays

Opened this issue · 5 comments

The below JSON schema produce the below RAML library which displays the records item not as an array:

#%RAML 1.0 Library
types:
  account.raml:
    type: object
    additionalProperties: true
    properties:
      totalSize:
        type: integer
        required: true
      done:
        type: boolean
        required: true
      records:
        (amf-tuple): true
        required: true 
 {
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "totalSize": {
      "type": "integer"
    },
    "done": {
      "type": "boolean"
    },
    "records": {
      "type": "array",
      "items": [
        {
          "type": "object",
          "properties": {
            "attributes": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                }
              },
              "required": [
                "type",
                "url"
              ]
            },
            "testCcodeAbanderamiento__c": {
              "type": "null"
            }
          },
          "required": [
            "attributes",
            "Name",
            "testCcodeAbanderamiento__c"
          ]
        },
        {
          "type": "object",
          "properties": {
            "attributes": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                }
              },
              "required": [
                "type",
                "url"
              ]
            },
            "Name": {
              "type": "string"
            },
            "testCcodeAbanderamiento__c": {
              "type": "null"
            }
          },
          "required": [
            "attributes",
            "testCcodeAbanderamiento__c"
          ]
        },
        {
          "type": "object",
          "properties": {
            "attributes": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                }
              },
              "required": [
                "type",
                "url"
              ]
            },
            "Name": {
              "type": "string"
            },
            "testCcodeAbanderamiento__c": {
              "type": "null"
            }
          },
          "required": [
            "attributes"
          ]
        }
      ]
    }
  },
  "required": [
    "totalSize",
    "done",
    "records"
  ]
}

@ettoregia: as @gutee pointed-out in this comment, it is not possible to enforce the type of an item at a specific position in RAML.

Is this what you really meant to define or did you mean to define items in combination with anyOf? The latter would be equivalent to the RAML union type.

Hi @jstoiko, all I was trying to achieve was, given the above json schema to get a RAML out. Are we saying that's not possible for the specific json schema in input?

Since RAML allows you to refer to JSON schemas from within types, you can do:

#%RAML 1.0 Library
types:
  Account:
    properties:
      totalSize: integer
      done: boolean
      records: !include schema.json#records

assuming you schema file above is named schema.json and obviously you can also put records in its own JSON schema file, say records.json, in which case you would end-up with:

#%RAML 1.0 Library
types:
  Account:
    properties:
      totalSize: integer
      done: boolean
      records: !include records.json

(I've intentionally simplified your RAML)

To address this, I think we should find an elegant way to have the output RAML either embed the part of any JSON Schema that cannot be translated to RAML or have it be included like in the examples above.

@postatum: can you add this to the "Limitations" of the README for now?

@postatum: can you add this to the "Limitations" of the README for now?

Added.