Skip to content

Commit

Permalink
Pass reference rewrites between ecursive calls
Browse files Browse the repository at this point in the history
  • Loading branch information
carlesarnal committed Nov 7, 2024
1 parent 76401cb commit faf9304
Show file tree
Hide file tree
Showing 9 changed files with 885 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static RewrittenContentHolder recursivelyResolveReferencesWithContext(Typ
// First we resolve all the references tree, re-writing the nested contents to use the artifact
// version coordinates instead of the reference name.
return resolveReferencesWithContext(mainContent, mainContentType, resolvedReferences, references,
loader);
loader, new HashMap<>());
}
}

Expand All @@ -84,8 +84,8 @@ public static RewrittenContentHolder recursivelyResolveReferencesWithContext(Typ
*/
private static RewrittenContentHolder resolveReferencesWithContext(TypedContent mainContent,
String schemaType, Map<String, TypedContent> partialRecursivelyResolvedReferences,
List<ArtifactReferenceDto> references, Function<ArtifactReferenceDto, ContentWrapperDto> loader) {
Map<String, String> referencesRewrites = new HashMap<>();
List<ArtifactReferenceDto> references, Function<ArtifactReferenceDto, ContentWrapperDto> loader,
Map<String, String> referencesRewrites) {
if (references != null && !references.isEmpty()) {
for (ArtifactReferenceDto reference : references) {
if (reference.getArtifactId() == null || reference.getName() == null
Expand All @@ -112,7 +112,7 @@ private static RewrittenContentHolder resolveReferencesWithContext(TypedContent
RewrittenContentHolder rewrittenContentHolder = resolveReferencesWithContext(
TypedContent.create(nested.getContent(), nested.getArtifactType()),
nested.getArtifactType(), partialRecursivelyResolvedReferences,
nested.getReferences(), loader);
nested.getReferences(), loader, referencesRewrites);
referencesRewrites.put(refName, referenceCoordinates);
TypedContent rewrittenContent = typeUtilProvider.getContentDereferencer()
.rewriteReferences(rewrittenContentHolder.getRewrittenContent(),
Expand Down
52 changes: 52 additions & 0 deletions examples/json-maven-with-references-auto/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.apicurio</groupId>
<artifactId>apicurio-registry-examples</artifactId>
<version>3.0.4-SNAPSHOT</version>
</parent>

<artifactId>apicurio-registry-examples-json-maven-with-references-auto</artifactId>
<packaging>jar</packaging>

<properties>
<projectRoot>${project.basedir}/../..</projectRoot>
</properties>

<build>
<plugins>
<plugin>
<groupId>io.apicurio</groupId>
<artifactId>apicurio-registry-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>register-artifact</id>
<goals>
<goal>register</goal>
</goals>
<phase>process-test-resources</phase>
<configuration>
<registryUrl>http://localhost:8080/apis/registry/v2</registryUrl>
<artifacts>
<artifact>
<groupId>json-maven-with-references-auto</groupId>
<artifactId>stockAdjustment</artifactId>
<version>1.0.0</version>
<type>JSON</type>
<file>${project.basedir}/src/main/resources/schemas/FLIStockAdjustment.json</file>
<ifExists>RETURN_OR_UPDATE</ifExists>
<canonicalize>true</canonicalize>
<analyzeDirectory>true</analyzeDirectory>
<autoRefs>true</autoRefs>
</artifact>
</artifacts>
<existingReferences/>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "FLIBusinessUnitBaseTypes.json",
"type": "object",
"$defs": {
"buCodeType": {
"type": "string",
"pattern": "(^[0-9A-Z]{3,5})|AP"
},
"buTypeType": {
"type": "string",
"pattern": "(^[A-Z]{2,3})"
},
"buNumber":{
"type": "string",
"pattern": "(^[A-Z]{2,3})"
},
"BusinessUnitReferenceType": {
"type": "object",
"required": [
"BusinessUnitCode",
"BusinessUnitType"
],
"properties": {
"BusinessUnitCode": {
"$ref": "#/$defs/buCodeType"
},
"BusinessUnitType": {
"$ref": "#/$defs/buTypeType"
}
},
"additionalProperties": false
},
"BusinessUnitReferenceDuplicateType": {
"type": "object",
"required": [
"BusinessUnitCode",
"BusinessUnitType"
],
"properties": {
"BusinessUnitCode": {
"$ref": "#/$defs/buCodeType"
},
"BusinessUnitType": {
"$ref": "#/$defs/buTypeType"
}
},
"additionalProperties": false
},
"BusinessUnitAddressReferenceType": {
"type": "object",
"required": [
"BusinessUnitCode",
"BusinessUnitType",
"BusinessUnitSequence"
],
"properties": {
"BusinessUnitCode": {
"$ref": "#/$defs/buCodeType"
},
"BusinessUnitType": {
"$ref": "#/$defs/buTypeType"
},
"BusinessUnitSequence": {
"$ref": "FLIServiceTypes.json#/$defs/positiveInteger4"
}
},
"additionalProperties": false
}
},
"anyOf": [
{
"$ref": "#/$defs/BusinessUnitReferenceType"
},
{
"$ref": "#/$defs/BusinessUnitAddressReferenceType"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "FLIItemBaseTypes.json",
"$defs": {
"ItemReferenceType": {
"type": "object",
"properties": {
"ItemNumber": {
"type": "string",
"minLength": 1,
"maxLength": 15
},
"ItemType": {
"type": "string",
"enum": [
"ADS",
"ART",
"CCI",
"HM",
"OAD",
"SGR",
"SPR"
]
}
},
"required": [
"ItemNumber",
"ItemType"
],
"additionalProperties": false
},
"ItemSKUType": {
"type": "string",
"minLength": 1,
"maxLength": 20
},
"DWPReferenceType": {
"type": "object",
"properties": {
"ItemReference": {
"$ref": "#/$defs/ItemReferenceType"
},
"ItemSupplierReference": {
"$ref": "FLIBusinessUnitBaseTypes.json#/$defs/BusinessUnitReferenceType"
},
"DWPNumber": { "type": "integer" },
"DWPEdition": { "type": "integer" },
"DWPFromPackagingDate": {
"type": "string",
"format": "date"
}
},
"required": [
"ItemReference",
"ItemSupplierReference",
"DWPNumber",
"DWPEdition",
"DWPFromPackagingDate"
],
"additionalProperties": false
}
},
"anyOf": [
{ "$ref": "#/$defs/ItemReferenceType" },
{ "$ref": "#/$defs/DWPReferenceType" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "FLIMessageHeader.json",
"$defs": {
"MsgHeaderType": {
"type": "object",
"properties": {
"MsgName": {
"type": "string",
"minLength": 1,
"maxLength": 36
},
"MsgVersNo": {
"type": "string",
"minLength": 1,
"maxLength": 10
},
"MsgDateTime": {
"type": "string",
"format": "date-time",
"pattern": "^(.{20})([0-9]{3})[+-]((2[0-3]|[01][0-9])[:]([0-5][0-9]))$"
},
"MsgReference": {
"type": "string",
"minLength": 1,
"maxLength": 36
},
"SendingSystem": {
"type": "string",
"minLength": 1,
"maxLength": 20
},
"SendingUnit": {
"type": "object",
"properties": {
"BUCode": {
"type": "string",
"minLength": 3,
"maxLength": 5
},
"BUType": {
"type": "string",
"minLength": 2,
"maxLength": 3
}
},
"required": [
"BUCode",
"BUType"
],
"additionalProperties": false
},
"LogicalRoutingIdentifier": {
"type": "object",
"properties": {
"SourceCode": {
"type": "string",
"minLength": 1
},
"SourceType": {
"type": "string",
"minLength": 1
},
"SourceLookupType": {
"type": "string",
"minLength": 1
}
},
"required": [
"SourceCode",
"SourceType"
],
"additionalProperties": false
}
},
"additionalProperties": false,
"required": [
"MsgName",
"MsgVersNo",
"MsgDateTime",
"MsgReference",
"SendingSystem"
]
}
},
"type": "object",
"properties": {
"MsgHeader": {
"$ref": "#/$defs/MsgHeaderType"
}
},
"required": [
"MsgHeader"
],
"additionalProperties": false
}
Loading

0 comments on commit faf9304

Please sign in to comment.