Loopback Swagger Questions.

405 views
Skip to first unread message

Rob Halff

unread,
Sep 19, 2014, 8:46:51 PM9/19/14
to loopb...@googlegroups.com
I want to start an API from scratch and I am considering creating a definition with swagger to generate the api.

As explained overhere: http://strongloop.com/strongblog/enterprise-api-swagger-2-0-loopback/

Some questions arise though:

- "You can also use the pet model directly. It will provide you the full CRUD operations."

   But it seems to me the more obvious interface would be the (v2) swagger api at /api.

   Does this mean I should manually define all crud operations within the `paths` section of the swagger definition?
   If so, it seems a bit like a step back, especially if I have to define these for a considerable amount of models.

- Within the `definitions` section in a swagger file all models can be defined.
  Is there a way to indicate I want default CRUD methods to be generated for them at /api instead of the normal interface at /
  (This is probably more of a swagger spec question and would solve the first question)

- I also want to generate an angular.js client, there is a generator for this, but this assumes I'm talking to the models directly at /
  When I talk to /api perhaps something like https://github.com/signalfuse/swagger-angular-client makes more sense?
  Downside being it lacks the extra stuff for authentication the normal generator adds (if I remember correctly)

I could use two endpoints / and /api, creating two kinds of services within angular, one with the crud operations and authentication and one for extra operations defined at /api, I hope though this is caused by my own misunderstanding of how to use the swagger generator and this is not necessary.

I'm not sure what the best approach is, using both, or define each and every crud method inside the swagger specification, any clues?






Raymond Feng

unread,
Sep 22, 2014, 7:11:55 PM9/22/14
to Rob Halff, loopb...@googlegroups.com
Hi, Rob.

Thank you for trying out the loopback:swagger generator. Please loopback and swagger use different ways to describe APIs.

- LoopBack organizes apis around models (sort of classes with methods and data)
- Swagger groups apis by the HTTP endpoints

Please see my comments inline.

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

On Sep 19, 2014, at 5:46 PM, Rob Halff <rob....@gmail.com> wrote:

I want to start an API from scratch and I am considering creating a definition with swagger to generate the api.

As explained overhere: http://strongloop.com/strongblog/enterprise-api-swagger-2-0-loopback/

Some questions arise though:

- "You can also use the pet model directly. It will provide you the full CRUD operations."

   But it seems to me the more obvious interface would be the (v2) swagger api at /api.

   Does this mean I should manually define all crud operations within the `paths` section of the swagger definition?
   If so, it seems a bit like a step back, especially if I have to define these for a considerable amount of models.


No. The challenge is that Swagger spec doesn’t provide enough metadata for the generator to find out what LoopBack model
should be used to anchor the api method. For now, we just try to create a plain model (such as api) to contain the methods. The 
plain model doesn’t have data properties and you can view it as a controller.

If the apis are close to RESTful CRUD operations. there is a great chance that such operations can be implemented using a LoopBack
model.

The compromise is that we can implement the methods using models from definitions. For example, an endpoint like GET /pets can be
implemented using ‘Pet.find()’.

- Within the `definitions` section in a swagger file all models can be defined.
  Is there a way to indicate I want default CRUD methods to be generated for them at /api instead of the normal interface at /
  (This is probably more of a swagger spec question and would solve the first question)

The definitions are close to LoopBack models. We generate model jsons from the json schemas from swagger definitions. These
models will get CRUD from loopback for free.


- I also want to generate an angular.js client, there is a generator for this, but this assumes I'm talking to the models directly at /
  When I talk to /api perhaps something like https://github.com/signalfuse/swagger-angular-client makes more sense?
  Downside being it lacks the extra stuff for authentication the normal generator adds (if I remember correctly)

I could use two endpoints / and /api, creating two kinds of services within angular, one with the crud operations and authentication and one for extra operations defined at /api, I hope though this is caused by my own misunderstanding of how to use the swagger generator and this is not necessary.

I'm not sure what the best approach is, using both, or define each and every crud method inside the swagger specification, any clues?

I would imagine that the Swagger base path can be mapped to loopback REST rootApiPath.







--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages