Parametrized JSON schemas


#1

Is it possible to have parametrized JSON schemas such as the following:

{
   "$schema":"http://json-schema.org/draft-04/schema#",
   "type":"object",
   "additionalProperties":false,
   "properties":{
      "arrayField":{
         "type":"array",
         "items":{
            "enum":<<possibleArrayFieldValues>>
         }
      }
   }
}

where the possibleArrayField is a parameter provided through a resource type or trait, for example:

- testingtrait:
      responses:
        200:
          body:
            application/json:   
              schema: |
                           {
				   "$schema":"http://json-schema.org/draft-04/schema#",
				   "type":"object",
				   "additionalProperties":false,
				   "properties":{
					  "arrayField":{
						 "type":"array",
						 "items":{
							"enum":<<possibleArrayFieldValues>>
						 }
					  }
				   }
				}

which is then used by resources as follows:

/resource:
       post:  
           is: [testingtrait: { possibleArrayFieldValues: "[\"Test1\", \"Test2\"]"}]   

I am using the API console to design my API. This example is not being parsed. Mind you, it would be parsed if the << possibleArrayFieldValues >> is value is surrounded by double quotes. But, this would render an invalid schema.


#2

Hi, I doubt that this is possible. :wink: