Skip to content

Commit 59121e4

Browse files
committed
Issue #22.
1 parent 4b0a823 commit 59121e4

File tree

8 files changed

+43
-33
lines changed

8 files changed

+43
-33
lines changed

compiler/src/main/java/org/hisrc/jsonix/compilation/jsonschema/JsonSchemaClassInfoCompiler.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import java.util.LinkedHashMap;
55
import java.util.List;
66
import java.util.Map;
7-
import java.util.Map.Entry;
87

98
import javax.xml.namespace.QName;
109

1110
import org.apache.commons.lang3.Validate;
11+
import org.hisrc.jsonix.JsonixConstants;
1212
import org.hisrc.jsonix.definition.Mapping;
1313
import org.hisrc.jsonix.jsonschema.JsonSchemaBuilder;
1414
import org.hisrc.jsonix.naming.StandardNaming;
@@ -19,9 +19,6 @@
1919
public class JsonSchemaClassInfoCompiler<T, C extends T> implements
2020
JsonSchemaTypeInfoCompiler<MClassInfo<T, C>, T, C> {
2121

22-
// TODO move to constants
23-
public static final String DEFAULT_SCOPED_NAME_DELIMITER = ".";
24-
2522
private final JsonSchemaMappingCompiler<T, C> mappingCompiler;
2623
private final Mapping<T, C> mapping;
2724

@@ -41,7 +38,7 @@ public JsonSchemaBuilder compile(MClassInfo<T, C> classInfo) {
4138
final JsonSchemaBuilder classInfoSchema = new JsonSchemaBuilder();
4239
classInfoSchema.addType("object");
4340
final String localName = classInfo
44-
.getContainerLocalName(DEFAULT_SCOPED_NAME_DELIMITER);
41+
.getContainerLocalName(JsonixConstants.DEFAULT_SCOPED_NAME_DELIMITER);
4542
classInfoSchema.addTitle(localName);
4643
final MClassTypeInfo<T, C> baseTypeInfo = classInfo.getBaseTypeInfo();
4744
final JsonSchemaBuilder typeInfoSchema;
@@ -55,15 +52,11 @@ public JsonSchemaBuilder compile(MClassInfo<T, C> classInfo) {
5552
typeInfoSchema = classInfoSchema;
5653
}
5754

58-
// TODO move to the builder
5955
final Map<String, JsonSchemaBuilder> propertyInfoSchemas = compilePropertyInfos(classInfo);
6056
final List<String> propertiesOrder = new ArrayList<String>(
6157
propertyInfoSchemas.size());
62-
for (Entry<String, JsonSchemaBuilder> entry : propertyInfoSchemas
63-
.entrySet()) {
64-
propertiesOrder.add(entry.getKey());
65-
classInfoSchema.addProperty(entry.getKey(), entry.getValue());
66-
}
58+
propertiesOrder.addAll(propertyInfoSchemas.keySet());
59+
classInfoSchema.addProperties(propertyInfoSchemas);
6760
typeInfoSchema.add(JsonixJsonSchemaConstants.TYPE_TYPE_PROPERTY_NAME,
6861
StandardNaming.CLASS_INFO);
6962
final QName typeName = classInfo.getTypeName();

compiler/src/main/java/org/hisrc/jsonix/compilation/jsonschema/JsonSchemaEnumLeafInfoCompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public JsonSchemaBuilder compile(MEnumLeafInfo<T, C> enumLeafInfo) {
4141
for (MEnumConstantInfo<T, C> enumConstant : enumLeafInfo.getConstants()) {
4242
final JsonSchemaBuilder enumConstantSchema = createEnumConstant(
4343
enumLeafInfo, enumConstant);
44-
// TODO
44+
// TODO generate enums
4545
if (enumConstantSchema != null) {
4646
typeInfoSchema.addEnum(enumConstantSchema);
4747
}

compiler/src/main/java/org/hisrc/jsonix/compilation/jsonschema/JsonSchemaMappingCompiler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public Mapping<T, C> getMapping() {
4949

5050
public JsonSchemaBuilder compile() {
5151
final JsonSchemaBuilder schema = new JsonSchemaBuilder();
52-
schema.addId(mapping.getSchemaId());
52+
final String schemaId = mapping.getSchemaId();
53+
if (!schemaId.isEmpty()) {
54+
schema.addId(schemaId);
55+
}
5356
addElementInfos(schema);
5457
addClassInfoSchemas(schema);
5558
addElementLeafInfoSchemas(schema);
@@ -94,7 +97,6 @@ private void addElementLeafInfoSchemas(final JsonSchemaBuilder schema) {
9497
for (MEnumLeafInfo<T, C> enumLeafInfo : mapping.getEnumLeafInfos()) {
9598
final JsonSchemaBuilder enumLeafInfoSchema = enumLeafInfoCompiler
9699
.compile(enumLeafInfo);
97-
// TODO constant
98100
schema.addDefinition(
99101
enumLeafInfo
100102
.getContainerLocalName(JsonixConstants.DEFAULT_SCOPED_NAME_DELIMITER),

compiler/src/main/java/org/hisrc/jsonix/compilation/jsonschema/JsonSchemaModuleCompiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class JsonSchemaModuleCompiler<T, C extends T> {
1515
private final JsonSchemaModulesCompiler<T, C> modulesCompiler;
1616
private final Modules<T, C> modules;
1717
private final Module<T, C> module;
18-
private final JsonSchema jsonSchema;
18+
// private final JsonSchema jsonSchema;
1919

2020
public JsonSchemaModuleCompiler(
2121
JsonSchemaModulesCompiler<T, C> modulesCompiler, Module<T, C> module, JsonSchema jsonSchema) {
@@ -25,7 +25,7 @@ public JsonSchemaModuleCompiler(
2525
this.modulesCompiler = modulesCompiler;
2626
this.modules = modulesCompiler.getModules();
2727
this.module = module;
28-
this.jsonSchema = jsonSchema;
28+
// this.jsonSchema = jsonSchema;
2929
}
3030

3131
public JsonSchemaModulesCompiler<T, C> getModulesCompiler() {

compiler/src/main/java/org/hisrc/jsonix/compilation/jsonschema/JsonSchemaPropertyInfoCompilerVisitor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ private JsonSchemaBuilder createElementRefSchema(
310310
MElementTypeInfo<T, C> elementTypeInfo) {
311311
final JsonSchemaBuilder schema = new JsonSchemaBuilder();
312312
addElementNameSchema(elementTypeInfo.getElementName(), schema);
313-
// TODO constant
314313
schema.addType(JsonSchemaConstants.OBJECT_TYPE);
315314
schema.addProperty(
316315
JsonixConstants.NAME_PROPERTY_NAME,

compiler/src/main/java/org/hisrc/jsonix/compilation/jsonschema/JsonixJsonSchemaConstants.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ public class JsonixJsonSchemaConstants {
55
private JsonixJsonSchemaConstants() {
66
}
77

8-
public static final String SCHEMA_ID = "todo:_jsonix_schema_id";
9-
10-
public static final String WILDCARD_TYPE_INFO_SCHEMA_REF = SCHEMA_ID + "/"
11-
+ JsonSchemaKeywords.definitions + "/" + "wildcard";
12-
public static final String DOM_TYPE_INFO_SCHEMA_REF = SCHEMA_ID + "/"
13-
+ JsonSchemaKeywords.definitions + "/" + "dome";
8+
public static final String CALENDAR_TYPE_INFO_SCHEMA_REF = "https://cdn.rawgit.com/highsource/jsonix/master/jsonschemas/jsonix/Jsonix.jsonschema#/definitions/calendar";
9+
// TODO Better schema?
10+
public static final String WILDCARD_TYPE_INFO_SCHEMA_REF = "https://cdn.rawgit.com/highsource/jsonix/master/jsonschemas/jsonix/Jsonix.jsonschema#/definitions/wildcard";
11+
// TODO Better schema?
12+
public static final String DOM_TYPE_INFO_SCHEMA_REF = "https://cdn.rawgit.com/highsource/jsonix/master/jsonschemas/jsonix/Jsonix.jsonschema#/definitions/dom";
1413

1514
public static String TYPE_TYPE_PROPERTY_NAME = "typeType";
1615

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.hisrc.jsonix.compilation.jsonschema;
22

33
import java.util.Collections;
4-
import java.util.HashMap;
4+
import java.util.LinkedHashMap;
55
import java.util.Map;
66

77
import javax.xml.namespace.QName;
@@ -13,27 +13,34 @@ public class XmlSchemaJsonSchemaConstants {
1313
private XmlSchemaJsonSchemaConstants() {
1414
}
1515

16-
public static final String SCHEMA_ID = "foo";
16+
public static final String SCHEMA_ID = "https://cdn.rawgit.com/highsource/jsonix/master/jsonschemas/w3c/2001/XMLSchema.jsonschema#";
1717

1818
public static final Map<QName, String> TYPE_NAME_SCHEMA_REFS;
1919
static {
20-
final Map<QName, String> tnsr = new HashMap<QName, String>();
20+
final Map<QName, String> tnsr = new LinkedHashMap<QName, String>();
2121
for (QName typeName : XmlSchemaConstants.TYPE_NAMES) {
22-
tnsr.put(typeName, SCHEMA_ID + "/" + JsonSchemaKeywords.definitions + "/"
23-
+ typeName.getLocalPart());
22+
tnsr.put(typeName, SCHEMA_ID + "/" + JsonSchemaKeywords.definitions
23+
+ "/" + typeName.getLocalPart());
2424
}
25+
tnsr.put(XmlSchemaConstants.CALENDAR,
26+
JsonixJsonSchemaConstants.CALENDAR_TYPE_INFO_SCHEMA_REF);
2527
TYPE_NAME_SCHEMA_REFS = Collections.unmodifiableMap(tnsr);
2628
}
2729

2830
public static final String ID_TYPE_INFO_SCHEMA_REF = SCHEMA_ID + "/"
29-
+ JsonSchemaKeywords.definitions + "/" + XmlSchemaConstants.ID.getLocalPart();
31+
+ JsonSchemaKeywords.definitions + "/"
32+
+ XmlSchemaConstants.ID.getLocalPart();
3033
public static final String IDREFS_TYPE_INFO_SCHEMA_REF = SCHEMA_ID + "/"
31-
+ JsonSchemaKeywords.definitions + "/" + XmlSchemaConstants.IDREFS.getLocalPart();
34+
+ JsonSchemaKeywords.definitions + "/"
35+
+ XmlSchemaConstants.IDREFS.getLocalPart();
3236
public static final String IDREF_TYPE_INFO_SCHEMA_REF = SCHEMA_ID + "/"
33-
+ JsonSchemaKeywords.definitions + "/" + XmlSchemaConstants.IDREF.getLocalPart();
37+
+ JsonSchemaKeywords.definitions + "/"
38+
+ XmlSchemaConstants.IDREF.getLocalPart();
3439
public static final String STRING_TYPE_INFO_SCHEMA_REF = SCHEMA_ID + "/"
35-
+ JsonSchemaKeywords.definitions + "/" + XmlSchemaConstants.STRING.getLocalPart();
40+
+ JsonSchemaKeywords.definitions + "/"
41+
+ XmlSchemaConstants.STRING.getLocalPart();
3642
public static final String QNAME_TYPE_INFO_SCHEMA_REF = SCHEMA_ID + "/"
37-
+ JsonSchemaKeywords.definitions + "/" + XmlSchemaConstants.QNAME.getLocalPart();
43+
+ JsonSchemaKeywords.definitions + "/"
44+
+ XmlSchemaConstants.QNAME.getLocalPart();
3845

3946
}

compiler/src/main/java/org/hisrc/jsonix/jsonschema/JsonSchemaBuilder.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ public JsonSchemaBuilder addProperty(String name, JsonSchemaBuilder schema) {
253253
return this;
254254
}
255255

256+
public JsonSchemaBuilder addProperties(
257+
Map<String, JsonSchemaBuilder> properties) {
258+
Validate.notNull(properties);
259+
if (this.properties == null) {
260+
this.properties = new LinkedHashMap<String, JsonSchemaBuilder>();
261+
}
262+
this.properties.putAll(properties);
263+
return this;
264+
}
265+
256266
public JsonSchemaBuilder addPatternProperty(String pattern,
257267
JsonSchemaBuilder schema) {
258268
Validate.notNull(pattern);

0 commit comments

Comments
 (0)