Download the PHP package justcoded/swagger-tools without Composer

On this page you can find all versions of the php package justcoded/swagger-tools. 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 swagger-tools

Swagger Tools

This repository contains an examples of OAS/Swagger API documentations with several tools and a guide to create good API documentation and use it to build a Mock server.

Why to use API documentation?

When two different teams develop backend and frontend separately - they both need a document stated the request and response data format. Of course, they make a deal in Slack for example and try to remember it. However, in this way your product become a "black box", which is highly difficult to support.

As a solution we propose to create a structured API documentation, which is not dependent on some specific technology. I mean that you don't need to learn some PHP or JavaScript to create such documentation. Nowadays, there are two popular formats: OAS (Open API Specification) and RAML (RESTful API Modeling Language). RAML is pretty cool, but OAS has bigger community and OAS became our choice. And unfortunately, we need to use outdated OAS2 format (aka "Swagger"), because OAS3 is not supported by numerous tools you will probably need it future.

Contents

You can find in this repo:

Writing Docs

Setup project

To start with - you can clone this repository to some webserver. It uses static html and javascript, so you don't need any special server configuration. You will need composer package manager on the server.

That's it, you can open http://mydomain.com/swagger/ in browser and you will get a Swagger UI with our sample doc.

Or you can try to check swagger UI running nginx with docker like this:

Create your docs

Now let's go to the examples folder. You can copy some folder to start with. After that you will need to update index.html to point to your new docs by default:

As already mentioned we use OAS2 format, specification can be found here:

If you are new to the swagger format you will need to learn such declarations:

Docs structure we propose to use:

Because of limitations of OAS2 format we need to list ALL routes inside main file:

Having the examples I think all other things are self-explanatory.

Swagger Editor

We recommend to use WebStorm or PHPStorm (or any other Jetbrains IDE) to edit swagger yaml files. To have autocompletions on swagger identifiers and references you will need to install plugin called Swagger Plugin.

JSON format

When you develop an API it's always a hard decision on what format JSON should be looks like. To solve this problem we suggest to follow JSONAPI specs: http://jsonapi.org/

In general, it defines that we need to transfer data in a format like this:

This format is good for JavaScript libraries such as React.js, Vue.js and Angular, because it's super easy to populate scope based on resource types.

JSONAPI has a lot of ready-to-use implementations: http://jsonapi.org/implementations/

JSONAPI Format For Non-resource Requests

Unfortunately, this specification doesn't answer how to form non-resource requests. Usually these are some actions, for example "search".

We suggest to define that we can transfer a document-type model of type "userInput", which can vary from route to route. Looks like this:

PHP Tools

Merge tool

./cli/swagger-merge.php examples/v2.0/swagger.yaml > merged-swagger2.yaml

Faker tool

Add to your properties x-faker attribute:

swagger: '2.0'
definitions:
  User:
    type: object
    properties:
      id:
        type: integer
        format: int64
        minimum: 1
      email:
        type: string
        format: email
        x-faker: email
      first_name:
        type: string
        x-faker: firstName
      last_name:
        type: string
        x-faker: lastName

Run command:

./cli/swagger-faker.php examples/merged/swagger2.yaml -n10 -r -c > swagger-faked.yaml

You will get:

definitions:
  User:
    type: object
    properties:
      id:
        type: integer
        format: int64
        minimum: 1
      email:
        type: string
        format: email
        x-faker: email
        enum:
          - [email protected]
          - [email protected]
          - [email protected]
          - [email protected]
          - [email protected]
          - [email protected]
          - [email protected]
          - [email protected]
          - [email protected]
          - [email protected]
      first_name:
        type: string
        x-faker: firstName
        enum:
          - Denis
          - Donna
          - Elissa
          - Brandyn
          - Dino
          - Linda
          - Sadye
          - Kenneth
          - Michel
          - Theo

      ...

    required:
    - id
    - email
    - first_name
    - last_name
    - profile

Using this repo as dependency

Of course, you can add this repository as dependency to your project, symlink swagger ui assets to your public repository and create your template inside your framework to print swagger ui interface, pointing to some generated doc.

As an example we created Yii extension, wrapping our PHP tools: https://github.com/justcoded/yii2-swaggerviewer


All versions of swagger-tools with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.0
symfony/yaml Version ^5.0 | ^6.0
swagger-api/swagger-ui Version ^4.15.0
fakerphp/faker Version ^1.21.0
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 justcoded/swagger-tools contains the following files

Loading the files please wait ....