Skip to content

Commit b4b6101

Browse files
committed
Enable configuring @type attribute for JSON payload in samm-cli
1 parent 30dc4de commit b4b6101

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

documentation/developer-guide/modules/tooling-guide/pages/samm-cli.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ of model resolution] for more information.
166166
be generated (default: en) | `samm aspect AspectModel.ttl to asyncapi -l de`
167167
| _--separate-files, -sf_ : Create separate files for each schema |
168168
| _--custom-resolver_ : use an external resolver for the resolution of the model elements |
169-
.3+| [[aspect-to-json]] aspect <model> to json | Generate example JSON payload data for an Aspect Model | `samm aspect AspectModel.ttl to json`
169+
.4+| [[aspect-to-json]] aspect <model> to json | Generate example JSON payload data for an Aspect Model | `samm aspect AspectModel.ttl to json`
170170
| _--output, -o_ : output file path (default: stdout) |
171171
| _--custom-resolver_ : use an external resolver for the resolution of the model elements |
172+
| _--add-type-attribute_, _-ta_ : Add `@type` attribute for inherited Entities |
172173
.3+| [[aspect-to-jsonld]] aspect <model> to jsonld | Generate JSON-LD representation of an Aspect Model | `samm aspect AspectModel.ttl to jsonld`
173174
| _--output, -o_ : output file path (default: stdout) |
174175
| _--custom-resolver_ : use an external resolver for the resolution of the model elements |

tools/samm-cli/src/main/java/org/eclipse/esmf/aspect/to/AspectToJsonCommand.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.eclipse.esmf.ResolverConfigurationMixin;
1919
import org.eclipse.esmf.aspect.AspectToCommand;
2020
import org.eclipse.esmf.aspectmodel.generator.json.AspectModelJsonPayloadGenerator;
21+
import org.eclipse.esmf.aspectmodel.generator.json.JsonPayloadGenerationConfig;
22+
import org.eclipse.esmf.aspectmodel.generator.json.JsonPayloadGenerationConfigBuilder;
2123

2224
import picocli.CommandLine;
2325

@@ -35,6 +37,12 @@ public class AspectToJsonCommand extends AbstractCommand {
3537
description = "Output file path" )
3638
private String outputFilePath = "-";
3739

40+
@SuppressWarnings( "FieldCanBeLocal" )
41+
@CommandLine.Option(
42+
names = { "--add-type-attribute", "-ta" },
43+
description = "Add @type attribute for inherited Entities" )
44+
private boolean addTypeAttribute = false;
45+
3846
@SuppressWarnings( "FieldCanBeLocal" )
3947
@CommandLine.Option(
4048
names = { "--details" },
@@ -55,8 +63,11 @@ public void run() {
5563
setDetails( details );
5664
setResolverConfig( resolverConfiguration );
5765

66+
final JsonPayloadGenerationConfig config = JsonPayloadGenerationConfigBuilder.builder()
67+
.addTypeAttributeForEntityInheritance( addTypeAttribute )
68+
.build();
5869
final AspectModelJsonPayloadGenerator generator = new AspectModelJsonPayloadGenerator(
59-
getInputHandler( parentCommand.parentCommand.getInput() ).loadAspect() );
70+
getInputHandler( parentCommand.parentCommand.getInput() ).loadAspect(), config );
6071
// we intentionally override the name of the generated artifact here to the name explicitly desired by the user (outputFilePath),
6172
// as opposed to what the model thinks it should be called (name)
6273
generator.generate( name -> getStreamForFile( outputFilePath ) );

0 commit comments

Comments
 (0)