Skip to content

Commit

Permalink
WIP JSON generator
Browse files Browse the repository at this point in the history
  • Loading branch information
CiGit committed Apr 8, 2019
1 parent 04e1ede commit f899f95
Show file tree
Hide file tree
Showing 18 changed files with 786 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ wegas-core/target
wegas-runtime/target/
wegas-runtime/derby.log
wegas-resources/target
wenerator-maven-plugin/target
doc/Wegas.uml~
#!target/site*
#!target/Wegas.war
Expand Down
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<module>wegas-app</module>
<module>wegas-resources</module>
<!--<module>wegas-mcq</module>-->
<module>wenerator-maven-plugin</module>
</modules>

<developers>
Expand Down Expand Up @@ -157,6 +158,11 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.wegas</groupId>
<artifactId>wegas-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
Expand Down Expand Up @@ -560,7 +566,7 @@
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix></classpathPrefix>
<classpathPrefix/>
</manifest>
</archive>
</configuration>
Expand Down Expand Up @@ -969,4 +975,4 @@
<url>http://jsdoctk-plugin.googlecode.com/svn/repo</url>
</pluginRepository>
</pluginRepositories>
</project>
</project>
26 changes: 25 additions & 1 deletion wegas-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@
</profiles>

<dependencies>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wenerator-maven-plugin</artifactId>
<version>${project.version}</version>
<!-- <type>jar</type> -->
<scope>compile</scope>
</dependency>
<!-- Project dependencies -->
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -274,6 +280,24 @@
<finalName>Wegas</finalName>

<plugins>
<plugin>
<groupId>com.wegas</groupId>
<artifactId>wenerator-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>schema</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/${project.build.finalName}/generated-schema</outputDirectory>
<pkg>
<param>com.wegas</param>
</pkg>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.wegas.editor.JSONSchema;

public class JSONArray extends JSONType {
private JSONSchema items;
private Integer minItems;
private Integer maxItems;

/**
* @return the items
*/
public JSONSchema getItems() {
return items;
}

/**
* @return the maxItems
*/
public Integer getMaxItems() {
return maxItems;
}

/**
* @param maxItems the maxItems to set
*/
public void setMaxItems(Integer maxItems) {
this.maxItems = maxItems;
}

/**
* @return the minItems
*/
public Integer getMinItems() {
return minItems;
}

/**
* @param minItems the minItems to set
*/
public void setMinItems(Integer minItems) {
this.minItems = minItems;
}

/**
* @param items the items to set
*/
public void setItems(JSONSchema items) {
this.items = items;
}

@Override
final public String getType() {
return "array";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wegas.editor.JSONSchema;

public class JSONBoolean extends JSONType {

@Override
final public String getType() {
return "boolean";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wegas.editor.JSONSchema;

public class JSONNumber extends JSONType {

@Override
final public String getType() {
return "number";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.wegas.editor.JSONSchema;

import java.util.HashMap;
import java.util.Map;

public class JSONObject extends JSONType {
private Map<String, JSONSchema> properties;
private JSONSchema additionalProperties;

/**
* @return the additionalProperties
*/
public JSONSchema getAdditionalProperties() {
return additionalProperties;
}

/**
* @param additionalProperties the additionalProperties to set
*/
public void setAdditionalProperties(JSONSchema additionalProperties) {
this.additionalProperties = additionalProperties;
}

/**
* @return the properties
*/
public Map<String, JSONSchema> getProperties() {
return properties;
}

/**
* @param prop the property name
* @param value the value
*/
public void setProperty(String prop, JSONSchema value) {
if (this.properties == null) {
this.properties = new HashMap<>();
}
this.properties.put(prop, value);
}

@Override
final public String getType() {
return "object";
}

}
19 changes: 19 additions & 0 deletions wegas-core/src/main/java/com/wegas/editor/JSONSchema/JSONRef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.wegas.editor.JSONSchema;

import com.fasterxml.jackson.annotation.JsonProperty;

public class JSONRef implements JSONSchema {
@JsonProperty("$ref")
private String ref;

public JSONRef(String ref) {
this.ref = ref;
}

/**
* @return the ref
*/
public String getRef() {
return ref;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wegas.editor.JSONSchema;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public interface JSONSchema {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.wegas.editor.JSONSchema;

public class JSONString extends JSONType {

@Override
final public String getType() {
return "string";
}
}
78 changes: 78 additions & 0 deletions wegas-core/src/main/java/com/wegas/editor/JSONSchema/JSONType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.wegas.editor.JSONSchema;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;

@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class JSONType implements JSONSchema {
abstract String getType();

private JsonNode value;

@JsonProperty("enum")
private List<JsonNode> enums;

@JsonProperty("const")
private JsonNode constant;

private String description;

/**
* @return the description
*/
public String getDescription() {
return description;
}

/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}

/**
* @return the enums (enum)
*/
public List<JsonNode> getEnums() {
return enums;
}

/**
* @param enums the enums to set (enum)
*/
public void setEnums(List<JsonNode> enums) {
this.enums = enums;
}

/**
* @return the value
*/
public JsonNode getValue() {
return value;
}

/**
* @param value the value to set
*/
public void setValue(JsonNode value) {
this.value = value;
}

/**
* @return the constant (const)
*/
public JsonNode getConstant() {
return constant;
}

/**
* @param constant the constant to set (const)
*/
public void setConstant(JsonNode constant) {
this.constant = constant;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wegas.editor.JSONSchema;

public final class JSONUnknown extends JSONType {

@Override
public String getType() {
return null;
}

}
25 changes: 25 additions & 0 deletions wegas-core/src/main/java/com/wegas/editor/Schema.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.wegas.editor;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.wegas.editor.JSONSchema.JSONSchema;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Inherited
@Repeatable(Schemas.class)
public @interface Schema {
Class<? extends JSONSchema> value();

String property();

/**
* Shallow merge, default true
*/
boolean merge() default true;
}
14 changes: 14 additions & 0 deletions wegas-core/src/main/java/com/wegas/editor/Schemas.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.wegas.editor;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Inherited
public @interface Schemas {
Schema[] value();
}
Loading

0 comments on commit f899f95

Please sign in to comment.