Skip to content

Instantly share code, notes, and snippets.

@TrentBrown
Last active March 4, 2016 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrentBrown/5627897 to your computer and use it in GitHub Desktop.
Save TrentBrown/5627897 to your computer and use it in GitHub Desktop.
FileThis Complex Question Schema

FileThis Complex Question Schema

When the kind property of Question resources has the value complex, the question property of the resource will have a JSON value that describes how the question parts must be posed to the user. This document defines the schema of those values and also the schema of the expected answer to the questions parts.

The schemas below are defined using JSON Schema.

Examples can be validated against schemas here.

Complex Question Schema:

{
	"type": "object",
	"properties":
	{
		"questions":
		{
		    "title": "Question Parts",
            "type": "array",
            "items": 
            {
        		"title": "Question Part",
        		"type":
        		[
        		    {
                        "description": "Textual question part",
                        "type": "object",
                        "additionalProperties": false,
                        "properties":
                        {
                            "kind":
                            {
                                "type": "string",
                                "required": true,
                                "enum": ["text"]
                            },
                            "persistent":
                            {
                                "type": "boolean"
                            },
                            "label":
                            {
                                "description": "The text to present to the user",
                                "type": "string",
                                "required": true
                            },
                            "key":
                            {
                                "description": "A value that identifies the question part",
                                "type": "string",
                                "required": true
                            }
            		    }
            		},
        		    {
                        "description": "Password question part - Use bullets to hide response entered by user",
                        "type": "object",
                        "additionalProperties": false,
                        "properties":
                        {
                            "kind":
                            {
                                "type": "string",
                                "required": true,
                                "enum": ["password"]
                            },
                            "persistent":
                            {
                                "type": "boolean"
                            },
                            "label":
                            {
                                "description": "The text to present to the user",
                                "type": "string",
                                "required": true
                            },
                            "key":
                            {
                                "description": "A value that identifies the question part",
                                "type": "string",
                                "required": true
                            }                            
            		    }
            		},
        		    {
                        "description": "Numerical question part",
                        "type": "object",
                        "additionalProperties": false,
                        "properties":
                        {
                            "kind":
                            {
                                "type": "string",
                                "required": true,
                                "enum": ["number"]
                            },
                            "persistent":
                            {
                                "type": "boolean"
                            },
                            "label":
                            {
                                "description": "The text to present to the user",
                                "type": "string",
                                "required": true
                            },
                            "key":
                            {
                                "description": "A value that identifies the question part",
                                "type": "string",
                                "required": true
                            }                            
            		    }
            		},
        		    {
                        "description": "Choice question part (ie. radiobuttons)",
                        "type": "object",
                        "additionalProperties": false,
                        "properties":
                        {
                            "kind":
                            {
                                "type": "string",
                                "required": true,
                                "enum": ["choice"]
                            },
                            "persistent":
                            {
                                "type": "boolean"
                            },
                            "key":
                            {
                                "description": "A value that identifies the question part",
                                "type": "string",
                                "required": true
                            },                      
                            "label":
                            {
                                "description": "Label for radiobutton group",
                                "type": "string",
                                "required": true
                            },
                            "choices":
                            {
                                "type": "array",
                                "required": true,
                                "items": 
                                {
                                    "title": "Choice (ie. radiobutton)",
                                    "type": "object",
                                    "properties":
                                    {
                                        "label":
                                        {
                                            "description": "Label for radiobutton",
                                            "type": "string",
                                            "required": true
                                        },
                                        "key":
                                        {
                                            "description": "Key for radiobutton",
                                            "type": "string",
                                            "required": true
                                        },
                                        "value":
                                        {
                                            "description": "Value for radiobutton",
                                            "type": "string",
                                            "required": true
                                        }
                                    }
                                }
                            }
            		    }
            		}
                ]
            }
		}
	}
}

Complex Question Example:

{
    "questions":
    [
        {
            "kind": "text",
            "key": "3Npb24gZnJvbSBvdGhlciBhbmltYWxz",
            "label": "What is the name of your first pet?"
        },
        {
            "kind": "choice",
            "key": "QgYnkgYSBwZXJzZXZlcmFuY2Ugb2",
            "label": "To verify my account, send my temporary password to:",
            "choices":
            [
                {"label": "SMS 415-123-4567", "key": "123", "value": "1111"},
                {"label": "Email bob@somewhere.com", "key": "456", "value": "2222"},
                {"label": "Email betty@somewhere.com", "key": "789", "value": "3333"}
            ]
        }
    ]
}

Complex Answer Schema:

{
    "type": "array",
    "required": true,
    "items": 
    {
        "title": "Answer to question part",
        "type": "object",
        "properties":
        {
            "key":
            {
                "description": "The key for the question part",
                "type": "string",
                "required": true
            },
            "value":
            {
                "description": "The answer by the user for the question part",
                "type": "string",
                "required": true
            }
        }
    }
}

Complex Answer Example:

[
    {
        "key": "3Npb24gZnJvbSBvdGhlciBhbmltYWxz",
        "value": "Rover"
    },
    {
        "key": "QgYnkgYSBwZXJzZXZlcmFuY2Ugb2",
        "value": "dWVkIGFuZCBpbmRlZmF0aWdhYm"
    }
]

Note: The answer example above is meant to correspond to the previous question example. The value field for the answer to the second question part will actually be the string that was used to specify the multiple choice item. To see how this is handled by the FileThis client, look at the generateGui and answer methods in the ComplexQuestionMediator.as file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment