From 63518ad7f5268d026502a51cc02ab041bea5d30e Mon Sep 17 00:00:00 2001 From: Carles Arnal Date: Mon, 28 Oct 2024 09:47:11 +0100 Subject: [PATCH] Add manual example for json schema refs --- examples/json-maven-with-references/pom.xml | 142 ++++++++ .../common/jsd/FLIBusinessUnitBaseTypes.json | 59 ++++ .../schemas/common/jsd/FLIItemBaseTypes.json | 68 ++++ .../schemas/common/jsd/FLIMessageHeader.json | 96 ++++++ .../schemas/common/jsd/FLIServiceTypes.json | 308 ++++++++++++++++++ .../schemas/common/jsd/FLIStockTypes.json | 178 ++++++++++ .../schemas/out/jsd/FLIStockAdjustment.json | 100 ++++++ examples/pom.xml | 1 + .../dereference/JsonSchemaDereferencer.java | 7 + .../registry/maven/RegisterRegistryMojo.java | 86 +++-- 10 files changed, 1012 insertions(+), 33 deletions(-) create mode 100644 examples/json-maven-with-references/pom.xml create mode 100644 examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIBusinessUnitBaseTypes.json create mode 100644 examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIItemBaseTypes.json create mode 100644 examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIMessageHeader.json create mode 100644 examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIServiceTypes.json create mode 100644 examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIStockTypes.json create mode 100644 examples/json-maven-with-references/src/main/resources/schemas/out/jsd/FLIStockAdjustment.json diff --git a/examples/json-maven-with-references/pom.xml b/examples/json-maven-with-references/pom.xml new file mode 100644 index 0000000000..9048e6bb20 --- /dev/null +++ b/examples/json-maven-with-references/pom.xml @@ -0,0 +1,142 @@ + + + + apicurio-registry-examples + io.apicurio + 2.6.6-SNAPSHOT + + 4.0.0 + + apicurio-registry-examples-json-maven-with-references + jar + + + + + io.apicurio + apicurio-registry-maven-plugin + ${project.version} + + + register-artifact + + register + + process-test-resources + + http://localhost:8080/apis/registry/v2 + + + json-maven-with-references + stockAdjustment + 1.0.0 + JSON + + ${project.basedir}/src/main/resources/schemas/out/jsd/FLIStockAdjustment.json + + RETURN_OR_UPDATE + true + + + ../../common/jsd/FLIServiceTypes.json + json-maven-with-references + FLIServiceTypes + 1.0.0 + JSON + + ${project.basedir}/src/main/resources/schemas/common/jsd/FLIServiceTypes.json + + RETURN_OR_UPDATE + true + + + ../../common/jsd/FLIStockTypes.json + json-maven-with-references + FLIStockTypes + 1.0.0 + JSON + + ${project.basedir}/src/main/resources/schemas/common/jsd/FLIStockTypes.json + + RETURN_OR_UPDATE + true + + + ../../common/jsd/FLIItemBaseTypes.json + json-maven-with-references + FLIItemBaseTypes + 1.0.0 + JSON + + ${project.basedir}/src/main/resources/schemas/common/jsd/FLIItemBaseTypes.json + + RETURN_OR_UPDATE + true + + + ../../common/jsd/FLIBusinessUnitBaseTypes.json + json-maven-with-references + FLIBusinessUnitBaseTypes + 1.0.0 + JSON + + ${project.basedir}/src/main/resources/schemas/common/jsd/FLIBusinessUnitBaseTypes.json + + RETURN_OR_UPDATE + true + + + ../../common/jsd/FLIServiceTypes.json + json-maven-with-references + FLIServiceTypes + 1.0.0 + + + + + + + ../../common/jsd/FLIBusinessUnitBaseTypes.json + json-maven-with-references + FLIBusinessUnitBaseTypes + 1.0.0 + + + ../../common/jsd/FLIServiceTypes.json + json-maven-with-references + FLIServiceTypes + 1.0.0 + + + + + ../../common/jsd/FLIBusinessUnitBaseTypes.json + json-maven-with-references + FLIBusinessUnitBaseTypes + 1.0.0 + + + ../../common/jsd/FLIMessageHeader.json + json-maven-with-references + MsgHeaderType + 1.0.0 + JSON + + ${project.basedir}/src/main/resources/schemas/common/jsd/FLIMessageHeader.json + + RETURN_OR_UPDATE + true + + + + + + + + + + + + diff --git a/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIBusinessUnitBaseTypes.json b/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIBusinessUnitBaseTypes.json new file mode 100644 index 0000000000..c06746e7bb --- /dev/null +++ b/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIBusinessUnitBaseTypes.json @@ -0,0 +1,59 @@ +{ + "$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})" + }, + "BusinessUnitReferenceType": { + "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": "../../common/jsd/FLIServiceTypes.json#/$defs/positiveInteger4" + } + }, + "additionalProperties": false + } + }, + "anyOf": [ + { + "$ref": "#/$defs/BusinessUnitReferenceType" + }, + { + "$ref": "#/$defs/BusinessUnitAddressReferenceType" + } + ] +} diff --git a/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIItemBaseTypes.json b/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIItemBaseTypes.json new file mode 100644 index 0000000000..fe1d9ceb33 --- /dev/null +++ b/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIItemBaseTypes.json @@ -0,0 +1,68 @@ + +{ + "$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": "../../common/jsd/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" } + ] +} \ No newline at end of file diff --git a/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIMessageHeader.json b/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIMessageHeader.json new file mode 100644 index 0000000000..b5bafc391a --- /dev/null +++ b/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIMessageHeader.json @@ -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 +} \ No newline at end of file diff --git a/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIServiceTypes.json b/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIServiceTypes.json new file mode 100644 index 0000000000..34a7c26754 --- /dev/null +++ b/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIServiceTypes.json @@ -0,0 +1,308 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "FLIServiceTypes.json", + "$defs": { + "fliDate": { + "type": "string", + "format": "date" + }, + "fliDateTime": { + "type": "string", + "format": "date-time", + "pattern": "^(.{20})([0-9]{3})[+-]((2[0-3]|[01][0-9])[:]([0-5][0-9]))$" + }, + "positiveInteger": { + "type": "integer", + "minimum": 0 + }, + "positiveInteger4": { + "type": "integer", + "minimum": 0, + "maximum": 9999 + }, + "positiveIntegerMax100": { + "type": "integer", + "minimum": 0, + "maximum": 100 + }, + "integer2": { + "type": "integer", + "minimum": -99, + "maximum": 99 + }, + "integer3": { + "type": "integer", + "minimum": -999, + "maximum": 999 + }, + "integer4": { + "type": "integer", + "minimum": -9999, + "maximum": 9999 + }, + "integer6": { + "type": "integer", + "minimum": -999999, + "maximum": 999999 + }, + "integer11": { + "type": "integer", + "minimum": -99999999999, + "maximum": 99999999999 + }, + "decimal7-3": { + "type": "number", + "minimum": -9999.999, + "maximum": 9999.999, + "multipleOf": 0.001 + }, + "decimal9-2": { + "type": "number", + "minimum": -9999999.99, + "maximum": 9999999.99, + "multipleOf": 0.01 + }, + "decimal9-5": { + "type": "number", + "minimum": -9999.99999, + "maximum": 9999.99999, + "multipleOf": 0.00001 + }, + "decimal11-2": { + "type": "number", + "minimum": -999999999.99, + "maximum": 999999999.99, + "multipleOf": 0.01 + }, + "decimal15-5": { + "type": "number", + "minimum": -9999999999.99999, + "maximum": 9999999999.99999, + "multipleOf": 0.00001 + }, + "string1": { + "type": "string", + "maxLength": 1 + }, + "string2": { + "type": "string", + "maxLength": 2 + }, + "string4": { + "type": "string", + "maxLength": 4 + }, + "string8": { + "type": "string", + "maxLength": 8 + }, + "string10": { + "type": "string", + "maxLength": 10 + }, + "string24": { + "type": "string", + "maxLength": 24 + }, + "string35": { + "type": "string", + "maxLength": 35 + }, + "string36": { + "type": "string", + "maxLength": 36 + }, + "string40": { + "type": "string", + "maxLength": 40 + }, + "string50": { + "type": "string", + "maxLength": 50 + }, + "string70": { + "type": "string", + "maxLength": 70 + }, + "string100": { + "type": "string", + "maxLength": 100 + }, + "string160": { + "type": "string", + "maxLength": 160 + }, + "string500": { + "type": "string", + "maxLength": 500 + }, + "nonEmptyString4000": { + "type": "string", + "maxLength": 4000, + "minLength": 1 + }, + "nonEmptyString1000": { + "type": "string", + "maxLength": 1000, + "minLength": 1 + }, + "nonEmptyString500": { + "type": "string", + "maxLength": 500, + "minLength": 1 + }, + "nonEmptyString200": { + "type": "string", + "maxLength": 200, + "minLength": 1 + }, + "nonEmptyString160": { + "type": "string", + "maxLength": 160, + "minLength": 1 + }, + "nonEmptyString150": { + "type": "string", + "maxLength": 150, + "minLength": 1 + }, + "nonEmptyString100": { + "type": "string", + "maxLength": 100, + "minLength": 1 + }, + "nonEmptyString80": { + "type": "string", + "maxLength": 80, + "minLength": 1 + }, + "nonEmptyString70": { + "type": "string", + "maxLength": 70, + "minLength": 1 + }, + "nonEmptyString50": { + "type": "string", + "maxLength": 50, + "minLength": 1 + }, + "nonEmptyString40": { + "type": "string", + "maxLength": 40, + "minLength": 1 + }, + "nonEmptyString36": { + "type": "string", + "maxLength": 36, + "minLength": 1 + }, + "nonEmptyString35": { + "type": "string", + "maxLength": 35, + "minLength": 1 + }, + "nonEmptyString30": { + "type": "string", + "maxLength": 30, + "minLength": 1 + }, + "nonEmptyString25": { + "type": "string", + "maxLength": 25, + "minLength": 1 + }, + "nonEmptyString24": { + "type": "string", + "maxLength": 24, + "minLength": 1 + }, + "nonEmptyString20": { + "type": "string", + "maxLength": 20, + "minLength": 1 + }, + "nonEmptyString18": { + "type": "string", + "maxLength": 18, + "minLength": 1 + }, + "nonEmptyString15": { + "type": "string", + "maxLength": 15, + "minLength": 1 + }, + "nonEmptyString10": { + "type": "string", + "maxLength": 10, + "minLength": 1 + }, + "nonEmptyString8": { + "type": "string", + "maxLength": 8, + "minLength": 1 + }, + "nonEmptyString5": { + "type": "string", + "maxLength": 5, + "minLength": 1 + }, + "nonEmptyString4": { + "type": "string", + "maxLength": 4, + "minLength": 1 + }, + "nonEmptyString3": { + "type": "string", + "maxLength": 3, + "minLength": 1 + }, + "nonEmptyString2": { + "type": "string", + "maxLength": 2, + "minLength": 1 + }, + "nonEmptyString1": { + "type": "string", + "maxLength": 1, + "minLength": 1 + }, + "nonEmptyString": { + "type": "string", + "minLength": 1 + }, + "CountryCodeType": { + "type": "string", + "pattern": "(^[A-Z]{2}$)" + }, + "ServiceResponseType": { + "type": "object", + "properties": { + "ServiceName": { + "$ref": "#/$defs/nonEmptyString100" + }, + "MessageReference": { + "$ref": "#/$defs/nonEmptyString36" + }, + "ReturnCode": { + "$ref": "#/$defs/nonEmptyString4" + }, + "ErrorMessage": { + "$ref": "#/$defs/nonEmptyString100" + }, + "ErrorDetails": { + "$ref": "#/$defs/nonEmptyString500" + } + }, + "required": [ + "ServiceName", + "MessageReference", + "ReturnCode" + ], + "additionalProperties": false + } + }, + "type": "object", + "anyOf": [ + { "$ref": "#/$defs/ServiceResponseType" } + ] +} \ No newline at end of file diff --git a/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIStockTypes.json b/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIStockTypes.json new file mode 100644 index 0000000000..2a96918183 --- /dev/null +++ b/examples/json-maven-with-references/src/main/resources/schemas/common/jsd/FLIStockTypes.json @@ -0,0 +1,178 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "FLIStockTypes.json", + "type": "object", + "$defs": { + "LUStock": { + "description": "This object models the stock object.", + "type": "object", + "properties": { + "ItemReference": { + "$ref": "../../common/jsd/FLIItemBaseTypes.json#/$defs/ItemReferenceType" + }, + "SupplierReference": { + "$ref": "../../common/jsd/FLIBusinessUnitBaseTypes.json#/$defs/BusinessUnitReferenceType" + }, + "ItemDWPReference": { + "$ref": "../../common/jsd/FLIItemBaseTypes.json#/$defs/DWPReferenceType" + }, + "RegistrationDateTime": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/fliDateTime" + }, + "ProductionDate": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/fliDate" + }, + "StockLocationId": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/nonEmptyString30" + }, + "Quantity": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/decimal11-2" + }, + "UOMCodeQuantity": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/nonEmptyString10" + }, + "InboundConsignmentLineReference": { + "$ref": "#/$defs/ConsignmentLineReference" + }, + "CountryOfOrigin": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/string2" + }, + "TradeStatus": { + "$ref": "#/$defs/TradeStatus" + }, + "OrderReference": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/nonEmptyString24" + }, + "OrderType": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/nonEmptyString10" + }, + "BondedFlag": { + "type": "boolean" + }, + "LUStockStatus": { + "type": "array", + "items": { + "$ref": "#/$defs/LUStockStatus" + } + } + }, + "required": [ + "ItemReference", + "SupplierReference", + "ItemDWPReference", + "RegistrationDateTime", + "ProductionDate", + "StockLocationId", + "Quantity", + "UOMCodeQuantity", + "CountryOfOrigin", + "TradeStatus", + "BondedFlag" + ], + "additionalProperties": false + }, + "ConsignmentLineReference": { + "type": "object", + "properties": { + "ConsignmentId": { + "$ref": "#/$defs/ConsignmentId" + }, + "ConsignmentLineNumber": { + "$ref": "#/$defs/ConsignmentLineNumber" + } + }, + "required": [ + "ConsignmentId", + "ConsignmentLineNumber" + ], + "additionalProperties": false + }, + "TradeStatus": { + "type": "integer", + "enum": [ + 0, + 1, + 2 + ] + }, + "StockStatusSubCode": { + "type": "integer", + "minimum": 0, + "maximum": 99 + }, + "LUStockStatus": { + "type": "object", + "properties": { + "StockStatus": { + "type": "string" + }, + "StockStatusSubCode": + { + "$ref": "#/$defs/StockStatusSubCode" + } + }, + "required": [ + "StockStatus" + ], + "additionalProperties": false + }, + "ConsignmentId": { + "type": "object", + "properties": { + "CreatorReference": { + "$ref": "../../common/jsd/FLIBusinessUnitBaseTypes.json#/$defs/BusinessUnitReferenceType" + }, + "ConsignmentNumber": { + "type": "string", + "maxLength": 12, + "minLength": 1 + } + }, + "required": [ + "CreatorReference", + "ConsignmentNumber" + ], + "additionalProperties": false + }, + "ConsignmentLineNumber": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/positiveInteger" + }, + "orderSource": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/nonEmptyString10" + }, + "executableOrderId": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/nonEmptyString40" + }, + "executableOrderLineId": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/integer4" + }, + "OutBoundReferences": { + "type": "object", + "properties": { + "OutboundConsignmentLineReference": { + "$ref": "#/$defs/ConsignmentLineReference" + }, + "OrderSource": { + "$ref": "#/$defs/orderSource" + }, + "ExecutableOrderLineReference": { + "type": "object", + "properties": { + "ExecutableOrderId": { + "$ref": "#/$defs/executableOrderId" + }, + "ExecutableOrderLineId": { + "$ref": "#/$defs/executableOrderLineId" + } + }, + "required": [ + "ExecutableOrderId", + "ExecutableOrderLineId" + ], + "additionalProperties": false + } + }, + "additionalProperties": false + } + } +} diff --git a/examples/json-maven-with-references/src/main/resources/schemas/out/jsd/FLIStockAdjustment.json b/examples/json-maven-with-references/src/main/resources/schemas/out/jsd/FLIStockAdjustment.json new file mode 100644 index 0000000000..0090233520 --- /dev/null +++ b/examples/json-maven-with-references/src/main/resources/schemas/out/jsd/FLIStockAdjustment.json @@ -0,0 +1,100 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "FLIStockAdjustment.json", + "title": "Stock adjustment schema for GIS", + "description": "Schema for the validation of stock adjustment messages.", + "$defs": { + "LUStockAdjustment": { + "type": "object", + "properties": { + "LogId": { + "type": "integer" + }, + "TransactionType": { + "type": "string", + "maxLength": 3 + }, + "ReportDateTime": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/fliDateTime" + }, + "TransactionDateTime": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/fliDateTime" + }, + "AdjustmentQuantity": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/decimal11-2" + }, + "UOMCodeQuantity": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/nonEmptyString10" + }, + "ChangeNote": { + "$ref": "../../common/jsd/FLIServiceTypes.json#/$defs/nonEmptyString35" + }, + "OutBoundReferences": { + "$ref": "../../common/jsd/FLIStockTypes.json#/$defs/OutBoundReferences" + }, + "RuleIdentifier": { + "type": "integer" + }, + "SubCode": { + "$ref": "../../common/jsd/FLIStockTypes.json#/$defs/StockStatusSubCode" + } + }, + "required": [ + "LogId", + "TransactionType", + "ReportDateTime", + "TransactionDateTime", + "AdjustmentQuantity", + "UOMCodeQuantity" + ], + "additionalProperties": false + }, + "StockAdjustment": { + "type": "object", + "properties": { + "LogisticUnitReference": { + "$ref": "../../common/jsd/FLIBusinessUnitBaseTypes.json#/$defs/BusinessUnitReferenceType" + }, + "LUStock": { + "$ref": "../../common/jsd/FLIStockTypes.json#/$defs/LUStock" + }, + "LUStockAdjustment": { + "$ref": "#/$defs/LUStockAdjustment" + } + }, + "required": [ + "LogisticUnitReference", + "LUStock", + "LUStockAdjustment" + ], + "additionalProperties": false + } + }, + "type": "object", + "properties": { + "MsgHeader": { + "$ref": "../../common/jsd/FLIMessageHeader.json#/$defs/MsgHeaderType" + }, + "MsgBody": { + "type": "object", + "properties": { + "StockAdjustments": { + "type": "array", + "items": { + "$ref": "#/$defs/StockAdjustment" + }, + "minItems": 1 + } + }, + "required": [ + "StockAdjustments" + ], + "additionalProperties": false + } + }, + "required": [ + "MsgHeader", + "MsgBody" + ], + "additionalProperties": false +} diff --git a/examples/pom.xml b/examples/pom.xml index ffa8f1b55b..24f9b4998c 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -54,6 +54,7 @@ simple-validation serdes-with-references avro-maven-with-references + json-maven-with-references avro-maven-with-references-auto json-maven-with-references-auto protobuf-validation diff --git a/schema-util/json/src/main/java/io/apicurio/registry/content/dereference/JsonSchemaDereferencer.java b/schema-util/json/src/main/java/io/apicurio/registry/content/dereference/JsonSchemaDereferencer.java index 7a88d8e82e..8ce8bd6db4 100644 --- a/schema-util/json/src/main/java/io/apicurio/registry/content/dereference/JsonSchemaDereferencer.java +++ b/schema-util/json/src/main/java/io/apicurio/registry/content/dereference/JsonSchemaDereferencer.java @@ -140,6 +140,13 @@ private void rewriteInObject(ObjectNode node, Map resolvedRefere String $ref = node.get("$ref").asText(); if (resolvedReferenceUrls.containsKey($ref)) { node.put("$ref", resolvedReferenceUrls.get($ref)); + } else { + //The reference in the file might be using just a component, use just the resource for the lookup. + JsonPointerExternalReference externalReference = new JsonPointerExternalReference($ref); + if (resolvedReferenceUrls.containsKey(externalReference.getResource())) { + JsonPointerExternalReference rewrittenRef = new JsonPointerExternalReference(resolvedReferenceUrls.get(externalReference.getResource()), externalReference.getComponent()); + node.put("$ref", rewrittenRef.getFullReference()); + } } } Iterator fieldNames = node.fieldNames(); diff --git a/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/RegisterRegistryMojo.java b/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/RegisterRegistryMojo.java index 5e0b7751b1..55eb54bf42 100644 --- a/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/RegisterRegistryMojo.java +++ b/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/RegisterRegistryMojo.java @@ -17,6 +17,27 @@ package io.apicurio.registry.maven; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.protobuf.Descriptors.FileDescriptor; +import io.apicurio.registry.content.ContentHandle; +import io.apicurio.registry.content.refs.ExternalReference; +import io.apicurio.registry.content.refs.ReferenceFinder; +import io.apicurio.registry.maven.refs.IndexedResource; +import io.apicurio.registry.maven.refs.ReferenceIndex; +import io.apicurio.registry.rest.v2.beans.ArtifactMetaData; +import io.apicurio.registry.rest.v2.beans.ArtifactReference; +import io.apicurio.registry.rest.v2.beans.IfExists; +import io.apicurio.registry.types.ArtifactType; +import io.apicurio.registry.types.ContentTypes; +import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider; +import io.apicurio.registry.types.provider.DefaultArtifactTypeUtilProviderImpl; +import org.apache.avro.Schema; +import org.apache.commons.io.FileUtils; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -34,29 +55,6 @@ import java.util.Stack; import java.util.stream.Collectors; -import org.apache.avro.Schema; -import org.apache.commons.io.FileUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.protobuf.Descriptors.FileDescriptor; - -import io.apicurio.registry.content.ContentHandle; -import io.apicurio.registry.content.refs.ExternalReference; -import io.apicurio.registry.content.refs.ReferenceFinder; -import io.apicurio.registry.maven.refs.IndexedResource; -import io.apicurio.registry.maven.refs.ReferenceIndex; -import io.apicurio.registry.rest.v2.beans.ArtifactMetaData; -import io.apicurio.registry.rest.v2.beans.ArtifactReference; -import io.apicurio.registry.rest.v2.beans.IfExists; -import io.apicurio.registry.types.ArtifactType; -import io.apicurio.registry.types.ContentTypes; -import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider; -import io.apicurio.registry.types.provider.DefaultArtifactTypeUtilProviderImpl; - /** * Register artifacts against registry. * @@ -85,7 +83,8 @@ public class RegisterRegistryMojo extends AbstractRegistryMojo { protected void validate() throws MojoExecutionException { if (artifacts == null || artifacts.isEmpty()) { getLog().warn("No artifacts are configured for registration."); - } else { + } + else { int idx = 0; int errorCount = 0; for (RegisterArtifact artifact : artifacts) { @@ -100,7 +99,8 @@ protected void validate() throws MojoExecutionException { if (artifact.getFile() == null) { getLog().error(String.format("File is required when registering an artifact. Missing from artifacts[%s].", idx)); errorCount++; - } else if (!artifact.getFile().exists()) { + } + else if (!artifact.getFile().exists()) { getLog().error(String.format("Artifact file to register is configured but file does not exist: %s", artifact.getFile().getPath())); errorCount++; } @@ -133,18 +133,22 @@ protected void executeInternal() throws MojoExecutionException { Stack registrationStack = new Stack<>(); registerWithAutoRefs(artifact, index, registrationStack); - } else if (artifact.getAnalyzeDirectory() != null && artifact.getAnalyzeDirectory()) { //Auto register selected, we must figure out if the artifact has reference using the directory structure + } + else if (artifact.getAnalyzeDirectory() != null + && artifact.getAnalyzeDirectory()) { //Auto register selected, we must figure out if the artifact has reference using the directory structure registerDirectory(artifact); - } else { + } + else { List references = new ArrayList<>(); //First, we check if the artifact being processed has references defined if (hasReferences(artifact)) { - references = registerArtifactReferences(artifact.getReferences()); + references = processArtifactReferences(artifact.getReferences()); } registerArtifact(artifact, references); } - } catch (Exception e) { + } + catch (Exception e) { errorCount++; getLog().error(String.format("Exception while registering artifact [%s] / [%s]", groupId, artifactId), e); } @@ -193,7 +197,8 @@ private ArtifactMetaData registerWithAutoRefs(RegisterArtifact artifact, Referen try { ArtifactMetaData amd = registerWithAutoRefs(refArtifact, index, registrationStack); iresource.setRegistration(amd); - } catch (IOException e) { + } + catch (IOException e) { throw new RuntimeException(e); } } @@ -236,7 +241,22 @@ private void registerDirectory(RegisterArtifact artifact) throws IOException { private ArtifactMetaData registerArtifact(RegisterArtifact artifact, List references) throws FileNotFoundException { - return registerArtifact(artifact, new FileInputStream(artifact.getFile()), references); + if (artifact.getFile() != null) { + return registerArtifact(artifact, new FileInputStream(artifact.getFile()), references); + } + else { + return getArtifactMetadata(artifact); + } + } + + private ArtifactMetaData getArtifactMetadata(RegisterArtifact artifact) { + String groupId = artifact.getGroupId(); + String artifactId = artifact.getArtifactId(); + + ArtifactMetaData amd = this.getClient().getArtifactMetaData(groupId, artifactId); + getLog().info(String.format("Successfully processed artifact [%s] / [%s]. GlobalId is [%d]", groupId, artifactId, amd.getGlobalId())); + + return amd; } private ArtifactMetaData registerArtifact(RegisterArtifact artifact, InputStream artifactContent, List references) { @@ -268,14 +288,14 @@ private static boolean hasReferences(RegisterArtifact artifact) { return artifact.getReferences() != null && !artifact.getReferences().isEmpty(); } - private List registerArtifactReferences + private List processArtifactReferences (List referencedArtifacts) throws FileNotFoundException { List references = new ArrayList<>(); for (RegisterArtifactReference artifact : referencedArtifacts) { List nestedReferences = new ArrayList<>(); //First, we check if the artifact being processed has references defined, and register them if needed if (hasReferences(artifact)) { - nestedReferences = registerArtifactReferences(artifact.getReferences()); + nestedReferences = processArtifactReferences(artifact.getReferences()); } final ArtifactMetaData artifactMetaData = registerArtifact(artifact, nestedReferences); references.add(buildReferenceFromMetadata(artifactMetaData, artifact.getName()));