Download the PHP package hcesrl/laravel-swagger-api without Composer

On this page you can find all versions of the php package hcesrl/laravel-swagger-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-swagger-api

hcesrl/laravel-swagger-api

License

The packages adds a layer on top of the Laravel routing system allowing you to easily add metadata to your routes in order to create a Swagger UI compliant API.

Table of contents

Installation

hc
Install the package:

Publish configuration and assets:

Basic usage

Configuration

The main configuration is located in the config/api.php file. Here you can set some general metadata for your API specification such as the title, the description, etc.

Make sure that the prefix is the same used in your RouteServiceProvider for the api routes.

HTTPS/Trusted proxies

In case your API is hosted behind a load balancer and does not generate proper secure urls, refer to the Laravel docs about configuring trusted proxies.

Routing

The Api facade works with the same syntax as the Route facade and you can use it directly in your routes/api.php file.

Note: the supported methods: get, post, put, delete, patch, options. There's no support for the match method because every route must be associated with a single Operation in the Swagger specification.

When you create a new route, the Api facade returns an instance of an Operation object. This object exposes some chainable configuration methods. The following example shows an extensive use of those methods.

Route parameters

You can define different types of route parameters after creating a route through the following methods:

All these methods accept 4 parameters: name, description, required and type:

Note: the addBodyParameter method doesn't accept a type parameter, according to the Swagger specification.

If you need a deeper configuration for the parameter, you may pass a Closure function instead of a text description:

Route path parameter auto-parsing

When you define a route containg path parameters using the Laravel syntax, the route URI will be automatically parsed for path parameters, both required and optional.

The route:

will be parsed and the two path parameters will be added automatically. You can still edit the paramaters configuration:

It is also possible to disable the automatic route parsing from the main config file config/api.php setting parse_route_parameters to false.

Responses

Use the addResponse to define the route response types:

Advanced configuration

General route parameters

You may need to register different routes using the same parameters (eg. lang or locale) and these could lead to a long and difficult to maintein routes file.

To avoid this you can register general reusable route parameters that will be automatically applied when parameters with the same are found in the route uris.

Guess parameters from FormRequest

In order to simplify the parameters registration, you may bind a Laravel FormRequest directly to a route and let the package guess the parameters from the request rules.

Tags

In order to create a tag for your operations, you may call the tag method passing the name of the tag and its description, if needed.

You can also pass a callback function to create a group of operations automatically tagged with the given tag.

You may register many tags at once by passing an array to the tags method:

Versions

If you want to group your routes by different version, you may use the version method. The grouped routes will be automatically prefixed and tagged with the given version name.

Aggregated resources endpoint

An aggregate endpoint is an API endpoint that returns a mixed collection of resources, combining both Eloquent models and data generated by Closures.

Note: closures require a non-numeric array key.

Aggregated models endpoint

Building a complex API may require the creation of several endpoints exposing models data. You can easily do this with the models shortcut. With this method you can create a general resource endpoints connected to a simple Resource controller that implements only the index and show actions and handles multiple models.

The following configuration:

is equivalent to:

Customize the response

If you use custom API Resources to personalize the API data you can define the following methods within your models in order the provide the right resource to the API server.

Authorization

In order to provide the security definitions for the specification you can use one the following methods:

In any operation you can set the required security schemes via the requiresAuth method:

and on resources as well:

API Json Caching

To generate a Swagger UI json file cache, just execute the api:cache Artisan command:

After running this command, your cached json file will be used. Remember, if you add any new routes to the API you will need to generate a fresh route cache. Because of this, you should only run the api:cache command during your project's deployment.

You may use the api:clear command to clear the API cache:

Todos

License

This package is open-sourced software licensed under the MIT license.


All versions of laravel-swagger-api with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
ext-json Version *
illuminate/contracts Version ^5.5|^6.0|^7.0|^8.0|^9.0
illuminate/filesystem Version ^5.5|^6.0|^7.0|^8.0|^9.0
illuminate/http Version ^5.5|^6.0|^7.0|^8.0|^9.0
illuminate/routing Version ^5.5|^6.0|^7.0|^8.0|^9.0
illuminate/support Version ^5.5|^6.0|^7.0|^8.0|^9.0
calcinai/strut Version ^0.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hcesrl/laravel-swagger-api contains the following files

Loading the files please wait ....