PHPackages                             paysera/util-raml-code-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. paysera/util-raml-code-generator

ActiveProject[Utility &amp; Helpers](/categories/utility)

paysera/util-raml-code-generator
================================

Generate Code from RAML specification

11.11.2(8mo ago)131920[2 issues](https://github.com/paysera/util-raml-code-generator/issues)[17 PRs](https://github.com/paysera/util-raml-code-generator/pulls)proprietaryPHPPHP &gt;=7.4CI failing

Since Apr 11Pushed 8mo ago6 watchersCompare

[ Source](https://github.com/paysera/util-raml-code-generator)[ Packagist](https://packagist.org/packages/paysera/util-raml-code-generator)[ RSS](/packages/paysera-util-raml-code-generator/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (24)Versions (102)Used By (0)

util-raml-code-generator
========================

[](#util-raml-code-generator)

[![Latest Version](https://camo.githubusercontent.com/e3a7d3840b9b3297aef6742b690651a8afc321b245befd4e6ec1b6c609d1ca98/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f706179736572612f7574696c2d72616d6c2d636f64652d67656e657261746f723f7374796c653d666c61742d737175617265)](https://github.com/paysera/util-raml-code-generator/releases)[![Build Status](https://camo.githubusercontent.com/80f78acd8e9eeb9b80c20dc1504aa75e327d31bf92c2db223c8325785d59231c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f706179736572612f7574696c2d72616d6c2d636f64652d67656e657261746f722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/paysera/util-raml-code-generator)

`util-raml-code-generator` generates code packages from specified RAML definition. Currently this utility can:

- Automatically generate and release:
    - `PHP REST API client`
    - `Javascript REST API client`
- Generate `Symfony Api Bundle`

Requirements
------------

[](#requirements)

- `PHP >=7.4`
- `Composer  {
    const defaultUrlParameters = {};

    if (Object.prototype.hasOwnProperty.call(options, 'urlParameters')) {
        const { urlParameters } = options;
        for (let [key, value] of Object.entries(defaultUrlParameters)) {
            if (!Object.prototype.hasOwnProperty.call(urlParameters, key)) {
                urlParameters[key] = value;
            }
        }
        options.urlParameters = urlParameters;
    }

    return new CategoryClient(
        createClient({
            baseURL,
            middleware,
            options
        })
    )
};
```

#### src/service/CategoryClient.js

[](#srcservicecategoryclientjs)

```
import { createRequest, ClientWrapper } from '@paysera/http-client-common';

import Category from '../entity/Category';
import CategoryFilter from '../entity/CategoryFilter';
import CategoryResult from '../entity/CategoryResult';

class CategoryClient {
    /**
     * @param {ClientWrapper} client
     */
    constructor(client) {
        this.client = client;
    }

    /**
     * Enable category
     * PUT /categories/{id}/enable
     *
     * @param {string} id
     * @return {Promise.}
     */
    enableCategory(id) {
        const request = createRequest(
            'PUT',
            `categories/${encodeURIComponent(id)}/enable`,
            null,
        );

        return this.client
            .performRequest(request)
            .then(data => new Category(data));
    }

    /**
     * Disable category
     * PUT /categories/{id}/disable
     *
     * @param {string} id
     * @return {Promise.}
     */
    disableCategory(id) {
        const request = createRequest(
            'PUT',
            `categories/${encodeURIComponent(id)}/disable`,
            null,
        );

        return this.client
            .performRequest(request)
            .then(data => new Category(data));
    }

    /**
     * Update category
     * PUT /categories/{id}
     *
     * @param {string} id
     * @param {Category} category
     * @return {Promise.}
     */
    updateCategory(id, category) {
        const request = createRequest(
            'PUT',
            `categories/${encodeURIComponent(id)}`,
            category,
        );

        return this.client
            .performRequest(request)
            .then(data => new Category(data));
    }
    /**
     * Delete category
     * DELETE /categories/{id}
     *
     * @param {string} id
     * @return {Promise.}
     */
    deleteCategory(id) {
        const request = createRequest(
            'DELETE',
            `categories/${encodeURIComponent(id)}`,
            null,
        );

        return this.client
            .performRequest(request)
            .then(data => null);
    }

    /**
     * Standard SQL-style Result filtering
     * GET /categories
     *
     * @param {CategoryFilter} categoryFilter
     * @return {Promise.}
     */
    getCategories(categoryFilter) {
        const request = createRequest(
            'GET',
            `categories`,
            categoryFilter,
        );

        return this.client
            .performRequest(request)
            .then(data => null);
    }
    /**
     * Create category
     * POST /categories
     *
     * @param {Category} category
     * @return {Promise.}
     */
    createCategory(category) {
        const request = createRequest(
            'POST',
            `categories`,
            category,
        );

        return this.client
            .performRequest(request)
            .then(data => new CategoryResult(data, 'items'));
    }

}

export default AClient;
```

Generate PHP REST client
------------------------

[](#generate-php-rest-client)

1. Run `bin/console php-generator:rest-client {path_to_raml} {output_dir} {namespace} --library_name={library_name}`.
    - `path_to_raml` path to `raml` file.
    - `output_dir` directory where to put generated files.
    - `namespace` is the namespace of Client.
    - `library_name` is optional name for generated library, i.e. `paysera/lib-some-api-client`
2. Check the dumped output to `{output_dir}` directory.

#### PHP Client file tree

[](#php-client-file-tree)

In `output_dir` you should expect these files generated:

```
|   composer.json
|   README.md
|
└───src
    |   CategoryClient.php
    |   ClientFactory.php
    |
    ├───Entity
    |       Category.php
    |       CategoryFilter.php
    |       CategoryResult.php

```

With following contents of `src` directory:

#### src/CategoryClient.php

[](#srccategoryclientphp)

```
