Skip to content
Permalink
Browse files

Implemented: Do not require an id on inline schema definitions #25

We're ready for release 0.5.0.
  • Loading branch information
rigolepe committed Feb 19, 2016
1 parent f011553 commit 1c282b087c411efd62e54d5295c0f0ceb5f3dd5e
@@ -8,8 +8,8 @@ notifications:
email:
recipients:
- peter.rigole@atomicbits.io
after_success:
- '[[ $TRAVIS_BRANCH == "develop" ]] && { sbt "+ publish" ; };'
#after_success:
#- '[[ $TRAVIS_BRANCH == "develop" ]] && { sbt "+ publish" ; };'

env:
global:
@@ -19,9 +19,11 @@

package io.atomicbits.scraml.generator.lookup

import java.util.UUID

import io.atomicbits.scraml.generator.model.Language
import io.atomicbits.scraml.jsonschemaparser.model._
import io.atomicbits.scraml.jsonschemaparser.{AbsoluteId, JsonSchemaParseException, RootId}
import io.atomicbits.scraml.jsonschemaparser.{ImplicitId, AbsoluteId, JsonSchemaParseException, RootId}

import scala.annotation.tailrec

@@ -40,22 +42,22 @@ object SchemaLookupParser {


/**
* Expand all relative ids to absolute ids and register them in the schema lookup and also expand all $ref pointers.
*
* @param schema
* @return
*/
* Expand all relative ids to absolute ids and register them in the schema lookup and also expand all $ref pointers.
*
* @param schema
* @return
*/
def expandRelativeToAbsoluteIds(schema: Schema): Schema = {

/**
* Expand the ids in a schema based on the nearest root id of the enclosing schemas.
*
* @param schema the schema whose ids need expanding
* @param root the nearest (original) root id that was found in the enclosing schemas
* @param expandingRoot the root that we're expanding (creating) based on the seed (the nearest original root id)
* @param path the fragment path we're on
* @return a copy of the original schema in which all ids are replaced by root ids
*/
* Expand the ids in a schema based on the nearest root id of the enclosing schemas.
*
* @param schema the schema whose ids need expanding
* @param root the nearest (original) root id that was found in the enclosing schemas
* @param expandingRoot the root that we're expanding (creating) based on the seed (the nearest original root id)
* @param path the fragment path we're on
* @return a copy of the original schema in which all ids are replaced by root ids
*/
def expandWithRootAndPath(schema: Schema, root: RootId, expandingRoot: RootId, path: List[String] = List.empty): Schema = {

val currentRoot =
@@ -78,7 +80,8 @@ object SchemaLookupParser {
objEl.copy(
fragments = objEl.fragments.map(expandFragment),
properties = objEl.properties.map(expandFragment),
selection = objEl.selection.map(select => select.map(schema => expandWithRootAndPath(schema, currentRoot, expandingRoot, path)))
selection = objEl.selection
.map(select => select.map(schema => expandWithRootAndPath(schema, currentRoot, expandingRoot, path)))
)
case frag: Fragment => frag.copy(fragments = frag.fragments.map(expandFragment))
case arr: ArrayEl =>
@@ -106,19 +109,24 @@ object SchemaLookupParser {

schema.id match {
case rootId: RootId => expandWithRootAndPath(schema, rootId, rootId)
case ImplicitId =>
// We assume we hit an inline schema without an id, so we may just invent a random unique one since it will never be referenced.
val uniqueName = UUID.randomUUID().toString
val rootId = RootId(s"http://atomicbits.io/schema/$uniqueName.json")
expandWithRootAndPath(schema.updated(rootId), rootId, rootId)
case _ => throw JsonSchemaParseException("We cannot expand the ids in a schema that has no absolute root id.")
}

}


/**
*
* @param lookup The schema lookup
* @param linkedSchema A tuple containing a field name and the schema the field refers to. Nothing is done with the
* field name, it is there to make folding easier on schema fragments and object properties.
* @return The schema lookup with added object references.
*/
*
* @param lookup The schema lookup
* @param linkedSchema A tuple containing a field name and the schema the field refers to. Nothing is done with the
* field name, it is there to make folding easier on schema fragments and object properties.
* @return The schema lookup with added object references.
*/
def updateLookupTableAndObjectMap(lookup: SchemaLookup, linkedSchema: (String, Schema)): SchemaLookup = {


@@ -176,9 +184,9 @@ object SchemaLookupParser {


/**
* For each unprocessed object, lookup the selection references and collect al selection objects recursively and
* fill in the parent-child relations.
*/
* For each unprocessed object, lookup the selection references and collect al selection objects recursively and
* fill in the parent-child relations.
*/
def updateObjectHierarchy(schemaLookup: SchemaLookup): SchemaLookup = {

@tailrec
@@ -213,9 +221,9 @@ object SchemaLookupParser {


/**
* Check if there is a type field present in each leaf-object that is an EnumEl with one element and fill in the
* typeDiscriminatorValue field in each of them.
*/
* Check if there is a type field present in each leaf-object that is an EnumEl with one element and fill in the
* typeDiscriminatorValue field in each of them.
*/
def updateTypeDiscriminatorFields(schemaLookup: SchemaLookup): SchemaLookup = {

schemaLookup.objectMap.foldLeft(schemaLookup) { (lookup, objPair) =>
@@ -96,7 +96,6 @@
application/vnd-v1.0+json:
schema: |
{
"id": "http://atomicbits.io/schema/anonymous3.json",
"$ref": "http://atomicbits.io/schema/paged-list.json#",
"genericTypes": {
"T": {
@@ -117,7 +116,6 @@
application/vnd-v1.0+json:
schema: |
{
"id": "http://atomicbits.io/schema/anonymous1.json",
"type": "array",
"items": {
"$ref": "user.json"
@@ -129,7 +127,6 @@
application/vnd-v1.0+json:
schema: |
{
"id": "http://atomicbits.io/schema/anonymous2.json",
"type": "array",
"items": {
"$ref": "user.json"
@@ -63,7 +63,7 @@ trait BuildSettings {
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
None // Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},

0 comments on commit 1c282b0

Please sign in to comment.
You can’t perform that action at this time.