scalacheck-schema

ScalaCheck generators for various Iglu-compatible Schema formats

License

License

Categories

Categories

Scala Languages
GroupId

GroupId

com.snowplowanalytics
ArtifactId

ArtifactId

scalacheck-schema_2.11
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

scalacheck-schema
ScalaCheck generators for various Iglu-compatible Schema formats
Project URL

Project URL

http://snowplowanalytics.com
Project Organization

Project Organization

com.snowplowanalytics
Source Code Management

Source Code Management

https://github.com/snowplow-incubator/scalacheck-schema

Download scalacheck-schema_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.snowplowanalytics/scalacheck-schema_2.11/ -->
<dependency>
    <groupId>com.snowplowanalytics</groupId>
    <artifactId>scalacheck-schema_2.11</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.snowplowanalytics/scalacheck-schema_2.11/
implementation 'com.snowplowanalytics:scalacheck-schema_2.11:0.1.0'
// https://jarcasting.com/artifacts/com.snowplowanalytics/scalacheck-schema_2.11/
implementation ("com.snowplowanalytics:scalacheck-schema_2.11:0.1.0")
'com.snowplowanalytics:scalacheck-schema_2.11:jar:0.1.0'
<dependency org="com.snowplowanalytics" name="scalacheck-schema_2.11" rev="0.1.0">
  <artifact name="scalacheck-schema_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.snowplowanalytics', module='scalacheck-schema_2.11', version='0.1.0')
)
libraryDependencies += "com.snowplowanalytics" % "scalacheck-schema_2.11" % "0.1.0"
[com.snowplowanalytics/scalacheck-schema_2.11 "0.1.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
com.snowplowanalytics : iglu-scala-client_2.11 jar 0.5.0
com.snowplowanalytics : schema-ddl_2.11 jar 0.6.0
org.scalacheck : scalacheck_2.11 jar 1.14.0
io.chrisdavenport : cats-scalacheck_2.11 jar 0.1.0

test (3)

Group / Artifact Type Version
commons-validator : commons-validator jar 1.6
org.specs2 : specs2-core_2.11 jar 4.3.2
org.specs2 : specs2-scalacheck_2.11 jar 4.3.2

Project Modules

There are no modules declared in this project.

ScalaCheck Schema

ScalaCheck generators for various Iglu-compatible schema formats.

Installation

The latest version of ScalaCheck Schema is 0.1.0, which is cross-built against Scala 2.11.x and 2.12.x.

If you're using SBT, add the following lines to your build file:

libraryDependencies += "com.snowplowanalytics" %% "scalacheck-schema" % "0.1.0"

Usage

import org.json4s.jackson.parseJson
import com.snowplowanalytics.iglu.schemaddl.jsonschema.Schema
import com.snowplowanalytics.iglu.schemaddl.jsonschema.json4s.Json4sToSchema._
import com.snowplowanalytics.iglu.schemaddl.scalacheck.JsonSchemaGen

val schemaJson = parseJson("""{"type": ["integer", "string"], "maxLength": 10}""")
val schemaObject: Schema = Schema.parse(schemaJson).getOrElse(throw new RuntimeException("Invalid JSON Schema"))
val jsonGen: Gen[JValue] = JsonSchemaGen.json(schemaObject)

Or you can fetch existing Schema from Iglu Registry:

import com.snowplowanalytics.iglu.client.Resolver
import com.snowplowanalytics.iglu.schemaddl.scalacheck.{ IgluSchemas, JsonSchemaGen }

val resolver: Option[Resolver] = ???    // Can be some custom resolver or none for Iglu Central

for {
  // Get schema from Iglu Central
  schemaJson <- IgluSchemas.lookup(None)("iglu:com.snowplowanalytics.snowplow/geolocation_context/jsonschema/1-1-0")
  // Parse as JSON Schema AST
  schemaObject <- IgluSchemas.parseSchema(schemaJson)
  // Create JSON generateor
  gen = schemaObject.map(JsonSchemaGen.json)
  // Generate JSON instance compatible with specified schema
  json = gen.sample
} yield json

Copyright and License

Snowplow scalacheck-schema is copyright 2018 Snowplow Analytics Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

com.snowplowanalytics

Snowplow Analytics: Incubator

Versions

Version
0.1.0
0.1.0-M4