Skip to content

Commit 30dc4de

Browse files
committed
Enable configuring @type attribute for JSON payload in Maven plugin
1 parent a3d27c3 commit 30dc4de

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

documentation/developer-guide/modules/tooling-guide/pages/maven-plugin.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ Configuration Properties:
524524
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
525525
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
526526
| `outputDirectory` | The path to the directory where the generated JSON payload will be written to. | `String` | none | {ok}
527+
| `addTypeAttribute` | Adds a `@type` attribute for inherited Entities | `Boolean` | `false` | {ok}
527528
|===
528529

529530
=== Generating JSON-LD representation of an Aspect Model

tools/esmf-aspect-model-maven-plugin/src/main/java/org/eclipse/esmf/aspectmodel/GenerateJsonPayload.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,35 @@
1616
import java.util.Set;
1717

1818
import org.eclipse.esmf.aspectmodel.generator.json.AspectModelJsonPayloadGenerator;
19+
import org.eclipse.esmf.aspectmodel.generator.json.JsonPayloadGenerationConfig;
20+
import org.eclipse.esmf.aspectmodel.generator.json.JsonPayloadGenerationConfigBuilder;
1921
import org.eclipse.esmf.metamodel.Aspect;
2022

2123
import org.apache.maven.plugin.MojoExecutionException;
2224
import org.apache.maven.plugin.MojoFailureException;
2325
import org.apache.maven.plugins.annotations.LifecyclePhase;
2426
import org.apache.maven.plugins.annotations.Mojo;
27+
import org.apache.maven.plugins.annotations.Parameter;
2528
import org.slf4j.Logger;
2629
import org.slf4j.LoggerFactory;
2730

2831
@Mojo( name = "generateJsonPayload", defaultPhase = LifecyclePhase.GENERATE_RESOURCES )
2932
public class GenerateJsonPayload extends AspectModelMojo {
3033
private static final Logger LOG = LoggerFactory.getLogger( GenerateJsonPayload.class );
3134

35+
@Parameter( defaultValue = "false" )
36+
private boolean addTypeAttribute;
37+
3238
@Override
3339
public void executeGeneration() throws MojoExecutionException, MojoFailureException {
3440
validateParameters();
3541

3642
final Set<Aspect> aspects = loadAspects();
3743
for ( final Aspect context : aspects ) {
38-
final AspectModelJsonPayloadGenerator generator = new AspectModelJsonPayloadGenerator( context );
44+
final JsonPayloadGenerationConfig config = JsonPayloadGenerationConfigBuilder.builder()
45+
.addTypeAttributeForEntityInheritance( addTypeAttribute )
46+
.build();
47+
final AspectModelJsonPayloadGenerator generator = new AspectModelJsonPayloadGenerator( context, config );
3948
generator.generate( name -> getOutputStreamForFile( name + ".json", outputDirectory ) );
4049
}
4150
LOG.info( "Successfully generated example JSON payloads for Aspect Models." );

0 commit comments

Comments
 (0)