Skip to content

Commit

Permalink
Merge pull request #8
Browse files Browse the repository at this point in the history
gh actions
  • Loading branch information
ivangsa authored May 11, 2023
2 parents 4838541 + 8ffafd3 commit e13b063
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/prepare-maven-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
token: ${{ github.token }}
# with:
# token: ${{ github.token }}
- name: Set up Java for publishing to Maven Central Repository
uses: actions/setup-java@v2
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@

import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.StringUtils;
import org.jsonschema2pojo.FileCodeWriterWithEncoding;
import org.jsonschema2pojo.Jackson2Annotator;
import org.jsonschema2pojo.Jsonschema2Pojo;
import org.jsonschema2pojo.SchemaGenerator;
import org.jsonschema2pojo.SchemaMapper;
import org.jsonschema2pojo.SchemaStore;
import org.jsonschema2pojo.SourceType;
import org.jsonschema2pojo.*;
import org.jsonschema2pojo.exception.ClassAlreadyExistsException;
import org.jsonschema2pojo.rules.RuleFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -148,13 +143,15 @@ public void generateFromJsonSchemaFile(JsonSchema2PojoConfiguration config, URL
SourceType sourceType = url.getFile().endsWith(".yml") || url.getFile().endsWith(".yaml") ? YAMLSCHEMA : JSONSCHEMA;
config.setSourceType(sourceType);
}
Jsonschema2Pojo.generate(config, null);
Jsonschema2Pojo.generate(config, ruleLogger);
}

public void generateFromNativeFormat(JsonSchema2PojoConfiguration config, Map<String, Object> payload, String packageName, String className) throws IOException {
var json = this.convertToJson(payload, packageName);

SchemaMapper mapper = new SchemaMapper(new RuleFactory(config, new Jackson2Annotator(config), new SchemaStore()), new SchemaGenerator());
var ruleFactory = new RuleFactory(config, new Jackson2Annotator(config), new SchemaStore());
ruleFactory.setLogger(ruleLogger);
SchemaMapper mapper = new SchemaMapper(ruleFactory, new SchemaGenerator());
var sourcesWriter = new FileCodeWriterWithEncoding(targetSourceFolder, config.getOutputEncoding());
var resourcesWriter = new FileCodeWriterWithEncoding(targetSourceFolder, config.getOutputEncoding());
var codeModel = new JCodeModel();
Expand All @@ -174,4 +171,59 @@ protected String convertToJson(final Map<String, Object> payload, final String p
return this.jsonMapper.writeValueAsString(jsonObject);
}

private RuleLogger ruleLogger = new AbstractRuleLogger() {
@Override
protected void doDebug(String msg) {
log.debug(msg);
}

@Override
protected void doError(String msg, Throwable e) {
if (e instanceof ClassAlreadyExistsException) {
log.debug("Class already exists: {}", ((ClassAlreadyExistsException)e).getExistingClass());
} else {
log.debug(msg, e);
}
}

@Override
protected void doInfo(String msg) {
log.debug(msg);
}

@Override
protected void doTrace(String msg) {
log.trace(msg);
}

@Override
protected void doWarn(String msg, Throwable e) {

}

@Override
public boolean isDebugEnabled() {
return false;
}

@Override
public boolean isErrorEnabled() {
return false;
}

@Override
public boolean isInfoEnabled() {
return false;
}

@Override
public boolean isTraceEnabled() {
return false;
}

@Override
public boolean isWarnEnabled() {
return false;
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ public void setup() throws IOException {
FileUtils.deleteDirectory(new File("target/zenwave630/out"));
}

@Test
public void test_generator_for_asyncapi_repeated_enum() throws Exception {
Plugin plugin = new AsyncApiJsonSchema2PojoPlugin()
.withSpecFile("classpath:asyncapi.yml")
.withTargetFolder("target/zenwave630")
.withOption("modelPackage", "io.example.integration.test.with_schemas.model");

new MainGenerator().generate(plugin);

Assertions.assertTrue(new File("target/zenwave630/src/main/java/io/example/integration/test/with_schemas/model/Email.java").exists());
Assertions.assertTrue(new File("target/zenwave630/src/main/java/io/example/integration/test/with_schemas/model/UserSignedUp.java").exists());
}

@Test
public void test_generator_for_asyncapi_schemas() throws Exception {
Plugin plugin = new AsyncApiJsonSchema2PojoPlugin()
Expand Down
32 changes: 32 additions & 0 deletions plugins/asyncapi-jsonschema2pojo/src/test/resources/asyncapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
asyncapi: '2.6.0'
info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user signups
channels:
user/signedup:
subscribe:
operationId: user-signedup
message:
$ref: '#/components/messages/UserSignedUp'
components:
messages:
UserSignedUp:
payload:
type: object
properties:
displayName:
type: string
description: Name of the user
email:
$ref: "#/components/schemas/Email"
description: Email of the user
backupEmail:
description: something else
$ref: "#/components/schemas/Email"
schemas:
Email:
type: string
enum:
- Google
- Yahoo

0 comments on commit e13b063

Please sign in to comment.