Hi,

applying a jsonschema check for arbitrary json objects may be used upfront
to ensure validity of those objects. One candidate could be the
'connect.json', so i thought i could give it a try. Please see below for an
example jsonschema, as a first attempt.

I would not want to create an jira issue for this, as it is really just an
experiment.


Example usage on empty json ( it's just '{}' ):

$ jsonschema -i empty.json qpid-proton-connect-schema.json || echo "Invalid
json"
(no output )
NOTE: empty json is valid to this schema, but it's not very useful.

Example usage on an incorrect json:

$ jsonschema -i broken2.json qpid-proton-connect-schema.json || echo
"Invalid json"
: '' is not of type 'integer'
Invalid json
NOTE: This check failed, as the file 'broken.json' has an empty string for
'heartbeat', according to the schema, that should be an integer.
NOTE2: Also, the scheme used is 'http', which is not reflected in the
schema, yet.

BR,
Thomas


## Appendix -1  file: qpid-proton-connect-schema.json

$ cat qpid-proton-connect-schema.json
{
  "$schema": "http://json-schema/draft-07/schema#";,
  "$id": "qpid-proton_connect-schema",
  "title": "qpid-proton connect schema",
  "description": "Schema for the 'connect.json' config file used by
qpid-proton python binding.",
  "type": "object",
  "additionalProperties": true,
  "required": [
  ],
  "properties": {
    "scheme": {
      "type": "string",
      "description": "The AMQP scheme to use. Can be 'amqp' or 'amqps'"
    },
    "host": {
      "type": "string",
      "description": "The hostname to connect to."
    },
    "heartbeat": {
      "type": "integer",
      "description": "Specify a heartbeat interval."
    },
    "sasl": {
      "$ref": "#/definitions/sasl_properties"
    },
    "user": {
       "type": "string",
       "description": "Specify connecting username to AMQP service
endpoint."
    },
    "password": {
       "type": "string",
       "description": "Specify the connecting users password."
    },
    "tls": {
       "type": "object",
       "$ref": "#/definitions/tls_properties"
    }
  },
  "definitions": {
     "sasl_properties": {
       "type": "object",
       "required": [ "sasl_enabled", "mechanisms" ],
       "properties": {
         "sasl_enabled": {
           "type": "boolean",
           "description": "Indicates the usage of any SASL auth mechanism."
         },
         "mechanisms": {
           "type": "string",
           "description": "A space separated list of enabled SASL
mechanisms."
         }
       }
     },
     "tls_properties": {
       "type": "object",
       "required": [ "ca", "cert", "key", "verify" ],
       "ca": {
         "type": "string"
       },
       "cert": {
         "type": "string"
       },
       "key": {
         "type": "string"
       },
       "verify": {
         "type": "boolean"
       }
    }
  }
}

## Appendix -2  file: broken.json

{
    "scheme": "http",
    "host": "example.com",
    "heartbeat": "",
    "user": "foo",
    "password": "bar"
}

Reply via email to