jsonschemafriend icon indicating copy to clipboard operation
jsonschemafriend copied to clipboard

Parsing composite schema object definition

Open gauamg opened this issue 2 years ago • 5 comments

Thank you very much for making this library available as open source. This is extremely useful and I am glad I chanced upon it before giving up. I am using this library to build a quality check tool that scans JSON schemas for compliance with certain design standards. There is one particular design pattern (composition) that seems to be slipping through the parser. Here is the schema snippet: "BaseAddress": { "type": "object", "properties": { "addressLineText": { "$ref": "#/definitions/String50" }, "addressUnitIdentifier": { "$ref": "#/definitions/String11" }, "cityName": { "$ref": "#/definitions/String35" }, "postalCode": { "$ref": "#/definitions/PostalCodeType" } } }, "ResidenceAddress": { "allOf": [ { "$ref": "#/definitions/BaseAddress" }, { "properties": { "stateCode": { "$ref": "#/definitions/ResidenceStateCodeType" } } } ], "required": [ "addressLineText", "cityName", "postalCode", "stateCode" ] }, While the BaseAddress object is being correctly read, the ResidenceAddress object is not being recognized. What am I missing?

Regards

gauamg avatar Apr 17 '23 13:04 gauamg

It's hard to say with that snippet; I'd need to know what you think should fail validation that isn't (or vice versa). Could I see the complete schema (paricularly as $ref works differently between different schema versions) and some example data?

jimblackler avatar Apr 17 '23 21:04 jimblackler

Thanks for responding so promptly. I guess, I did not explain my problem clearly enough. I am not trying to validate an instance JSON document - I am trying to parse a schema to look for certain features. Here is a more complete version of the schema:

So, I am loading the sub schemas and trying to iterate through them -

Map<URI, Schema> subSchemas = schema.getSubSchemas(); Set<URI> uris = subSchemas.keySet(); Iterator<URI> itr1 = uris.iterator(); while (itr1.hasNext()) { ...... Schema s = subSchemas.get(key); .. s.getExplicitTypes()....... }

What I am seeing is that for all the sub schemas below, barring the composite ones - "ResidenceAddress" and "SubjectPropertyAddress" - the getExplicitTypes() call is returning "object" - which is correct, but for the two composite objects the value being returned is null. Am I not using the library correctly? What am I missing?

{ "$schema": "https://json-schema.org/draft-07/schema#", "title": "", "description": "", "type": "object", "properties": { "Application": { "type": "object", "description": "Application", "properties": { "Borrowers": { "$ref": "#/definitions/Borrowers" } } } }, "definitions": { "Borrower": { "type": "object", "properties": { "ResidenceAddress": { "$ref": "#/definitions/ResidenceAddress" } } }, "Borrowers": { "type": "array", "items": { "$ref": "#/definitions/Borrower" }, "minItems": 1, "maxItems": 2 }, "BaseAddress": { "type": "object", "properties": { "addressLineText": { "$ref": "#/definitions/String50" }, "addressUnitIdentifier": { "$ref": "#/definitions/String50" }, "cityName": { "$ref": "#/definitions/String50" }, "postalCode": { "$ref": "#/definitions/String50" } } }, "ResidenceAddress": { "allOf": [ { "$ref": "#/definitions/BaseAddress" }, { "properties": { "stateCode": { "$ref": "#/definitions/ResidenceStateCodeType" } } } ], "required": [ "addressLineText", "cityName", "postalCode", "stateCode" ] }, "SubjectPropertyAddress": { "allOf": [ { "$ref": "#/definitions/BaseAddress" }, { "properties": { "countyName": { "$ref": "#/definitions/String50" }, "stateCode": { "$ref": "#/definitions/SubjectPropertyStateCodeType" } } } ], "required": [ "stateCode" ] }, "String50": { "type": "string", "maxLength": 50 }, "ResidenceStateCodeType": { "type": "string", "enum": [ "AA", "BB" ] }, "SubjectPropertyStateCodeType": { "type": "string", "enum": [ "CC", "DD" ] } } } Thanks again for building this very useful library. Regards.

gauamg avatar Apr 18 '23 14:04 gauamg

Hi sorry I haven't had time to investigate this yet.

jimblackler avatar Apr 29 '23 15:04 jimblackler

No problem. Appreciate you getting back.

From: Jim Blackler @.> Sent: Saturday, April 29, 2023 11:56 AM To: jimblackler/jsonschemafriend @.> Cc: gauamg @.>; Author @.> Subject: Re: [jimblackler/jsonschemafriend] Parsing composite schema object definition (Issue #26)

Hi sorry I haven't had time to investigate this yet.

Reply to this email directly, view it on GitHubhttps://github.com/jimblackler/jsonschemafriend/issues/26#issuecomment-1528817805, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMR3RIRCGS6VH2HXUORCPV3XDU2YHANCNFSM6AAAAAAXBGZSBY. You are receiving this because you authored the thread.Message ID: @.@.>>

gauamg avatar Apr 29 '23 16:04 gauamg

@gauamg

for all the sub schemas below, barring the composite ones - "ResidenceAddress" and "SubjectPropertyAddress" - the getExplicitTypes() call is returning "object" - which is correct, but for the two composite objects the value being returned is null. Am I not using the library correctly? What am I missing?

You miss the "type": "object" definition in schema. scr_20231130T06_12_58

@jimblackler - issue can be closed

kool79 avatar Nov 30 '23 04:11 kool79