@@ -418,11 +418,21 @@ ClassMethod GetContentArray(
418418ClassMethod SchemaToContents (
419419 schema As %DynamicObject ,
420420 Output pContents ) As %Status
421+ {
422+ // Call internal method with root schema tracking
423+ Return ##class (IOP.Message ).SchemaToContentsInternal (schema , schema , .pContents )
424+ }
425+
426+ /// Internal method - same as SchemaToContents but tracks root schema for $defs resolution
427+ ClassMethod SchemaToContentsInternal (
428+ schema As %DynamicObject ,
429+ rootSchema As %DynamicObject ,
430+ Output pContents ) As %Status
421431{
422432 Set tSC = $$$OK
423433 Try {
424434 Set idx = 0
425- Do ..ProcessProperties (schema .properties , .idx , .pContents , schema )
435+ Do ..ProcessPropertiesInternal (schema .properties , .idx , .pContents , rootSchema )
426436 }
427437 Catch ex {
428438 Set tSC = ex .AsStatus ()
@@ -444,6 +454,63 @@ ClassMethod ProcessProperties(
444454 Return $$$OK
445455}
446456
457+ ClassMethod ProcessPropertiesInternal (
458+ properties As %DynamicObject ,
459+ ByRef idx As %Integer ,
460+ Output pContents ,
461+ rootSchema As %DynamicObject ) As %Status
462+ {
463+ Set iterator = properties .%GetIterator ()
464+ While iterator .%GetNext (.key , .value ) {
465+ Set idx = idx + 1
466+ Do ..HandlePropertyInternal (value , .key , idx , .pContents , rootSchema )
467+ }
468+ Return $$$OK
469+ }
470+
471+ ClassMethod HandlePropertyInternal (
472+ value As %DynamicObject ,
473+ ByRef key As %String ,
474+ idx As %Integer ,
475+ Output pContents ,
476+ rootSchema As %DynamicObject )
477+ {
478+ Set type = value .type
479+
480+ If (type = " string" ) || (type = " number" ) || (type = " boolean" ) {
481+ Do ..HandlePrimitiveType (type , idx , .pContents )
482+ }
483+ ElseIf type = " array" {
484+ Do ..HandleArrayTypeInternal (value , .key , idx , .pContents , rootSchema )
485+ }
486+ ElseIf type = " object" {
487+ Do ..HandleObjectType (value , idx , .pContents )
488+ }
489+ ElseIf $IsObject (value .allOf ) {
490+ Do ..HandleAllOfTypeInternal (value , key , idx , .pContents , rootSchema )
491+ }
492+ ElseIf value .%Get (" $ref" )'=" " {
493+ Set tDef = rootSchema ." $defs" .%Get ($Piece (value ." $ref" , " /" , *))
494+ // Check if it's an enum or an object
495+ If $IsObject (tDef .enum ) {
496+ // Handle enum - treat as string with enum values
497+ Do ..HandleEnumType (tDef , idx , .pContents )
498+ }
499+ Else {
500+ // Handle object type
501+ Do ..HandleObjectTypeInternal (tDef , idx , .pContents , rootSchema )
502+ }
503+ }
504+ Else {
505+ Set pContents (idx ," type" ) = type
506+ }
507+
508+ If type = " array" Set key = key _" ()"
509+ Set pContents = idx
510+ Set pContents (idx ," name" ) = key
511+ Set pContents (idx ," alias" ) = key
512+ }
513+
447514ClassMethod HandleProperty (
448515 value As %DynamicObject ,
449516 ByRef key As %String ,
@@ -467,7 +534,15 @@ ClassMethod HandleProperty(
467534 }
468535 ElseIf value .%Get (" $ref" )'=" " {
469536 Set tDef = schema ." $defs" .%Get ($Piece (value ." $ref" , " /" , *))
470- Do ..HandleObjectType (tDef , idx , .pContents )
537+ // Check if it's an enum or an object
538+ If $IsObject (tDef .enum ) {
539+ // Handle enum - treat as string with enum values
540+ Do ..HandleEnumType (tDef , idx , .pContents )
541+ }
542+ Else {
543+ // Handle object type
544+ Do ..HandleObjectType (tDef , idx , .pContents )
545+ }
471546 }
472547 Else {
473548 Set pContents (idx ," type" ) = type
@@ -502,6 +577,18 @@ ClassMethod HandleArrayType(
502577 Do ..HandleProperty (value .items , key , idx , .pContents , schema )
503578}
504579
580+ ClassMethod HandleArrayTypeInternal (
581+ value As %DynamicObject ,
582+ ByRef key As %String ,
583+ idx As %Integer ,
584+ Output pContents ,
585+ rootSchema As %DynamicObject )
586+ {
587+ Set pContents (idx ," type" ) = " ()"
588+ // Handle array as a Handle Property
589+ Do ..HandlePropertyInternal (value .items , key , idx , .pContents , rootSchema )
590+ }
591+
505592ClassMethod HandleObjectType (
506593 value As %DynamicObject ,
507594 idx As %Integer ,
@@ -514,6 +601,37 @@ ClassMethod HandleObjectType(
514601 }
515602}
516603
604+ ClassMethod HandleObjectTypeInternal (
605+ value As %DynamicObject ,
606+ idx As %Integer ,
607+ Output pContents ,
608+ rootSchema As %DynamicObject )
609+ {
610+ Set pContents (idx ," type" ) = " object"
611+ If $IsObject (value .properties ) {
612+ Do ..SchemaToContentsInternal (value , rootSchema , .subContents )
613+ Merge pContents (idx ) = subContents
614+ }
615+ }
616+
617+ ClassMethod HandleEnumType (
618+ value As %DynamicObject ,
619+ idx As %Integer ,
620+ Output pContents )
621+ {
622+ Set pContents (idx ," type" ) = " %String"
623+ // Store enum values for reference
624+ If $IsObject (value .enum ) {
625+ Set enumString = " "
626+ Set enumIterator = value .enum .%GetIterator ()
627+ While enumIterator .%GetNext (.enumIdx , .enumValue ) {
628+ If enumString '= " " Set enumString = enumString _" ,"
629+ Set enumString = enumString _enumValue
630+ }
631+ Set pContents (idx ," enum" ) = enumString
632+ }
633+ }
634+
517635ClassMethod HandleAllOfType (
518636 value As %DynamicObject ,
519637 key As %String ,
@@ -539,6 +657,31 @@ ClassMethod HandleAllOfType(
539657 }
540658}
541659
660+ ClassMethod HandleAllOfTypeInternal (
661+ value As %DynamicObject ,
662+ key As %String ,
663+ idx As %Integer ,
664+ Output pContents ,
665+ rootSchema As %DynamicObject )
666+ {
667+ Set pContents (idx ) = 1 //TODO size of subContents
668+ Set pContents (idx ," type" ) = " object"
669+ Set pContents (idx ," name" ) = key
670+ Set pContents (idx ," alias" ) = key
671+
672+ Set allOfIterator = value .allOf .%GetIterator ()
673+ While allOfIterator .%GetNext (.allOfKey , .allOfValue ) {
674+ If $IsObject (allOfValue ." $ref" ) {
675+ Do ..SchemaToContentsInternal (allOfValue ." $ref" , rootSchema , .subContents )
676+ }
677+ Else {
678+ Set tDef = rootSchema ." $defs" .%Get ($Piece (allOfValue ." $ref" ," /" ,*))
679+ Do ..SchemaToContentsInternal (tDef , rootSchema , .subContents )
680+ }
681+ Merge pContents (idx ) = subContents
682+ }
683+ }
684+
542685Method bufferGet ()
543686{
544687 Quit ..#BUFFER
0 commit comments