13
13
14
14
package io .openmanufacturing .sds .aspectmodel .generator .jsonschema ;
15
15
16
- import com .google .common .base .Strings ;
17
- import io .openmanufacturing .sds .metamodel .NamedElement ;
18
16
import java .math .BigDecimal ;
19
17
import java .util .HashMap ;
20
18
import java .util .LinkedList ;
34
32
import com .fasterxml .jackson .databind .node .NumericNode ;
35
33
import com .fasterxml .jackson .databind .node .ObjectNode ;
36
34
import com .fasterxml .jackson .databind .node .TextNode ;
35
+ import com .google .common .base .Strings ;
37
36
import com .google .common .collect .ImmutableMap ;
38
37
39
38
import io .openmanufacturing .sds .aspectmetamodel .KnownVersion ;
40
39
import io .openmanufacturing .sds .aspectmodel .generator .DocumentGenerationException ;
41
40
import io .openmanufacturing .sds .aspectmodel .resolver .services .BammDataType ;
42
41
import io .openmanufacturing .sds .aspectmodel .urn .AspectModelUrn ;
43
42
import io .openmanufacturing .sds .aspectmodel .vocabulary .BAMM ;
43
+ import io .openmanufacturing .sds .characteristic .Collection ;
44
+ import io .openmanufacturing .sds .characteristic .Either ;
45
+ import io .openmanufacturing .sds .characteristic .Enumeration ;
46
+ import io .openmanufacturing .sds .characteristic .Set ;
47
+ import io .openmanufacturing .sds .characteristic .SingleEntity ;
48
+ import io .openmanufacturing .sds .characteristic .SortedSet ;
49
+ import io .openmanufacturing .sds .characteristic .Trait ;
50
+ import io .openmanufacturing .sds .constraint .LengthConstraint ;
51
+ import io .openmanufacturing .sds .constraint .RangeConstraint ;
52
+ import io .openmanufacturing .sds .constraint .RegularExpressionConstraint ;
44
53
import io .openmanufacturing .sds .metamodel .AbstractEntity ;
45
54
import io .openmanufacturing .sds .metamodel .Aspect ;
46
- import io .openmanufacturing .sds .metamodel .ModelElement ;
47
55
import io .openmanufacturing .sds .metamodel .Characteristic ;
48
- import io .openmanufacturing .sds .characteristic .Collection ;
49
56
import io .openmanufacturing .sds .metamodel .CollectionValue ;
50
57
import io .openmanufacturing .sds .metamodel .ComplexType ;
51
58
import io .openmanufacturing .sds .metamodel .Constraint ;
52
- import io .openmanufacturing .sds .characteristic .Either ;
53
59
import io .openmanufacturing .sds .metamodel .Entity ;
54
60
import io .openmanufacturing .sds .metamodel .EntityInstance ;
55
- import io .openmanufacturing .sds .characteristic .Enumeration ;
56
61
import io .openmanufacturing .sds .metamodel .HasProperties ;
57
- import io .openmanufacturing .sds .constraint .LengthConstraint ;
62
+ import io .openmanufacturing .sds .metamodel .ModelElement ;
63
+ import io .openmanufacturing .sds .metamodel .NamedElement ;
58
64
import io .openmanufacturing .sds .metamodel .Property ;
59
- import io .openmanufacturing .sds .constraint .RangeConstraint ;
60
- import io .openmanufacturing .sds .constraint .RegularExpressionConstraint ;
61
65
import io .openmanufacturing .sds .metamodel .Scalar ;
62
66
import io .openmanufacturing .sds .metamodel .ScalarValue ;
63
- import io .openmanufacturing .sds .characteristic .Set ;
64
- import io .openmanufacturing .sds .characteristic .SingleEntity ;
65
- import io .openmanufacturing .sds .characteristic .SortedSet ;
66
- import io .openmanufacturing .sds .characteristic .Trait ;
67
67
import io .openmanufacturing .sds .metamodel .Type ;
68
68
import io .openmanufacturing .sds .metamodel .Value ;
69
69
import io .openmanufacturing .sds .metamodel .datatypes .LangString ;
@@ -192,18 +192,25 @@ private JsonNode toJsonNode() {
192
192
private final ObjectNode rootNode = factory .objectNode ();
193
193
private final Map <ModelElement , JsonNode > hasVisited = new HashMap <>();
194
194
195
+ private final boolean generateCommentForSeeAttributes ;
196
+
195
197
public AspectModelJsonSchemaVisitor ( final boolean useExtendedTypes , final Locale locale ) {
198
+ this ( useExtendedTypes , locale , false );
199
+ }
200
+
201
+ public AspectModelJsonSchemaVisitor ( final boolean useExtendedTypes ) {
202
+ this ( useExtendedTypes , Locale .ENGLISH );
203
+ }
204
+
205
+ public AspectModelJsonSchemaVisitor ( final boolean useExtendedTypes , final Locale locale , final boolean generateCommentForSeeAttributes ) {
196
206
if ( useExtendedTypes ) {
197
207
typeData = extendedTypeData ;
198
208
} else {
199
209
typeData = openApiTypeData ;
200
210
}
201
211
202
212
this .locale = locale ;
203
- }
204
-
205
- public AspectModelJsonSchemaVisitor ( final boolean useExtendedTypes ) {
206
- this ( useExtendedTypes , Locale .ENGLISH );
213
+ this .generateCommentForSeeAttributes = generateCommentForSeeAttributes ;
207
214
}
208
215
209
216
public ObjectNode getRootNode () {
@@ -420,7 +427,7 @@ public JsonNode visitEither( final Either either, final ObjectNode context ) {
420
427
properties .set ( "left" , either .getLeft ().accept ( this , properties ) );
421
428
properties .set ( "right" , either .getRight ().accept ( this , properties ) );
422
429
423
- return addDescription ( factory .objectNode (), either , locale )
430
+ return addDescription ( factory .objectNode (), either , locale )
424
431
.put ( "additionalProperties" , false )
425
432
.<ObjectNode > set ( "properties" , properties )
426
433
.set ( "oneOf" ,
@@ -431,11 +438,11 @@ public JsonNode visitEither( final Either either, final ObjectNode context ) {
431
438
432
439
@ Override
433
440
public JsonNode visitCharacteristic ( final Characteristic characteristic ,
434
- final ObjectNode context ) {
441
+ final ObjectNode context ) {
435
442
final JsonNode dataTypeNode = characteristic .getDataType ().map ( type -> type .accept ( this , context ) )
436
443
.orElseThrow ( () -> new DocumentGenerationException ( "Characteristic " + characteristic + " is missing a dataType" ) );
437
444
438
- return addDescription ( ( ObjectNode ) dataTypeNode , characteristic , locale );
445
+ return addDescription ( (ObjectNode ) dataTypeNode , characteristic , locale );
439
446
}
440
447
441
448
private void setNodeInRootSchema ( final JsonNode node , final String name ) {
@@ -584,7 +591,7 @@ private JsonNode createNodeForEnumEntityInstance( final EntityInstance entityIns
584
591
final ObjectNode enumEntityInstanceNode = factory .objectNode ();
585
592
final ArrayNode required = factory .arrayNode ();
586
593
final ObjectNode properties = factory .objectNode ();
587
- addDescription (enumEntityInstanceNode , entityInstance , locale );
594
+ addDescription ( enumEntityInstanceNode , entityInstance , locale );
588
595
enumEntityInstanceNode .put ( "type" , "object" );
589
596
590
597
final Entity entity = entityInstance .getEntityType ();
@@ -636,13 +643,20 @@ private JsonNode createNodeForEnumEntityPropertyInstance( final Property propert
636
643
return propertyInstanceNode ;
637
644
}
638
645
639
- private static ObjectNode addDescription ( final ObjectNode node ,
640
- final NamedElement describedElement , final Locale locale ) {
646
+ private ObjectNode addDescription ( final ObjectNode node , final NamedElement describedElement , final Locale locale ) {
641
647
final String description = describedElement .getDescription ( locale );
642
648
643
649
if ( !Strings .isNullOrEmpty ( description ) ) {
644
650
node .put ( "description" , description );
645
651
}
652
+
653
+ if ( generateCommentForSeeAttributes ) {
654
+ final String sees = String .join ( ", " , describedElement .getSee () );
655
+ if ( !Strings .isNullOrEmpty ( sees ) ) {
656
+ node .put ( "$comment" , "See: " + sees );
657
+ }
658
+ }
659
+
646
660
return node ;
647
661
}
648
662
}
0 commit comments