Skip to content

Commit 6cfa0de

Browse files
authoredNov 12, 2024
Pass reference rewrites between recursive calls (#5487)
* Pass reference rewrites between recursive calls * Fix url
1 parent 417dde2 commit 6cfa0de

File tree

9 files changed

+885
-4
lines changed

9 files changed

+885
-4
lines changed
 

‎app/src/main/java/io/apicurio/registry/storage/impl/sql/RegistryContentUtils.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static RewrittenContentHolder recursivelyResolveReferencesWithContext(Typ
7272
// First we resolve all the references tree, re-writing the nested contents to use the artifact
7373
// version coordinates instead of the reference name.
7474
return resolveReferencesWithContext(mainContent, mainContentType, resolvedReferences, references,
75-
loader);
75+
loader, new HashMap<>());
7676
}
7777
}
7878

@@ -84,8 +84,8 @@ public static RewrittenContentHolder recursivelyResolveReferencesWithContext(Typ
8484
*/
8585
private static RewrittenContentHolder resolveReferencesWithContext(TypedContent mainContent,
8686
String schemaType, Map<String, TypedContent> partialRecursivelyResolvedReferences,
87-
List<ArtifactReferenceDto> references, Function<ArtifactReferenceDto, ContentWrapperDto> loader) {
88-
Map<String, String> referencesRewrites = new HashMap<>();
87+
List<ArtifactReferenceDto> references, Function<ArtifactReferenceDto, ContentWrapperDto> loader,
88+
Map<String, String> referencesRewrites) {
8989
if (references != null && !references.isEmpty()) {
9090
for (ArtifactReferenceDto reference : references) {
9191
if (reference.getArtifactId() == null || reference.getName() == null
@@ -112,7 +112,7 @@ private static RewrittenContentHolder resolveReferencesWithContext(TypedContent
112112
RewrittenContentHolder rewrittenContentHolder = resolveReferencesWithContext(
113113
TypedContent.create(nested.getContent(), nested.getArtifactType()),
114114
nested.getArtifactType(), partialRecursivelyResolvedReferences,
115-
nested.getReferences(), loader);
115+
nested.getReferences(), loader, referencesRewrites);
116116
referencesRewrites.put(refName, referenceCoordinates);
117117
TypedContent rewrittenContent = typeUtilProvider.getContentDereferencer()
118118
.rewriteReferences(rewrittenContentHolder.getRewrittenContent(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>io.apicurio</groupId>
6+
<artifactId>apicurio-registry-examples</artifactId>
7+
<version>3.0.4-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>apicurio-registry-examples-json-maven-with-references-auto</artifactId>
11+
<packaging>jar</packaging>
12+
13+
<properties>
14+
<projectRoot>${project.basedir}/../..</projectRoot>
15+
</properties>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>io.apicurio</groupId>
21+
<artifactId>apicurio-registry-maven-plugin</artifactId>
22+
<version>${project.version}</version>
23+
<executions>
24+
<execution>
25+
<id>register-artifact</id>
26+
<goals>
27+
<goal>register</goal>
28+
</goals>
29+
<phase>process-test-resources</phase>
30+
<configuration>
31+
<registryUrl>http://localhost:8080/apis/registry/v3</registryUrl>
32+
<artifacts>
33+
<artifact>
34+
<groupId>json-maven-with-references-auto</groupId>
35+
<artifactId>stockAdjustment</artifactId>
36+
<version>1.0.0</version>
37+
<artifactType>JSON</artifactType>
38+
<file>${project.basedir}/src/main/resources/schemas/FLIStockAdjustment.json</file>
39+
<ifExists>FIND_OR_CREATE_VERSION</ifExists>
40+
<canonicalize>true</canonicalize>
41+
<analyzeDirectory>true</analyzeDirectory>
42+
<autoRefs>true</autoRefs>
43+
</artifact>
44+
</artifacts>
45+
<existingReferences/>
46+
</configuration>
47+
</execution>
48+
</executions>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "FLIBusinessUnitBaseTypes.json",
4+
"type": "object",
5+
"$defs": {
6+
"buCodeType": {
7+
"type": "string",
8+
"pattern": "(^[0-9A-Z]{3,5})|AP"
9+
},
10+
"buTypeType": {
11+
"type": "string",
12+
"pattern": "(^[A-Z]{2,3})"
13+
},
14+
"buNumber":{
15+
"type": "string",
16+
"pattern": "(^[A-Z]{2,3})"
17+
},
18+
"BusinessUnitReferenceType": {
19+
"type": "object",
20+
"required": [
21+
"BusinessUnitCode",
22+
"BusinessUnitType"
23+
],
24+
"properties": {
25+
"BusinessUnitCode": {
26+
"$ref": "#/$defs/buCodeType"
27+
},
28+
"BusinessUnitType": {
29+
"$ref": "#/$defs/buTypeType"
30+
}
31+
},
32+
"additionalProperties": false
33+
},
34+
"BusinessUnitReferenceDuplicateType": {
35+
"type": "object",
36+
"required": [
37+
"BusinessUnitCode",
38+
"BusinessUnitType"
39+
],
40+
"properties": {
41+
"BusinessUnitCode": {
42+
"$ref": "#/$defs/buCodeType"
43+
},
44+
"BusinessUnitType": {
45+
"$ref": "#/$defs/buTypeType"
46+
}
47+
},
48+
"additionalProperties": false
49+
},
50+
"BusinessUnitAddressReferenceType": {
51+
"type": "object",
52+
"required": [
53+
"BusinessUnitCode",
54+
"BusinessUnitType",
55+
"BusinessUnitSequence"
56+
],
57+
"properties": {
58+
"BusinessUnitCode": {
59+
"$ref": "#/$defs/buCodeType"
60+
},
61+
"BusinessUnitType": {
62+
"$ref": "#/$defs/buTypeType"
63+
},
64+
"BusinessUnitSequence": {
65+
"$ref": "FLIServiceTypes.json#/$defs/positiveInteger4"
66+
}
67+
},
68+
"additionalProperties": false
69+
}
70+
},
71+
"anyOf": [
72+
{
73+
"$ref": "#/$defs/BusinessUnitReferenceType"
74+
},
75+
{
76+
"$ref": "#/$defs/BusinessUnitAddressReferenceType"
77+
}
78+
]
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "FLIItemBaseTypes.json",
4+
"$defs": {
5+
"ItemReferenceType": {
6+
"type": "object",
7+
"properties": {
8+
"ItemNumber": {
9+
"type": "string",
10+
"minLength": 1,
11+
"maxLength": 15
12+
},
13+
"ItemType": {
14+
"type": "string",
15+
"enum": [
16+
"ADS",
17+
"ART",
18+
"CCI",
19+
"HM",
20+
"OAD",
21+
"SGR",
22+
"SPR"
23+
]
24+
}
25+
},
26+
"required": [
27+
"ItemNumber",
28+
"ItemType"
29+
],
30+
"additionalProperties": false
31+
},
32+
"ItemSKUType": {
33+
"type": "string",
34+
"minLength": 1,
35+
"maxLength": 20
36+
},
37+
"DWPReferenceType": {
38+
"type": "object",
39+
"properties": {
40+
"ItemReference": {
41+
"$ref": "#/$defs/ItemReferenceType"
42+
},
43+
"ItemSupplierReference": {
44+
"$ref": "FLIBusinessUnitBaseTypes.json#/$defs/BusinessUnitReferenceType"
45+
},
46+
"DWPNumber": { "type": "integer" },
47+
"DWPEdition": { "type": "integer" },
48+
"DWPFromPackagingDate": {
49+
"type": "string",
50+
"format": "date"
51+
}
52+
},
53+
"required": [
54+
"ItemReference",
55+
"ItemSupplierReference",
56+
"DWPNumber",
57+
"DWPEdition",
58+
"DWPFromPackagingDate"
59+
],
60+
"additionalProperties": false
61+
}
62+
},
63+
"anyOf": [
64+
{ "$ref": "#/$defs/ItemReferenceType" },
65+
{ "$ref": "#/$defs/DWPReferenceType" }
66+
]
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "FLIMessageHeader.json",
4+
"$defs": {
5+
"MsgHeaderType": {
6+
"type": "object",
7+
"properties": {
8+
"MsgName": {
9+
"type": "string",
10+
"minLength": 1,
11+
"maxLength": 36
12+
},
13+
"MsgVersNo": {
14+
"type": "string",
15+
"minLength": 1,
16+
"maxLength": 10
17+
},
18+
"MsgDateTime": {
19+
"type": "string",
20+
"format": "date-time",
21+
"pattern": "^(.{20})([0-9]{3})[+-]((2[0-3]|[01][0-9])[:]([0-5][0-9]))$"
22+
},
23+
"MsgReference": {
24+
"type": "string",
25+
"minLength": 1,
26+
"maxLength": 36
27+
},
28+
"SendingSystem": {
29+
"type": "string",
30+
"minLength": 1,
31+
"maxLength": 20
32+
},
33+
"SendingUnit": {
34+
"type": "object",
35+
"properties": {
36+
"BUCode": {
37+
"type": "string",
38+
"minLength": 3,
39+
"maxLength": 5
40+
},
41+
"BUType": {
42+
"type": "string",
43+
"minLength": 2,
44+
"maxLength": 3
45+
}
46+
},
47+
"required": [
48+
"BUCode",
49+
"BUType"
50+
],
51+
"additionalProperties": false
52+
},
53+
"LogicalRoutingIdentifier": {
54+
"type": "object",
55+
"properties": {
56+
"SourceCode": {
57+
"type": "string",
58+
"minLength": 1
59+
},
60+
"SourceType": {
61+
"type": "string",
62+
"minLength": 1
63+
},
64+
"SourceLookupType": {
65+
"type": "string",
66+
"minLength": 1
67+
}
68+
},
69+
"required": [
70+
"SourceCode",
71+
"SourceType"
72+
],
73+
"additionalProperties": false
74+
}
75+
},
76+
"additionalProperties": false,
77+
"required": [
78+
"MsgName",
79+
"MsgVersNo",
80+
"MsgDateTime",
81+
"MsgReference",
82+
"SendingSystem"
83+
]
84+
}
85+
},
86+
"type": "object",
87+
"properties": {
88+
"MsgHeader": {
89+
"$ref": "#/$defs/MsgHeaderType"
90+
}
91+
},
92+
"required": [
93+
"MsgHeader"
94+
],
95+
"additionalProperties": false
96+
}

0 commit comments

Comments
 (0)
Please sign in to comment.