All Projects → amzn → ion-schema-kotlin

amzn / ion-schema-kotlin

Licence: Apache-2.0 license
A Kotlin reference implementation of the Ion Schema Specification.

Programming Languages

kotlin
9241 projects

Labels

Projects that are alternatives of or similar to ion-schema-kotlin

hodur-visualizer-schema
Hodur is a domain modeling approach and collection of libraries to Clojure. By using Hodur you can define your domain model as data, parse and validate it, and then either consume your model via an API or use one of the many plugins to help you achieve mechanical results faster and in a purely functional manner.
Stars: ✭ 16 (-30.43%)
Mutual labels:  schema
popoto-examples
Contains a list of Popoto.js examples
Stars: ✭ 121 (+426.09%)
Mutual labels:  schema
scheriff
Schema Sheriff: yet another Kubernetes manifests validation tool
Stars: ✭ 15 (-34.78%)
Mutual labels:  schema
arrest
Swagger REST framework for Node.js, with support for MongoDB and JSON-Schema
Stars: ✭ 17 (-26.09%)
Mutual labels:  schema
pykafarr
A high-performance Python Kafka client. Efficiently from Kafka to Pandas and back.
Stars: ✭ 32 (+39.13%)
Mutual labels:  schema
Workshop-GraphQL
A GraphQL Server made for the workshop
Stars: ✭ 22 (-4.35%)
Mutual labels:  schema
joyce
Joyce is a highly scalable event-driven Cloud Native Data Hub.
Stars: ✭ 37 (+60.87%)
Mutual labels:  schema
openapi-types.ts
Generated TypeScript definitions based on GitHub's OpenAPI spec
Stars: ✭ 30 (+30.43%)
Mutual labels:  schema
examples
Apache Pulsar examples and demos
Stars: ✭ 41 (+78.26%)
Mutual labels:  schema
srclient
Golang Client for Schema Registry
Stars: ✭ 188 (+717.39%)
Mutual labels:  schema
upscheme
Database migrations and schema updates made easy
Stars: ✭ 737 (+3104.35%)
Mutual labels:  schema
pulsar-io-kafka
Pulsar IO Kafka Connector
Stars: ✭ 24 (+4.35%)
Mutual labels:  schema
linkifier
Database reverse engineering
Stars: ✭ 32 (+39.13%)
Mutual labels:  schema
oerschema
A RDF vocabulary for OER content on the web.
Stars: ✭ 21 (-8.7%)
Mutual labels:  schema
performify
Service object which makes you better.
Stars: ✭ 14 (-39.13%)
Mutual labels:  schema
schemify
Automatically generate Schema.org JSON-LD markup for WordPress content.
Stars: ✭ 58 (+152.17%)
Mutual labels:  schema
classicpress-seo
Classic SEO is the first SEO plugin built specifically to work with ClassicPress. A fork of Rank Math, the plugin contains many essential SEO tools to help optimize your website.
Stars: ✭ 18 (-21.74%)
Mutual labels:  schema
graphql-rbac
GraphQL Role-based access control (RBAC) middleware
Stars: ✭ 36 (+56.52%)
Mutual labels:  schema
csv-schema
Parse a CSV file into PHP objects based on a schema.
Stars: ✭ 23 (+0%)
Mutual labels:  schema
openapi4j
OpenAPI 3 parser, JSON schema and request validator.
Stars: ✭ 92 (+300%)
Mutual labels:  schema

Ion Schema Kotlin

A reference implementation of the Ion Schema Specification, written in Kotlin.

Build Status Maven Central Javadoc codecov

Getting Started

The following kotlin and java code samples are a simple example of how to use this API. The Customer type is a struct that requires firstName and lastName fields as strings, while the middleName field is optional ( To keep things simple, the schema is loaded inline ).

Kotlin

import com.amazon.ion.system.IonSystemBuilder
import com.amazon.ionschema.IonSchemaSystemBuilder.Companion.standard
import com.amazon.ionschema.Type


object IonSchemaGettingStarted {
    private val ION = IonSystemBuilder.standard().build()
    @JvmStatic
    fun main(args: Array<String>) {
        val iss = standard()
                .build()

        val schema = iss.newSchema(
                """
            type::{
              name: Customer,
              type: struct,
              fields: {
                firstName: { type: string, occurs: required },
                middleName: string,
                lastName: { type: string, occurs: required },
              },
            }
        """
        )
        val type = schema.getType("Customer")
        checkValue(type, """ { firstName: "Susie", lastName: "Smith" } """)
        checkValue(type, """ { firstName: "Susie", middleName: "B", lastName: "Smith" } """)
        checkValue(type, """ { middleName: B, lastName: Washington } """)
    }

    private fun checkValue(type: Type?, str: String) {
        val value = ION.singleValue(str)
        val violations = type!!.validate(value)
        if (!violations.isValid()) {
            println(str)
            println(violations)
        }
    }
}

Java

import com.amazon.ion.IonSystem;
import com.amazon.ion.IonValue;
import com.amazon.ion.system.IonSystemBuilder;
import com.amazon.ionschema.AuthorityFilesystem;
import com.amazon.ionschema.IonSchemaSystem;
import com.amazon.ionschema.IonSchemaSystemBuilder;
import com.amazon.ionschema.Schema;
import com.amazon.ionschema.Type;
import com.amazon.ionschema.Violations;

public class IonSchemaGettingStarted {
    private static IonSystem ION = IonSystemBuilder.standard().build();

    public static void main(String[] args) {
        IonSchemaSystem iss = IonSchemaSystemBuilder.standard()
                .build();

        Schema schema = iss.newSchema(" type::{\n" +
                        "              name: Customer,\n" +
                        "              type: struct,\n" +
                        "              fields: {\n" +
                        "                firstName: { type: string, occurs: required },\n" +
                        "                middleName: string,\n" +
                        "                lastName: { type: string, occurs: required },\n" +
                        "              },\n" +
                        "            }\n")
                ;
        Type type = schema.getType("Customer");

        checkValue(type, "{ firstName: \"Susie\", lastName: \"Smith\" }");
        checkValue(type, "{ firstName: \"Susie\", middleName: \"B\", lastName: \"Smith\" }");
        checkValue(type, "{ middleName: B, lastName: Washington }");
    }

    private static void checkValue(Type type, String str) {
        IonValue value = ION.singleValue(str);
        Violations violations = type.validate(value);
        if (!violations.isValid()) {
            System.out.println(str);
            System.out.println(violations);
        }
    }
}

When run, the code above produces the following output:

{ middleName: B, lastName: Washington }
Validation failed:
- one or more fields don't match expectations
  - firstName
    - expected range::[1,1] occurrences, found 0
  - middleName: B
    - expected type string, found symbol
  - lastName: Washington
    - expected type string, found symbol

Development

This repository contains two git submodules: ion-schema-tests and ion-schema-schemas. Both are used by this library's unit tests.

The easiest way to clone the ion-schema-kotlin repository and initialize its submodules is to run the following command:

$ git clone --recursive https://github.com/amzn/ion-schema-kotlin.git ion-schema-kotlin

Alternatively, the submodule may be initialized independently from the clone by running the following commands:

$ git submodule init
$ git submodule update

ion-schema-kotlin may now be built with the following command:

$ gradle build

Pulling in Upstream Changes

To pull upstream changes into ion-schema-kotlin, start with a simple git pull. This will pull in any changes to ion-schema-kotlin itself (including any changes to its .gitmodules file), but not any changes to the submodules. To make sure the submodules are up-to-date, use the following command:

$ git submodule update --remote

For detailed walkthroughs of git submodule usage, see the Git Tools documentation.

Roadmap

The roadmap is organized as a series of milestones.

License

This library is licensed under the Apache 2.0 License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].