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

JSON schema to RAML not converting arrays #111

Open
ettoregia opened this issue Oct 29, 2019 · 5 comments
Open

JSON schema to RAML not converting arrays #111

ettoregia opened this issue Oct 29, 2019 · 5 comments
Assignees

Comments

@ettoregia
Copy link

ettoregia commented Oct 29, 2019

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"
  ]
}
@jstoiko
Copy link
Contributor

jstoiko commented Nov 5, 2019

@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.

@ettoregia
Copy link
Author

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?

@jstoiko
Copy link
Contributor

jstoiko commented Nov 14, 2019

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)

@jstoiko
Copy link
Contributor

jstoiko commented Dec 6, 2019

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 added a commit that referenced this issue Dec 10, 2019
@postatum
Copy link
Contributor

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

Added.

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

3 participants