loopback-connector-swagger

    The Swagger connector enables LoopBack applications to interact with other RESTful APIs described usingOpenAPI (Swagger) specification v.2.0.

    To interact with a Swagger API, we first configure a data source backed by the Swagger connector:

    • spec: http url or local file system path to the swagger specification file (Specification file must be of or .json extension) or the specification.Note: Current implementation supports relative local path to the current working directory (i.e. process.cwd()).

    • validate: when true, validates provided spec against Swagger specification 2.0 before initializing a data source.default:

    • Basic authentication:

    • OAuth2:Note: value of name must correspond to a security scheme declared in the within spec document.

    NOTE: The Swagger connector loads the API specification document asynchronously.As a result, the data source won’t be ready to create models until it is connected.The recommended way is to use an event handler for the connected event of data source:

    For example:

    1. PetService.getPetById({petId: 1}, function (err, res){
    2. });

    Once the model is defined, it can be wrapped or mediated to define new methods.The following example simplifies the getPetById operation to a method that takes petID and returns a Pet instance.

    This custom method on the PetService model can be exposed as REST API end-point. It uses the to define the mappings:

    coming soon…