loopback-swagger icon indicating copy to clipboard operation
loopback-swagger copied to clipboard

StrongLoop API Explorer, do not show whole defition model in Data Type - Model Schema

Open Biax2099 opened this issue 10 years ago • 5 comments

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?

untitled

The property "Brand" its so defined...

"Brand": [ { "size": { "type": "Number" }, "color" : { "type" : "String" } } ]

Biax2099 avatar Oct 05 '16 10:10 Biax2099

Sorry, nobody of the admins can answer me? Thanks!

Biax2099 avatar Oct 10 '16 20:10 Biax2099

@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:

screen shot 2016-10-11 at 3 55 23 pm

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 :)

gunjpan avatar Oct 11 '16 19:10 gunjpan

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 avatar Oct 18 '16 07:10 Biax2099

@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).

gunjpan avatar Oct 18 '16 13:10 gunjpan

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!

Biax2099 avatar Oct 18 '16 14:10 Biax2099