Skip to content

Commit

Permalink
Merge pull request #28 from Property-Data-Trust-Framework/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
Ed Molyneux authored Nov 25, 2022
2 parents a78d068 + e36fac0 commit 4741420
Show file tree
Hide file tree
Showing 10 changed files with 1,588 additions and 1,783 deletions.
20 changes: 8 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const ajv = new Ajv({
allErrors: true,
// schema contains additional baspiRef and RDSRef metadata which is not strictly valid
strictSchema: false,
discriminator: true,
});
// Adds date formats among other types to the validator.
addFormats(ajv);
Expand All @@ -45,18 +46,14 @@ const validator = ajv.compile(transactionSchema);

const getSubschema = (path) => {
const pathArray = path.split("/").slice(1);
if (pathArray.length < 1) {
return transactionSchema;
}

if (pathArray.length < 1) return transactionSchema;
return pathArray.reduce((schema, pathElement) => {
if (schema.type === "array") return schema.items;
if (schema.properties[pathElement]) return schema.properties[pathElement];
const dependencies = schema.dependencies;
if (dependencies) {
const discriminator = schema.discriminator?.propertyName;
if (discriminator) {
// only single dependency discriminator, oneOf keyword is supported
const dependencyDiscriminator = Object.keys(dependencies)[0];
const oneOfs = dependencies[dependencyDiscriminator].oneOf;
const oneOfs = schema.oneOf;
const matchingOneOf = oneOfs.find(
(oneOf) => oneOf["properties"][pathElement]
);
Expand Down Expand Up @@ -112,11 +109,10 @@ const getTitleAtPath = (schema, path, rootPath = path) => {
subSchema = schema.items;
return getTitleAtPath(subSchema, subPath, rootPath);
}
const dependencies = schema.dependencies;
if (dependencies) {
const discriminator = schema.discriminator?.propertyName;
if (discriminator) {
// only single dependency discriminator, oneOf keyword is supported
const dependencyDiscriminator = Object.keys(dependencies)[0];
const oneOfs = dependencies[dependencyDiscriminator].oneOf;
const oneOfs = schema.oneOf;
const matchingOneOf = oneOfs.find(
(oneOf) => oneOf["properties"][propertyName]
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pdtf/schemas",
"version": "0.10.8",
"version": "0.11.0-6",
"description": "Property Data Trust Framework Schemas and Utilities",
"main": "index.js",
"directories": {
Expand Down
53 changes: 10 additions & 43 deletions src/examples/exampleTransaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
},
"ownership": {
"ownershipType": "Leasehold",
"sharedOwnership": {
"isSharedOwnership": "Yes",
"sharedOwnershipPercentage": 25,
"sharedOwnershipRent": 225,
"sharedOwnershipRentFrequency": "Monthly"
},
"sharedOwnership": { "isSharedOwnership": "No" },
"startYearOfLease": 1900,
"lengthOfLeaseInYears": 999,
"currentGroundRent": 1750,
Expand Down Expand Up @@ -427,12 +422,14 @@
}
},
"additionalLegalInfo": {
"namesOfLegalOwners": [
{
"firstName": "Peter",
"lastName": "Hetherington-Smythe"
}
],
"legalOwners": {
"namesOfLegalOwners": [
{
"firstName": "Peter",
"lastName": "Hetherington-Smythe"
}
]
},
"sellersCapacity": { "capacity": "Legal Owner" },
"legalBoundaries": {
"left": "Seller",
Expand Down Expand Up @@ -490,37 +487,7 @@
"titlesToBeSold": [
{
"titleNumber": "HD221222",
"titleExtents": [
{
"type": "Feature",
"properties": {
"POLY_ID": 19851403,
"TITLE_NO": "HD221222",
"INSERT": "2016-02-05T13:36:55",
"UPDATE": "2016-02-05T13:36:55",
"REC_STATUS": "A"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-2.578781821932439, 51.48576411094672],
[-2.578669662492341, 51.48572105544199],
[-2.5786421470447154, 51.48570905261714],
[-2.5785524174118404, 51.48567442829361],
[-2.5785328794340825, 51.48566688186638],
[-2.5785279074169107, 51.4856723013566],
[-2.5784923376884157, 51.48570664492474],
[-2.5785118756765826, 51.48571419135863],
[-2.578603776881019, 51.48574970415372],
[-2.578629846557485, 51.48576126454427],
[-2.578738400129546, 51.48580388830907],
[-2.578781821932439, 51.48576411094672]
]
]
}
}
],
"titleExtents": "{'type':'Polygon','coordinates':[[[-2.5787833768108985,51.48576273335823],[-2.578739952913823,51.48580251052463],[-2.578631396439736,51.48575988696783],[-2.578605326085179,51.48574832663401],[-2.578513422397467,51.48571281401381],[-2.578493883879733,51.48570526761721],[-2.578529455342914,51.48567092421916],[-2.578534427612858,51.485665504755744],[-2.578553966121065,51.485673051145575],[-2.5786436981835235,51.48570767529821],[-2.578671214351269,51.48571967806404],[-2.5787833768108985,51.48576273335823]]]}",
"registerExtract": {
"OCSummaryData": {
"Title": {
Expand Down
Loading

0 comments on commit 4741420

Please sign in to comment.