Skip to content

Commit

Permalink
feat: API1 and API3 separate schemas with new formats.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Czeladka committed Nov 11, 2024
1 parent 4a36b5f commit 7623c50
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class JsonSchemaMetadataChecker implements MetadataChecker {

private final ObjectMapper objectMapper;

@Value("classpath:lob_blockchain_transaction_metadata_schema.json")
@Value("classpath:api1_lob_blockchain_transaction_metadata_schema.json")
@Setter
protected Resource metatdataSchemaResource;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "Individual Transactions Schema",
"definitions": {
"countryCodePattern": {
"type": "string",
Expand Down Expand Up @@ -54,7 +55,11 @@
},
"required": ["country_code", "name", "tax_id_number", "id", "currency_id"]
},
"txs": {
"type": {
"type": "string",
"enum": ["INDIVIDUAL_TRANSACTIONS"]
},
"data": {
"type": "array",
"items": {
"type": "object",
Expand Down Expand Up @@ -193,5 +198,5 @@
}
}
},
"required": ["metadata", "org", "txs"]
"required": ["metadata", "org", "type", "data"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "Report Schema",
"definitions": {
"countryCodePattern": {
"type": "string",
"pattern": "^[A-Z]{2}$"
},
"currencyIdPattern": {
"type": "string",
"pattern": "^ISO_4217:[A-Z]{3}$|^ISO_24165:[A-Z0-9]+(:[A-Z0-9]+)?$"
},
"bigDecimalPattern": {
"type": "string",
"pattern": "^[+-]?[0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?$"
}
},
"properties": {
"metadata": {
"type": "object",
"properties": {
"creation_slot": {
"type": "integer",
"minimum": 0
},
"format": {
"type": "string"
}
},
"required": ["creation_slot", "format"]
},
"org": {
"type": "object",
"properties": {
"country_code": {
"$ref": "#/definitions/countryCodePattern"
},
"name": {
"type": "string"
},
"tax_id_number": {
"type": "string"
},
"id": {
"type": "string"
},
"currency_id": {
"$ref": "#/definitions/currencyIdPattern"
}
},
"required": ["country_code", "name", "tax_id_number", "id", "currency_id"]
},
"type": {
"type": "string",
"enum": ["REPORT"]
},
"subType": {
"type": "string",
"enum": ["INCOME_STATEMENT", "BALANCE_SHEET"]
},
"interval": {
"type": "string",
"enum": ["YEAR", "MONTH", "QUARTER"]
},
"period": {
"type": ["integer", "null"],
"minimum": 1,
"maximum": 12
},
"year": {
"type": "string",
"pattern": "^[0-9]{4}$"
},
"mode": {
"type": "string",
"enum": ["USER", "SYSTEM"]
},
"data": {
"oneOf": [
{
"type": "object",
"properties": {
"revenues": {
"type": "object",
"properties": {
"other_income": {
"$ref": "#/definitions/bigDecimalPattern"
},
"build_of_long_term_provision": {
"$ref": "#/definitions/bigDecimalPattern"
}
}
},
"cogs": {
"type": "object",
"properties": {
"cost_of_providing_services": {
"$ref": "#/definitions/bigDecimalPattern"
}
}
},
"operating_expenses": {
"type": "object",
"properties": {
"personnel_expenses": {
"$ref": "#/definitions/bigDecimalPattern"
},
"general_and_administrative_expenses": {
"$ref": "#/definitions/bigDecimalPattern"
},
"depreciation_and_impairment_losses_on_tangible_assets": {
"$ref": "#/definitions/bigDecimalPattern"
},
"amortization_on_intangible_assets": {
"$ref": "#/definitions/bigDecimalPattern"
},
"rentExpenses": {
"$ref": "#/definitions/bigDecimalPattern"
}
}
},
"financial_income": {
"type": "object",
"properties": {
"finance_income": {
"$ref": "#/definitions/bigDecimalPattern"
},
"finance_expenses": {
"$ref": "#/definitions/bigDecimalPattern"
},
"realised_gains_on_sale_of_cryptocurrencies": {
"$ref": "#/definitions/bigDecimalPattern"
},
"staking_rewards_income": {
"$ref": "#/definitions/bigDecimalPattern"
},
"net_income_options_sale": {
"$ref": "#/definitions/bigDecimalPattern"
}
}
},
"extraordinary_income": {
"type": "object",
"properties": {
"extraordinary_expenses": {
"$ref": "#/definitions/bigDecimalPattern"
}
}
},
"tax_expenses": {
"type": "object",
"properties": {
"income_tax_expense": {
"$ref": "#/definitions/bigDecimalPattern"
}
}
}
},
"required": ["revenues", "cogs", "operating_expenses", "financial_income", "extraordinary_income", "tax_expenses"]
},
{
"type": "object",
"properties": {
"assets": {
"type": "object",
"properties": {
"non_current_assets": {
"type": "object",
"properties": {
"property_plant_equipment": {
"$ref": "#/definitions/bigDecimalPattern"
},
"intangible_assets": {
"$ref": "#/definitions/bigDecimalPattern"
},
"investments": {
"$ref": "#/definitions/bigDecimalPattern"
},
"financial_assets": {
"$ref": "#/definitions/bigDecimalPattern"
}
}
},
"current_assets": {
"type": "object",
"properties": {
"prepayments_and_other_short_term_assets": {
"$ref": "#/definitions/bigDecimalPattern"
},
"other_receivables": {
"$ref": "#/definitions/bigDecimalPattern"
},
"crypto_assets": {
"$ref": "#/definitions/bigDecimalPattern"
},
"cash_and_cash_equivalents": {
"$ref": "#/definitions/bigDecimalPattern"
}
}
}
}
},
"liabilities": {
"type": "object",
"properties": {
"non_current_liabilities": {
"type": "object",
"properties": {
"provisions": {
"$ref": "#/definitions/bigDecimalPattern"
}
}
},
"current_liabilities": {
"type": "object",
"properties": {
"trade_accounts_payables": {
"$ref": "#/definitions/bigDecimalPattern"
},
"other_current_liabilities": {
"$ref": "#/definitions/bigDecimalPattern"
},
"accruals_and_short_term_provisions": {
"$ref": "#/definitions/bigDecimalPattern"
}
}
}
}
},
"capital": {
"type": "object",
"properties": {
"capital": {
"$ref": "#/definitions/bigDecimalPattern"
},
"retained_earnings": {
"$ref": "#/definitions/bigDecimalPattern"
}
}
}
},
"required": ["assets", "liabilities", "capital"]
}
]
}
},
"required": ["metadata", "org", "type", "subType", "data", "interval", "year", "mode"],
"allOf": [
{
"if": {
"properties": { "interval": { "const": "YEAR" } }
},
"then": {
"not": { "required": ["period"] }
}
},
{
"if": {
"properties": { "interval": { "enum": ["MONTH", "QUARTER"] } }
},
"then": {
"required": ["period"]
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,72 @@

public class JsonSchemaMetadataCheckerTest {

private JsonSchemaMetadataChecker jsonSchemaMetadataChecker;
private JsonSchemaMetadataChecker api1JsonSchemaMetadataChecker;
private JsonSchemaMetadataChecker api3JsonSchemaMetadataChecker;

@BeforeEach
public void setUp() {
val objectMapper = new ObjectMapper();
val schemaResource = new ClassPathResource("lob_blockchain_transaction_metadata_schema.json");
jsonSchemaMetadataChecker = new JsonSchemaMetadataChecker(objectMapper);
jsonSchemaMetadataChecker.setMetatdataSchemaResource(schemaResource);
jsonSchemaMetadataChecker.setEnableChecker(true);
jsonSchemaMetadataChecker.init();
val api1SchemaResource = new ClassPathResource("api1_lob_blockchain_transaction_metadata_schema.json");
val api3SchemaResource = new ClassPathResource("api3_lob_blockchain_transaction_metadata_schema.json");

api1JsonSchemaMetadataChecker = new JsonSchemaMetadataChecker(objectMapper);
api1JsonSchemaMetadataChecker.setMetatdataSchemaResource(api1SchemaResource);
api1JsonSchemaMetadataChecker.setEnableChecker(true);
api1JsonSchemaMetadataChecker.init();

api3JsonSchemaMetadataChecker = new JsonSchemaMetadataChecker(objectMapper);
api3JsonSchemaMetadataChecker.setMetatdataSchemaResource(api3SchemaResource);
api3JsonSchemaMetadataChecker.setEnableChecker(true);
api3JsonSchemaMetadataChecker.init();
}

@Test
public void testCheckTransactionMetadata_Valid() throws IOException {
public void testAPI1CheckTransactionMetadata_Valid() throws IOException {
// Load valid JSON from test/resources
val validJson = Files.readString(Path.of("src/test/resources/test_transactions_valid.json"));
val validJson = Files.readString(Path.of("src/test/resources/api1_test_transactions_valid.json"));

// Check metadata
val result = jsonSchemaMetadataChecker.checkTransactionMetadata(validJson);
val result = api1JsonSchemaMetadataChecker.checkTransactionMetadata(validJson);

// Assert that the validation passes
assertThat(result).isTrue();
}

@Test
public void testCheckTransactionMetadata_Invalid() throws IOException {
public void testAPI1CheckTransactionMetadata_Invalid() throws IOException {
// Load invalid JSON from test/resources
val invalidJson = Files.readString(Path.of("src/test/resources/test_transactions_invalid.json"));
val invalidJson = Files.readString(Path.of("src/test/resources/api1_test_transactions_invalid.json"));

// Check metadata
val result = jsonSchemaMetadataChecker.checkTransactionMetadata(invalidJson);
val result = api1JsonSchemaMetadataChecker.checkTransactionMetadata(invalidJson);

// Assert that the validation fails
assertThat(result).isFalse();
}

@Test
public void testAPI3CheckTransactionMetadata_ValidBalanceSheet() throws IOException {
// Load valid JSON from test/resources
val validJson = Files.readString(Path.of("src/test/resources/api3_test_transactions_valid_bs.json"));

// Check metadata
val result = api3JsonSchemaMetadataChecker.checkTransactionMetadata(validJson);

// Assert that the validation passes
assertThat(result).isTrue();
}

@Test
public void testAPI3CheckTransactionMetadata_IncomeStatement() throws IOException {
// Load invalid JSON from test/resources
val invalidJson = Files.readString(Path.of("src/test/resources/api3_test_transactions_valid_is.json"));

// Check metadata
val result = api3JsonSchemaMetadataChecker.checkTransactionMetadata(invalidJson);

// Assert that the validation passes
assertThat(result).isTrue();
}

}
Loading

0 comments on commit 7623c50

Please sign in to comment.