RAML to JSON Schema

RAML to JSON Schema converter

License

License

Categories

Categories

JSON Data
GroupId

GroupId

no.ssb.raml
ArtifactId

ArtifactId

raml-to-jsonschema
Last Version

Last Version

0.14
Release Date

Release Date

Type

Type

jar
Description

Description

RAML to JSON Schema
RAML to JSON Schema converter
Project URL

Project URL

https://github.com/statisticsnorway/
Source Code Management

Source Code Management

https://github.com/statisticsnorway/raml-to-jsonschema/tree/master

Download raml-to-jsonschema

How to add to project

<!-- https://jarcasting.com/artifacts/no.ssb.raml/raml-to-jsonschema/ -->
<dependency>
    <groupId>no.ssb.raml</groupId>
    <artifactId>raml-to-jsonschema</artifactId>
    <version>0.14</version>
</dependency>
// https://jarcasting.com/artifacts/no.ssb.raml/raml-to-jsonschema/
implementation 'no.ssb.raml:raml-to-jsonschema:0.14'
// https://jarcasting.com/artifacts/no.ssb.raml/raml-to-jsonschema/
implementation ("no.ssb.raml:raml-to-jsonschema:0.14")
'no.ssb.raml:raml-to-jsonschema:jar:0.14'
<dependency org="no.ssb.raml" name="raml-to-jsonschema" rev="0.14">
  <artifact name="raml-to-jsonschema" type="jar" />
</dependency>
@Grapes(
@Grab(group='no.ssb.raml', module='raml-to-jsonschema', version='0.14')
)
libraryDependencies += "no.ssb.raml" % "raml-to-jsonschema" % "0.14"
[no.ssb.raml/raml-to-jsonschema "0.14"]

Dependencies

test (1)

Group / Artifact Type Version
org.testng : testng jar 6.14.3

Project Modules

There are no modules declared in this project.

raml-to-jsonschema

RAML to JSON Schema converts RAML Schema files to JSONSchema.

Using docker

Usage:

Where the volume RAML_VOLUME must contain the raml files inside a schemas folder. The json files will be written inside the jsonschema folder inside the same volume.

docker run -v RAML_VOLUME:/raml-project statisticsnorway/raml-to-jsonschema:latest

Prerequisites

This library uses jackson-dataformat-yaml which uses SnakeYAML library for low-level YAML parsing.

Yaml has fix set of reserved keywords:

 y|Y|yes|Yes|YES|n|N|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF

It has different ways to express a string. F.e

 languageCode:
        type: string
        description: The language code. Use only ISO 639-1 codes.
        displayName: Språkkode (ISO 639-1)
        enum:  # TODO: Foreløpig en enum, men bør flyttes til KLASS?
          - nb
          - nn
          - en
          - no

Above raml will get converted to Json as because of reserved keyword "no"

"languageCode" : {
          "type" : "string",
          "description" : "The language code. Use only ISO 639-1 codes.",
          "displayName" : "Språkkode (ISO 639-1)",
          "enum" : [ "nb", "nn", "en", false ]
        }

Solution

Explicitly provide the type on the elements

 languageCode:
        type: string
        description: The language code. Use only ISO 639-1 codes.
        displayName: Språkkode (ISO 639-1)
        enum:  # TODO: Foreløpig en enum, men bør flyttes til KLASS?
          - nb
          - nn
          - en
          - !!str no

Results

"languageCode" : {
          "type" : "string",
          "description" : "The language code. Use only ISO 639-1 codes.",
          "displayName" : "Språkkode (ISO 639-1)",
          "enum" : [ "nb", "nn", "en", "no" ]
        }

For numbers as strings:

 valuation?:
        type: string
        enum:  #TODO: Hvilke kategorier har vi her????
          - "1"
          - "2"
          - "3"
          - "4"
          - "5"
        displayName: Verdivurdering
        description: Har noe med sensivitet og bruk å gjøre. kommer fra GDPR-teamet.

will result into

"valuation" : {
          "type" : "string",
          "enum" : [ 1, 2, 3, 4, 5 ],
          "displayName" : "Verdivurdering",
          "description" : "Har noe med sensivitet og bruk å gjøre. kommer fra GDPR-teamet."
        }

Solution

  valuation?:
         type: string
         enum:  #TODO: Hvilke kategorier har vi her????
           - !!str 1
           - !!str 2
           - !!str 3
           - !!str 4
           - !!str 5
         displayName: Verdivurdering
         description: Har noe med sensivitet og bruk å gjøre. kommer fra GDPR-teamet.

will result into

"valuation" : {
          "type" : "string",
          "enum" : [ "1", "2", "3", "4", "5" ],
          "displayName" : "Verdivurdering",
          "description" : "Har noe med sensivitet og bruk å gjøre. kommer fra GDPR-teamet."
        }

Available types: !!bool, !!str, !!timestamp, !!float, !!int

Refer http://yaml.org/type for more details

no.ssb.raml

Statistics Norway

Versions

Version
0.14
0.13
0.12
0.11
0.10