How can I use json schema to verify that the object key is filled in correctly?

I have an object consisting of a key and then the rest of the attributes. I can easily check the attributes, but I can’t check the key for the correct spelling.

The structure of the object:

  Adfc_s:  # key of the object  pattern /^[a-zA-Z0-9_]{1,20}$/
    title: part
    description: part_new
    status: new

The scheme by which I describe the object:

schema:
  patternProperties:
   "^[a-zA-Z0-9_]{1,20}$":
     type:object
     properties:
       title:
         type: string
       description:
         type: string
       status:
         type: string
     required:
       - title
       - description
       - status
     additionalProperties: true
source: >      #source of validation some kind of example                              
    (
      $validator := $jsonschema($self.schema); 
      ([([
        components.$spread().( 
          $ID := $keys()[0];
          {                                                                 
            "id": $ID,                                                   =
            "isvalid": $validator($.*)                                   
          }
        )        
      ][isvalid != true]).isvalid.{    
        "uid": $.params.missingProperty & "-component-" & %.id,           
        "location": "/architect/components/" & %.id,                      
        "correction": "Fill required field",                       
        "description": message
      }])
    )

Checking all attributes works, but the key is not checked in any way if the object is specifically incorrectly written and strange errors are given.

Leave a Comment