Skip to content

Commit

Permalink
Fixes #225
Browse files Browse the repository at this point in the history
Unfortunately, POJO generation from JSON schemas is not supported in tests
  • Loading branch information
Aleksandar Stojsavljevic committed Apr 16, 2018
1 parent 07b0a1b commit 23c9fd3
Showing 1 changed file with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.phoenixnap.oss.ramlplugin.raml2code.helpers.NamingHelper;
import com.phoenixnap.oss.ramlplugin.raml2code.helpers.RamlParser;
import com.phoenixnap.oss.ramlplugin.raml2code.helpers.RamlTypeHelper;
import com.phoenixnap.oss.ramlplugin.raml2code.helpers.SchemaHelper;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlDataType;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.RamlRoot;
import com.phoenixnap.oss.ramlplugin.raml2code.raml.raml10.RJP10V2RamlRoot;
Expand Down Expand Up @@ -266,8 +267,10 @@ protected void generateEndpoints() throws IOException {
throw new IOException("Could not create directory:" + rootDir.getAbsolutePath());
}

generateCode(codeModel, controllers, rootDir);
generateUnreferencedSchemasV10(codeModel, loadRamlFromFile, rootDir, controllers);
generateCode(null, controllers, rootDir);
if (this.generateUnreferencedSchemas) {
generateUnreferencedObjects(codeModel, loadRamlFromFile, resolvedRamlPath, rootDir, controllers);
}

if (unifiedModel) {
buildCodeModelToDisk(codeModel, "Unified", rootDir);
Expand All @@ -293,18 +296,27 @@ private Set<String> getAllReferencedTypeNames(Set<ApiResourceMetadata> controlle
return bodyNames;
}

private void generateUnreferencedSchemasV10(JCodeModel codeModel, RamlRoot loadRamlFromFile, File rootDir,
private void generateUnreferencedObjects(JCodeModel codeModel, RamlRoot loadRamlFromFile, String resolvedRamlPath, File rootDir,
Set<ApiResourceMetadata> controllers) {
if (this.generateUnreferencedSchemas) {
if (loadRamlFromFile.getTypes() != null && !loadRamlFromFile.getTypes().isEmpty()) {
this.getLog().debug("Generating Code for Unreferenced Types");
if (loadRamlFromFile.getTypes() != null && !loadRamlFromFile.getTypes().isEmpty()) {
Set<String> allReferencedTypes = getAllReferencedTypeNames(controllers);
for (Map.Entry<String, RamlDataType> type : loadRamlFromFile.getTypes().entrySet()) {
if (!allReferencedTypes.contains(type.getKey())) {
ApiBodyMetadata tempBodyMetadata = RamlTypeHelper.mapTypeToPojo(codeModel, loadRamlFromFile,
type.getValue().getType());
generateModelSources(codeModel, tempBodyMetadata, rootDir);
}
Set<String> allReferencedTypes = getAllReferencedTypeNames(controllers);
for (Map.Entry<String, RamlDataType> type : loadRamlFromFile.getTypes().entrySet()) {
if (!allReferencedTypes.contains(type.getKey())) {
ApiBodyMetadata tempBodyMetadata = RamlTypeHelper.mapTypeToPojo(codeModel, loadRamlFromFile, type.getValue().getType());
generateModelSources(codeModel, tempBodyMetadata, rootDir);
}
}
}

if (loadRamlFromFile.getSchemas() != null && !loadRamlFromFile.getSchemas().isEmpty()) {
this.getLog().debug("Generating Code for Unreferenced Schemas");
for (Map<String, String> map : loadRamlFromFile.getSchemas()) {
for (String schemaName : map.keySet()) {
this.getLog().info("Generating POJO for unreferenced schema " + schemaName);
ApiBodyMetadata tempBodyMetadata = SchemaHelper.mapSchemaToPojo(loadRamlFromFile, schemaName, resolvedRamlPath,
schemaName, this.resolvedSchemaLocation);
generateModelSources(null, tempBodyMetadata, rootDir);
}
}
}
Expand Down

0 comments on commit 23c9fd3

Please sign in to comment.