I already have a working document that creates documentation using the Swagger-UI project, but I ran into a minor problem.
Mongoose supports the Mixed data type, which is a basically unstructured object that can hold anything. However, according to the Swagger specification, the only possible values ββfor the type property are string , integer , number , boolean and array . I could not find anything in the documentation, on Google, or in open issues for the Swagger-Spec project on GitHub, which would allow mixed data types to be used.
In the Swagger-Spec documentation, where they define type parameters, they refer to the JSON-Schema project. According to the JSON-Schema object specification, there should be an option, but it is not specified as a potential value in the Swagger-Spec.
Does anyone know a way to indicate in a Swagger document that a model property can contain any value (either a single primitive value or an object)?
<strong> Examples
Mongoose schema definition:
var sampleSchema = new mongoose.Schema({ lookupCodes : { type: [mongoose.Schema.Types.Mixed] }, address: { type: mongoose.Schema.Types.Mixed } }); mongoose.model('Sample', sampleSchema);
Using the mongoose model:
var Sample = mongoose.model('Sample'); var doc = new Sample();
These are all valid values ββfor two specific properties:
doc.lookupCodes = ['A', 'B', 3, 4, 5, 'F']; doc.lookupCodes = ['A', { code: '123' }, 5]; doc.address = '123 Main St., San Jose, CA, 95125'; doc.address = { street: '123 Main St.', city: 'San Jose', state: 'CA', postalCode: '95125'}
Swagger 1.2 document (snippet):
"models": { "Sample": { "properties": { "lookupCodes": { "type": "array", "items": { "type": "??????" }, "description": "An array of lookup codes. Codes can be strings, numbers or an object containing the `code` property." }, "address": { "type": "??????", "description": "An address. This value can be a single string, containing all the elements of the address together, or it can be a structured object with each of the elements as separate properties of the object." },
I'm just looking for a way to give the developer the ability to view documentation that a particular property in the model can accept / return any value (primitive variable or object).