StrongLoop API Explorer, do not show whole defition model in Data Type - Model Schema
I have this model "Product.json":
{
"name": "Product",
"strict": "validate",
"idInjection": false,
"properties": {
"Brand": [
{
"size": {
"type": "Number"
},
"color" : {
"type" : "String"
}
}
],
"ProductId": {
"type": "Number",
"id": true,
"required": true,
"length": null,
"precision": 10,
"scale": 0
},
"Availability": {
"type": "Number",
"required": false,
"length": null,
"precision": 10,
"scale": 0
}
}
}
My remote method:
Model.remoteMethod(
'CreateProduct', {
accepts: [
{ arg: 'context', type: 'object', 'http': function (ctx) { return ctx; } },
{ arg: 'data', type: 'Product', http: { source: 'body' } }
],
http: { path: '/CreateProduct', verb: 'post' },
returns: { arg: 'message', type: 'string', required: true, root: false }
});
Why in StrongLoop API Explorer i see this?
The property "Brand" its so defined...
"Brand": [ { "size": { "type": "Number" }, "color" : { "type" : "String" } } ]
Sorry, nobody of the admins can answer me? Thanks!
@Biax2099 : Hi, apologies for a delayed reply. In your following code:
"Brand": [
{
"size": {
"type": "Number"
},
"color" : {
"type" : "String"
}
}
],
Brand property is defined as Array of Objects datatype, which would accept an array of objects, which is displayed correctly in loopback-explorer.
I believe, you're trying to expose Brand property as an object where you can manipulate values for size & color and is generic across all instances of the Model, then, you should define
Brand with type: Object, as follows:
"Brand": {
"type": {
"size": {
"type": "Number"
},
"color": {
"type": "String"
}
}
},
or
"Brand":
{
"type": {
"size": "Number",
"color" : "String"
}
},
Both flavors would work and display Brand as following:

This should resolve your issue, closing for now. Please let me know, if you need any further assistance, in the comments and I'll help you the best I can. Thank you :)
Hi @gunjpan, thank you so much for your answer!
I can ask you if is possible to declare a prototype to function TypeRegistry in ..\node_modules\loopback-component-explorer\node_modules\loopback-swagger\lib\specgen\type-registry.js ?
@Biax2099 : Sorry, I didn't get your question. Could you please explain a bit more.
FYI: specgen adheres to Open API specification a.k.a. Swagger specification (read more about it here).
Hi @gunjpan, sorry i try to explaning better. If I would to record a custom json schema (not x-any, ObjectID, GeoPoint and Loopback Model) using specgen, how i can? Its possible?
Thanks!