GithubHelp home page GithubHelp logo

jjschema's Introduction

JJSchema

A Java JSON Schema and Hyper-Schema generator. Currently, it is based on v4 draft. Supports Java 8 Date and Time API.

Latest Release

<dependency>
  <groupId>com.github.reinert</groupId>
  <artifactId>jjschema</artifactId>
  <version>1.16</version>
</dependency>

Simple HOW TO

Suppose the following Class:

@Attributes(title="Product", description="A product from Acme's catalog")
static class Product {
	@Attributes(required=true, description="The unique identifier for a product")
	private long id;
	@Attributes(required=true, description="Name of the product")
	private String name;
	@Attributes(required=true, minimum=0, exclusiveMinimum=true)
	private BigDecimal price;
	@Attributes(minItems=1,uniqueItems=true)
	private List<String> tags;
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}	
	public void setName(String name) {
		this.name = name;
	}
	public BigDecimal getPrice() {
		return price;
	}
	public void setPrice(BigDecimal price) {
		this.price = price;
	}
	public List<String> getTags() {
		return tags;
	}
	public void setTags(List<String> tags) {
		this.tags = tags;
	}
}

Type the following code:

JsonSchemaFactory schemaFactory = new JsonSchemaV4Factory();
schemaFactory.setAutoPutDollarSchema(true);
JsonNode productSchema = schemaFactory.createSchema(Product.class);
System.out.println(productSchema);

The output:

{
  "type" : "object",
  "description" : "A product from Acme's catalog",
  "title" : "Product",
  "properties" : {
    "id" : {
      "type" : "integer",
      "description" : "The unique identifier for a product"
    },
    "name" : {
      "type" : "string",
      "description" : "Name of the product"
    },
    "price" : {
      "type" : "number",
      "minimum" : 0,
      "exclusiveMinimum" : true
    },
    "tags" : {
      "type" : "array",
      "items" : {
        "type" : "string"
      },
      "uniqueItems" : true,
      "minItems" : 1
    }
  },
  "required" : [ "id", "name", "price" ],
  "$schema" : "http://json-schema.org/draft-04/schema#"
}

Thanks to

IntelliJ

jjschema's People

Contributors

anubhawps avatar atkawa7 avatar chrisphe avatar dkulsh avatar dr0na avatar edual16 avatar eduecl avatar fge avatar heat avatar hgschmie avatar johnjohndoe avatar juliengrandjean avatar lordvlad avatar luciano-castro-ml avatar manukura avatar nabarunchakma avatar rdwallis avatar reinert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jjschema's Issues

Using this module in Gradle

Hi,

Can I use this module in the gradle project? What would be the dependency for it?

How would the gradle file look like?

Thanks.

Add support to versioned JSON schema validation

Hi. I would like to ask if there are plans in the future to add support for versioned schema? In our case, we use JJSchema for schema validation in our REST API. We want to maintain a single resource (model/class) that can potentially have different schema for different API versions rather than implement a new resource for every new API version.

Inherited Attributes not being output in Schema

Currently testing with 0.9 SNAPSHOT.

I have a model where Driver extends Customer.
When I generate the schema for the driver the attributes wihtin Customer are not being output in the schema.

Driver:
@Attributes(description="Age driver was licensed in the US", minimum=15, maximum=99)
private int ageLicensed;

Customer:
@Attributes(description="Customer Date of Birth", pattern="^(19|20)\d\d- /.- /.$")
private String dateOfBirth;

"ageLicensed" : {
"type" : "integer",
"description" : "Age driver was licensed in the US",
"maximum" : 99,
"minimum" : 15
},
"dateOfBirth" : {
"type" : "string"
},

processPropertyCollection fails with ClassCastException on nested generics

File: JsonSchemaGenerator.java
Method: processPropertyCollection
Line: 205

How to reproduce: have a remote transfer object with nested generics, like List<Optional> or the like and call generateSchema with it.
Expected result: a schema describing the input object.
Actual result: ClassCastException.
Reason: The method doesn't resolve the generic recursive, but only one level deep.

Schema generation fails with NullPointerException

Schema generation fails with NullPointerException when generating schema from java classes containing java.net.URL fields. Below is the code snippet to reproduce the issue.

JsonSchemaGenerator v4generator = SchemaGeneratorBuilder.draftV4Schema().build();
JsonNode schema = v4generator.generateSchema(java.net.URL.class);

Initial investigation reveals a missing null check in mergeWithParent() method of the JsonSchemaGenerator class. The superclass for Object.class is null and hence NullPointerException occurs in the subsequent if block. Adding a null check on superclass in the if condition solves the issue. Below is the corrected snippet.

if (superclass != null && superclass != Object.class)

Support of @JsonProperty

Hi,

JJSchema ignores the @JsonProperty annotation, which causes Jackson to create a JSON object which differs from the JSON schema definition.

Let's take a look at the following example class...

public class MyClass {
    @JsonProperty("my_attribute")
    private String myAttribute;

    public String getMyAttributes() { return myAttribute; }
    public MyClass setMyAttribute(String myAttribute) { this.myAttribute = myAttribute; return this; }
}

The code ...

new ObjectMapper().writeValueAsString(new MyClass().setMyAttribute("Hello World"));

... produces ...

{
    "my_attribute": "Hello World"
}

... but JJSchema produces ...

{
    "properties": {
        "myAttribute": { "type": "string" }
    }
}

Any ideas?


I found a dirty solution which is documented in the current test:

https://github.com/WhileTrueEndWhile/JJSchema/blob/master/src/test/java/com/github/reinert/jjschema/xproperties/XPropertiesTest.java

Using an X Property like properties = com.github.reinert.jjschema.xproperties.XPropertiesTest$RenameFactory:example -> another_name renames example to another_name...

Availability on Maven?

Hello!

I have my processor system fully in place, and am ready to write a processor with a JJSchema-decorated class as an argument which will end up validating data against that class.

I'd like to demo it on my site, but for this JJSchema needs to be available on Maven. Is it available at the moment?

Null types

The generator does not support null types yet and I don't know how to exactly do it. I'm a bit confused with this json-schema null type.

Circular references due to inheritance

Our project has a circular reference that does not appear to be handled.

In this fictional example, our model consists of an abstract BaseItem, a MusicItem, and a WarrantyItem. Both MusicItem and WarrantyItem extend from BaseItem. The abstract BaseItem contains a Set of WarrantyItems — and there in lies the problem: when attempting to generate a schema for the WarrantyItem the generator enters an infinite loop (as part of processing the WarrantyItem it processes the superclass BaseItem, which itself contains a Set of WarrantyItems, and
so on and so on). While the @JsonmanagedReference and @JSonBackReference seem to work well for properties of a class, our circular reference issue is the result of inheritance. If WarrantyItem does not extend from BaseItem a schema can be correctly generated but if WarrantyItem does extend BaseItem, as we need it to, JJSchema fails with a StackOverflow error.

Custom Attribute (**Implementation available**)

Hello,

through a targeted search for "POJO to JSON schema" I found JJSchema.
I would like to generate JSON schemas from Java classes, which are then used to create forms.
Unfortunately, non-standard metadata must be added for this.
With @Attributes I don't see any way around the given attribute names.

I imagined something like this:

// ...
    @Attributes(

        title = "Hello World",

        custom = new String[][] {
            // new String[] { "KEY", "VALUE" }
            new String[] { "widget", "select" }
            // ...
        }

    )
// ...

Whereby widget should better be called x-widget, but you can't always decide that yourself...
Specifically I would like to use it together with ngx-schema-form :-)

If the annotation is attached to an attribute of a class, the JSON scheme might look something like this:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "...":  {
            "type": "...",
            // ...
            // "KEY": "VALUE" <---- new String[] { "KEY", "VALUE" }
            "widget": "select" // <---- new String[] { "widget", "select" }
        }
        // ...
    }
    // ...
}

I don't expect a complete solution, but I just don't know if it is possible without a fork.

Thanks in advance!

Ignore properties from a schema does not work for List of primitives

The following property is included in the generated schema after ignoring using annotation.

        @SchemaIgnore
        private List<String> attachment;

It works only when the List contains an object where you could use Jackson annotations @JsonManagedReference on the container and @JsonBackReference on the object in combination with @SchemaIgnore.

I believe List of Strings would be a common requirement.

maxLength and minLength Incorrectly Generated

'maxLength' and 'minLength' in POJO always outputted as 0 and -1 in the schema.

Example model:

@Attributes(description="Customer first name", minLength=1, maxLength=15)
private String firstName;

And the corresponding schema:

"firstName" : {
"type" : "string",
"description" : "Customer first name",
"minLength" : 0,
"maxLength" : -1
},

Error converting Java interface to Json schema

I am getting the following error while converting java inteface to json schema

Exception in thread "main" java.lang.NullPointerException at java.lang.Class.isAssignableFrom(Native Method) at com.github.reinert.jjschema.JsonSchemaGenerator.checkAndProcessType(JsonSchemaGenerator.java:106) at com.github.reinert.jjschema.JsonSchemaGenerator.generateSchema(JsonSchemaGenerator.java:86) at com.github.reinert.jjschema.JsonSchemaGenerator.mergeWithParent(JsonSchemaGenerator.java:300) at com.github.reinert.jjschema.JsonSchemaGenerator.processCustomType(JsonSchemaGenerator.java:140) at com.github.reinert.jjschema.JsonSchemaGenerator.checkAndProcessType(JsonSchemaGenerator.java:120) at com.github.reinert.jjschema.JsonSchemaGenerator.generateSchema(JsonSchemaGenerator.java:86) at SchemaGeneratorTest.main(SchemaGeneratorTest.java:25)

My query is does jjschema library supports interface conversion or not?

Schema generation fails with NullPointerException

Schema generation fails with NullPointerException for java classes having java.net.URL fields. It fails when handling URL.class. Below is the code snippet to reproduce the issue.

JsonSchemaGenerator v4generator = SchemaGeneratorBuilder.draftV4Schema().build();
JsonNode schema = v4generator.generateSchema(java.net.URL.class);

Initial investigation shows that it caused due to a missing null check in mergeWithParent() method of JsonSchemaGenerator class. The mergeWithParent() receives Object.class as the class type and the superclass of the Object.class happens to be null and thereby throwing the NullPointerException in the If block. Adding a null check on the superclass in the If condition resolves the issue. Below is the corrected condition for your reference.

if (superclass != null && superclass != Object.class) {

java.lang.StringIndexOutOfBoundsException: String index out of range: 0

java.lang.StringIndexOutOfBoundsException: String index out of range: 0

at java.lang.String.charAt(String.java:658)
at com.github.reinert.jjschema.v1.PropertyWrapper.firstToLowerCase(PropertyWrapper.java:374)
at com.github.reinert.jjschema.v1.PropertyWrapper.processPropertyName(PropertyWrapper.java:369)
at com.github.reinert.jjschema.v1.PropertyWrapper.getName(PropertyWrapper.java:147)
at com.github.reinert.jjschema.v1.PropertyWrapper.<init>(PropertyWrapper.java:82)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:151)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:76)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:67)
at com.github.reinert.jjschema.v1.PropertyWrapper.<init>(PropertyWrapper.java:126)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:151)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:76)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:52)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:71)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:47)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:39)
at com.github.reinert.jjschema.v1.JsonSchemaV4Factory.createSchema(JsonSchemaV4Factory.java:36)
at com.robocoin.bank.services.util.PokitDokTest.testMedicalProcedureCode(PokitDokTest.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Provide a way to specify attributes for a containing element in the List

    public class Mail {
        @Attributes(required = true, title="From Addresses", minLength = 5, maxLength = 100, minItems = 1)
        private List<String> from;

        @Attributes(required = true, title="To Addresses", minLength = 5, maxLength = 100, minItems = 1)
        private List<String> to;

        public List<String> getFrom() {
            return from;
        }

        public void setFrom(List<String> from) {
            this.from = from;
        }

        public List<String> getTo() {
            return to;
        }

        public void setTo(List<String> to) {
            this.to = to;
        }

    }

produces this schema.

{
  "type" : "object",
  "properties" : {
    "from" : {
      "type" : "array",
      "items" : {
        "type" : "string"
      },
      "title" : "From Addresses",
      "minItems" : 1,
      "minLength" : 5,
      "maxLength" : 100
    },
    "to" : {
      "type" : "array",
      "items" : {
        "type" : "string"
      },
      "title" : "To Addresses",
      "minItems" : 1,
      "minLength" : 5,
      "maxLength" : 100
    }
  },
  "required" : [ "from", "to" ],
  "$schema" : "http://json-schema.org/draft-04/schema#"
}

It would be nice if I could control the Attributes on the Collection items probably using another annotation, so it produces this schema instead.

{
    "type" : "object",
    "properties" : {
        "from" : {
            "type" : "array",
            "items" : {
                "type" : "string",
                "minLength" : 5,
                "maxLength" : 100
            },
            "title" : "From Addresses",
            "minItems" : 1
        },
        "to" : {
            "type" : "array",
            "items" : {
                "type" : "string",
                "minLength" : 5,
                "maxLength" : 100
            },
            "title" : "To Addresses",
            "minItems" : 1
        }
    },
    "required" : [ "from", "to" ],
    "$schema" : "http://json-schema.org/draft-04/schema#"
}

Instant expected as String in 1.2

Hi!
I'm checking the new 1.2. I have an object with an Instant param and when I try to validate the result is expected["string"]:
This is the param I create the schema from
@Attributes(required = true, description = "expected time for activation")
private Instant activation;

This is the result I get:
com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: instance type (object) does not match any allowed
primitive type (allowed: ["string"])
level: "fatal"
schema: {"loadingURI":"#","pointer":"/properties/activation"}
instance: {"pointer":"/activation"}
domain: "validation"
keyword: "type"
found: "object"
expected: ["string"]

The release says this type is specifically supported, so I guess I am doing something wrong. Could you upgrade the example in readme.txt to include a Instant parameter and see what I'm doing wrong?

Thanks!!

Support to Bean Validation (JSR 303)

What do you think about supporting the Bean Validation spec?
It could be interesting offer support to the default annotations provided by the specification and customized annotations derived from it.

I saw that all the attributes provided by the BV spec can be mapped to json-schema attributes.

On the other hand, the opposite is not true. So it would still be necessary to have an own annotation like the SchemaProperty I've made.

So, there are 3 options:

  1. Maintain just one supported annotation like the SchemaProperty.
  2. Support both annotations, but they couldn't have similar attributes.
  3. Support both annotations, including similar attributes, and handle the intersections cases somehow.

What do you suggest?

NullPointerException on generateSchema

Here's the code:

JsonSchemaGenerator v4generator = SchemaGeneratorBuilder.draftV4Schema().build();
schema = v4generator.generateSchema(DataPack.class);

DataPack class is following:

@Attributes(title="DataPack", description="Datapack for a particular feed for metadata ingestion")
public @Data class DataPack {

@Attributes(description = "Id of the DataPack")
@Id @GeneratedValue(strategy= GenerationType.AUTO) long id;

@Attributes(description = "Version of DataPack")
String version;

@Attributes(required = true, description = "Database Name")
String database;

String metaInfoSource;
String metaInfoUrl;
@Attributes(required=true, minItems = 1, description = "List of grid aliases e.g, tiberium-tan, dilithium-red or all")
List<String> grids;

@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.EAGER)
@Attributes(required=true, minItems = 1, description = "Table metadata definitions array")
List<Table> tables;
}

And I am getting the following exception:

java.lang.NullPointerException: null
at java.lang.Class.isAssignableFrom(Native Method) ~[na:1.8.0_40]
at com.github.reinert.jjschema.JsonSchemaGenerator.checkAndProcessType(JsonSchemaGenerator.java:106) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.generateSchema(JsonSchemaGenerator.java:86) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.mergeWithParent(JsonSchemaGenerator.java:300) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.processCustomType(JsonSchemaGenerator.java:140) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.checkAndProcessType(JsonSchemaGenerator.java:120) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.generateSchema(JsonSchemaGenerator.java:86) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.generatePropertySchema(JsonSchemaGenerator.java:215) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.processProperties(JsonSchemaGenerator.java:258) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.processCustomType(JsonSchemaGenerator.java:137) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.checkAndProcessType(JsonSchemaGenerator.java:120) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.generateSchema(JsonSchemaGenerator.java:86) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.generatePropertySchema(JsonSchemaGenerator.java:215) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.processProperties(JsonSchemaGenerator.java:258) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.processCustomType(JsonSchemaGenerator.java:137) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.checkAndProcessType(JsonSchemaGenerator.java:120) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.generateSchema(JsonSchemaGenerator.java:86) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.processPropertyCollection(JsonSchemaGenerator.java:206) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.generatePropertySchema(JsonSchemaGenerator.java:213) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.processProperties(JsonSchemaGenerator.java:258) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.processCustomType(JsonSchemaGenerator.java:137) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.checkAndProcessType(JsonSchemaGenerator.java:120) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.generateSchema(JsonSchemaGenerator.java:86) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.processPropertyCollection(JsonSchemaGenerator.java:206) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.generatePropertySchema(JsonSchemaGenerator.java:213) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.processProperties(JsonSchemaGenerator.java:258) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.processCustomType(JsonSchemaGenerator.java:137) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.checkAndProcessType(JsonSchemaGenerator.java:120) ~[jjschema-0.6.jar:na]
at com.github.reinert.jjschema.JsonSchemaGenerator.generateSchema(JsonSchemaGenerator.java:86) ~[jjschema-0.6.jar:na]

Best design pattern to fit our needs

Folks,

I have just made a whole refactoring on the project.
I've decided to use the Strategy Pattern( http://www.oodesign.com/strategy-pattern.html ) for organizing the generating algorithms and Abstract Factory to create an instance of JsonSchema. I still need to update the HyperSchema.

It happens that I was wondering that maybe we could use yet another pattern for decoupling more the model - Visitor. Instead of the JsonSchema be an Interface defined with all possibilities, we could define it as a Map and use Visitors for adding properties to it.

Suppose the following:

class JsonSchema implements Map<String, Object> {
    private Map<String, Object> map;
...
    public accept(SchemaVisitor visitor) {
        visitor.visit(this);
    }
...
}
class TypeVisitor implements SchemaVisitor {
    private Class clazz;
...
    public visit(JsonSchema schema) {
        schema.put("type",  getTypeFromClass(clazz));
    }
...
}

Or it could be an org.codehaus.jackson.ObjectNode.
I think this way we will have a much more flexible design as new properties arises.

Schema properties to support

According to the JSON-Schema meta-schema at http://json-schema.org/schema

"id": {
"type": "string", [OK!]
"format": "uri" [IT WOULD BE NICE TO RESTRICT JUST URIs]
},
"$schema": {
"type": "string", [OK!]
"format": "uri" [IT WOULD BE NICE TO RESTRICT JUST URIs]
},
"title": {
"type": "string" [OK!]
},
"description": {
"type": "string" [OK!]
},
"default": {}, [OK!]
"multipleOf": {
"type": "number", [OK!]
"minimum": 0, [OK!]
"exclusiveMinimum": true [?]
},
"maximum": {
"type": "number" [OK!]
},
"exclusiveMaximum": {
"type": "boolean", [OK!]
"default": false [OK!]
},
"minimum": {
"type": "number" [OK!]
},
"exclusiveMinimum": {
"type": "boolean", [OK!]
"default": false [OK!]
},
"maxLength": { "$ref": "#/definitions/positiveInteger" }, [OK!]
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" }, [OK!]
"pattern": {
"type": "string", [OK!]
"format": "regex" [IT WOULD BE NICE TO RESTRICT JUST REGEXs]
},
"additionalItems": { [NO SUPPORT YET]
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"items": { [OK!]
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
},
"maxItems": { "$ref": "#/definitions/positiveInteger" }, [OK!]
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" }, [OK!]
"uniqueItems": {
"type": "boolean", [OK!]
"default": false [OK!]
},
"maxProperties": { "$ref": "#/definitions/positiveInteger" }, [NO SUPPORT YET]
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" }, [NO SUPPORT YET]
"required": { "$ref": "#/definitions/stringArray" }, [OK!]
"additionalProperties": { [NO SUPPORT YET]
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"definitions": { [NO SUPPORT YET]
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"properties": { [OK!]
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"patternProperties": { [NO SUPPORT YET]
"type": "object",
"additionalProperties": { "$ref": "#" },
"default": {}
},
"dependencies": { [NO SUPPORT YET]
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/stringArray" }
]
}
},
"enum": { [OK!]
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": { [OK!]
"anyOf": [
{ "$ref": "#/definitions/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/definitions/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"allOf": { "$ref": "#/definitions/schemaArray" }, [NO SUPPORT YET]
"anyOf": { "$ref": "#/definitions/schemaArray" }, [NO SUPPORT YET]
"oneOf": { "$ref": "#/definitions/schemaArray" }, [NO SUPPORT YET]
"not": { "$ref": "#" } [NO SUPPORT YET]

StringIndexOutOfBoundsException on SomeObject#get()

Methods named get() cause a StringIndexOutOfBoundsException. I noticed this when I was trying to build a schema containing an Optional. e.g.

import com.fasterxml.jackson.databind.JsonNode;
import com.github.reinert.jjschema.v1.JsonSchemaFactory;
import com.github.reinert.jjschema.v1.JsonSchemaV4Factory;

public class SchemaGenerator {

    public static class BadClass {
        public double get() {
            return 9d;
        }
    }

    public static void main(String[] args) {
        JsonSchemaFactory schemaFactory = new JsonSchemaV4Factory();
        schemaFactory.setAutoPutDollarSchema(true);
        JsonNode schema = schemaFactory.createSchema(BadClass.class);

        System.err.println(schema);
    }
}

The exception is

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
	at java.lang.String.charAt(String.java:658)
	at com.github.reinert.jjschema.v1.PropertyWrapper.firstToLowerCase(PropertyWrapper.java:352)
	at com.github.reinert.jjschema.v1.PropertyWrapper.processPropertyName(PropertyWrapper.java:347)
	at com.github.reinert.jjschema.v1.PropertyWrapper.getName(PropertyWrapper.java:170)
	at com.github.reinert.jjschema.v1.PropertyWrapper.<init>(PropertyWrapper.java:103)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:155)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:88)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:64)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:72)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:48)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:40)
	at com.github.reinert.jjschema.v1.JsonSchemaV4Factory.createSchema(JsonSchemaV4Factory.java:36)
	at SchemaGenerator.main(SchemaGenerator.java:16)

If the problem can't be fixed, I expect execution to terminate with an exception explaining that get() is a bad method name, or the getter to be silently ignored (possibly with a log message?).

Using $ref

Given the following

class A {
    Opaque ref;
}

class Opaque {
    int val;
}

I'd like to get something like:

{
    "type": "object",
    "properties": {
        "ref" {
            "$ref": "some reference"
        }
    }
}

as a schema for class A by using an annotation on class A's ref property. the following doesn't work

class A {
    @Attributes($ref = "some reference")
    Opaque ref;
}

as it still includes the schema for class Opaque. Is there some way to get what I want?

HyperSchema updates

It's necessary to update the HyperSchema generation to produce the new representation of schemas, JsonNode (from Jackson).

Support for java.util.Map

A domain class that has a Map fails - apparently because the Map type is not supported (whilst Collection is). Is there a way to achieve Map element processing for schema generation ?

import java.util.Map;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class Preferences {
	private Map<String, String> preferences = new HashMap<String, String>();
}```

Stack:
```Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
	at java.lang.String.charAt(String.java:658)
	at com.github.reinert.jjschema.v1.PropertyWrapper.firstToLowerCase(PropertyWrapper.java:374)
	at com.github.reinert.jjschema.v1.PropertyWrapper.processPropertyName(PropertyWrapper.java:369)
	at com.github.reinert.jjschema.v1.PropertyWrapper.getName(PropertyWrapper.java:147)
	at com.github.reinert.jjschema.v1.PropertyWrapper.<init>(PropertyWrapper.java:82)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:151)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:76)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:67)
	at com.github.reinert.jjschema.v1.PropertyWrapper.<init>(PropertyWrapper.java:126)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:151)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:76)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:67)
	at com.github.reinert.jjschema.v1.PropertyWrapper.<init>(PropertyWrapper.java:126)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:151)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:76)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:67)
	at com.github.reinert.jjschema.v1.PropertyWrapper.<init>(PropertyWrapper.java:126)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:151)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:76)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:52)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:71)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:47)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:39)
	at com.github.reinert.jjschema.v1.JsonSchemaV4Factory.createSchema(JsonSchemaV4Factory.java:36)

Restrict depth of properties

Hi, it is a question, not an issue.
Is it possible to restrict how deep Json Schema should be generated?
For example, there is a class User, which has a custom class as it's property called Organisation. Now Organisation has further more CustomClasses as it's properties.
Can we restrict the generated Schema to list only properties of User, and not list Properties of Organisation in Json schema of User?
Just list Organisation as type:object+some other details, but not go in the iteration of properties of all nth great grand children. Hope question is clear. :)

Thanks, Rishi

ClassCastException when using types that extends Collection<Something>

I've got a class like this:

public class People extends ArrayList< Person > {
...
}

And I'm using it, for example, in a class like

public class Company {
    People employees;
}

When I'm trying to generate a json schema for Company, I run in a CLassCastException at PropertyWrapper.java:79

java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
	at com.github.reinert.jjschema.v1.PropertyWrapper.<init>(PropertyWrapper.java:79)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:154)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:87)
	at com.github.reinert.jjschema.v1.CustomSchemaWrapper.<init>(CustomSchemaWrapper.java:63)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:71)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:47)
	at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:39)
	at com.github.reinert.jjschema.v1.JsonSchemaV4Factory.createSchema(JsonSchemaV4Factory.java:36)

Include some Ignore feature

JJSchema should provide some way to let the user decide which field he wants to be ignored in the schema generation process.

java.util.Date serializing and deserializing

Generating json from a Date attribute in a Pojo gives :
updateDate : {
"time": number,
"year": number,
"hours": number,
"seconds": number,
"timezoneOffset": number,
"day": number,
"minutes": number,
"date": number,
"month": number
}

When I try to create an instance of my Pojo I use the same structure but it gives me an com.fasterxml.jackson.databind.JsonMappingException with a message saying : Can not deserialize instance of java.util.Date out of START_OBJECT token \n

Java Instant parsing problem

Hi!
I am able to create json schemas from a class but when I use parameter type INSTANT or LOCALDATE I get an error.
Having this
@Attributes(required = false, description = "Task type identificator")
private LocalDate startingDate;
or this
@Attributes(required = false, description = "Task type identificator")
private Instant startingDate;

I get this error:

[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ MockWS---
[INFO] Running war on http://localhost:9090/MockWS
[INFO] Creating Tomcat server configuration at C:\WorkMockWS\target\tomcat
[INFO] create webapp with contextPath: /MockWS
ene 30, 2017 2:46:16 PM org.apache.coyote.AbstractProtocol init
INFORMACIËN: Initializing ProtocolHandler ["http-bio-9090"]
ene 30, 2017 2:46:16 PM org.apache.catalina.core.StandardService startInternal
INFORMACIËN: Starting service Tomcat
ene 30, 2017 2:46:16 PM org.apache.catalina.core.StandardEngine startInternal
INFORMACIËN: Starting Servlet Engine: Apache Tomcat/7.0.47
ene 30, 2017 2:46:18 PM com.sun.xml.ws.transport.http.servlet.WSServletContextListener parseAdaptersAndCreateDelegate
GRAVE: WSSERVLET11: failed to parse runtime descriptor: java.lang.StringIndexOutOfBoundsException: String index out of range: 1
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.substring(String.java:1963)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.getNameFromGetter(CustomSchemaWrapper.java:200)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.findProperties(CustomSchemaWrapper.java:167)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:136)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.(CustomSchemaWrapper.java:64)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:67)
at com.github.reinert.jjschema.v1.PropertyWrapper.(PropertyWrapper.java:125)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:139)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.(CustomSchemaWrapper.java:64)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.(CustomSchemaWrapper.java:51)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.(CustomSchemaWrapper.java:47)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:71)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:47)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:39)
at com.github.reinert.jjschema.v1.JsonSchemaV4Factory.createSchema(JsonSchemaV4Factory.java:36)
at MockWS.testJsonSchemaGenerator.loadPeriodicTaskSchema(JsonSchemaGenerator.java:45)
at MockWS.WebService.(WebService.java:35)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at com.sun.xml.ws.api.server.InstanceResolver.createNewInstance(InstanceResolver.java:219)
at com.sun.xml.ws.api.server.InstanceResolver.createDefault(InstanceResolver.java:184)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:127)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:513)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:257)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:151)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:131)
at com.sun.xml.ws.transport.http.servlet.WSServletContainerInitializer.onStartup(WSServletContainerInitializer.java:65)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5423)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

ene 30, 2017 2:46:18 PM org.apache.catalina.core.StandardContext startInternal
GRAVE: Error during ServletContainerInitializer processing
javax.servlet.ServletException: com.sun.xml.ws.transport.http.servlet.WSServletException: WSSERVLET11: failed to parse runtime descriptor: java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at com.sun.xml.ws.transport.http.servlet.WSServletContainerInitializer.onStartup(WSServletContainerInitializer.java:70)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5423)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.sun.xml.ws.transport.http.servlet.WSServletException: WSSERVLET11: failed to parse runtime descriptor: java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:141)
at com.sun.xml.ws.transport.http.servlet.WSServletContainerInitializer.onStartup(WSServletContainerInitializer.java:65)
... 8 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.substring(String.java:1963)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.getNameFromGetter(CustomSchemaWrapper.java:200)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.findProperties(CustomSchemaWrapper.java:167)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:136)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.(CustomSchemaWrapper.java:64)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:67)
at com.github.reinert.jjschema.v1.PropertyWrapper.(PropertyWrapper.java:125)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.processProperties(CustomSchemaWrapper.java:139)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.(CustomSchemaWrapper.java:64)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.(CustomSchemaWrapper.java:51)
at com.github.reinert.jjschema.v1.CustomSchemaWrapper.(CustomSchemaWrapper.java:47)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:71)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:47)
at com.github.reinert.jjschema.v1.SchemaWrapperFactory.createWrapper(SchemaWrapperFactory.java:39)
at com.github.reinert.jjschema.v1.JsonSchemaV4Factory.createSchema(JsonSchemaV4Factory.java:36)
at MockWS.JsonSchemaGenerator.loadTaskSchema(JsonSchemaGenerator.java:45)
at MockWS.WebService.(WebService.java:35)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at com.sun.xml.ws.api.server.InstanceResolver.createNewInstance(InstanceResolver.java:219)
at com.sun.xml.ws.api.server.InstanceResolver.createDefault(InstanceResolver.java:184)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:127)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:513)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:257)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:151)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:131)
... 9 more

The parsing code is the standar > schemaFactory.createSchema(PeriodicTask.class);
If I use Date or any other, then there is no problem. Any suggestion? Is there a way or example how to use INSTANT?

Definitly support customized collections

As you can see, the only way to generate a schema from a customized colletion is to wrap it into an Interable class.

For instance, if i want to generate a schema for an array of User, Java does not allow me to do pass as parameter a generic typed class like List< User >.class because of TypeErasure.

So, the need for creating a customized Iterable class, like:
class Users implements Iterable< User >

But, if you create a customized Collection class, like:
class Users extends Collection< User >
, the generator method won't recognize it as a customized array. Instead, it wil just map it as a simple array.

That's because, at the generator method, when I identify that the class inherits from Collection, so I define it as a simple array.

For differring simples arrays from customized arrays extended from Collection, we need to preview all the actual Java predefined Collection Types.

As fge contributed with an great idea of mapping all predefined types into an enum, we can than implement all the Java predefined Collection types into this enum and it will posibilite us to differentiate, at the generator method, if the class been mapped is a customized array or just a simple array.

What do you think?

Support for Bean Validation Annotations

Would be realy great if Bean Validation Annotations would be supported to define (most) auf the JSON Schema, so the validation rules don't have to be defined twice

Json Schema v3?

Hi,

Is there a way to configure JJSchema to produce output according to the 3rd version of the JSON schema specification?

Thanks, RK

Error minLength & maxLength

Hello Danilo,

I am using JJSchema and I have found a bug in file "JsonSchemaGeneratorV4.java":

if (props.minLength() > 0) {
schema.put("minLength", props.minItems());
}
if (props.maxLength() > -1) {
schema.put("maxLength", props.maxItems());
}

As you can see, when you put the properties minLength and maxLength in the schema, you are using minItems and maxItems instead the correct properties.

I have seen that you correct the same bug in file "PropertyWrapper.java" so I think it works in v1 but not in v4.

Best regards, Eduardo.

Bug Fix: fieldName could be empty or null.

Guard clause needs to be updated to check the validity of the fieldName in CustomSchemaWrapper.java.

Example:

If a class has method with signature public List<String> get(Object key), the methodName would be returned as get. When the following block is executed, it would return the fieldName as empty string.

if (methodName.startsWith(prefix)) {
    fieldName = methodName.substring(prefix.length());
}

So when fieldName.substring(..) is executed, it would throw java.lang.StringIndexOutOfBoundsException exception.

I have created PR #56 to fix this issue.

Use TestNG for testing purposes?

I see JUnit 3.x is used.

TestNG is (imho) a better tool for that. Consider this:

https://github.com/fge/json-schema-validator/blob/master/src/test/java/com/github/fge/jsonschema/syntax/AbstractSyntaxCheckerTest.java

In particular, note that there is a @DataProvider and it is used in the test:

    @Test(dataProvider = "getData", invocationCount = 5, threadPoolSize = 3)

This tests not only against all of the data provided by the data provider, but also does multithreaded testing.

Which means you can test at very low levels with ease: just create the appropriate data provider.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.