Skip to content

Additions to accept/returns type definitions #79

Description

@STRML

This relates to the Swagger 1.2 update at strongloop/loopback-component-explorer#14.

Swagger allows the display of model schemas inside the route definition, both as the return type:

return

And as a parameter type:

param

This requires that route definitions are able to mark their returns and accepts values as the model itself. Most built-in methods defined in dao.js (https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/dao.js#L1219) simply specify 'array' or 'object' as their return type, making it impossible to know the specifics of what they are returning.

I propose three new extensions to the accepts and returns syntax:

  1. The addition of 'this' as a type definition (subclass object). In loopback-explorer, this would be interpreted as equal to the parent model.
  2. Simple array syntax: {type: '[this]'}, {type: '[string]'}, etc., instead of the more verbose swagger-compliant {type: 'array', items: {type: 'string'}}. We should support both syntaxes in case of constraints on types, e.g. {type: 'array', items: {type: 'number', min: 0, max: 10}}.
  3. Anonymous model definition. Sometimes methods don't return a model, but rather selected fields from a model, aggregations, or metadata. Rather than simply define 'object' or 'array' as the return type, it would be great to be able to define the return schema inline. Since constraints don't make sense on return properties, in my opinion it is not necessary to support the more verbose {type: ...} syntax. For example:
returns: {arg: 'data', root: true, type: 'object' /* or array */, schema: {
  field1: 'number',
  field2: 'string',
  field3: '[number]',
  field4: '[this]'
}},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions