Skip to content

Commit

Permalink
chore: updating templates for php sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
valmoz authored and fattureincloud-bot committed May 1, 2024
1 parent fffdaf0 commit 572e0f5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 48 deletions.
47 changes: 30 additions & 17 deletions templates/openapi-generator/php/README.mustache
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# {{packageName}}

[![Packagist](https://img.shields.io/packagist/v/fattureincloud/fattureincloud-php-sdk?color=g)](https://packagist.org/packages/fattureincloud/fattureincloud-php-sdk) ![unit tests](https://github.com/fattureincloud/fattureincloud-php-sdk/actions/workflows/validate.yaml/badge.svg)

{{#appDescriptionWithNewLines}}
{{{.}}}
{{/appDescriptionWithNewLines}}
Expand All @@ -14,25 +12,37 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}).

### Requirements

PHP 7.3 and later.
PHP 7.4 and later.
Should also work with PHP 8.0.

### Composer

To install the bindings via [Composer](https://getcomposer.org/), run the following command:

```bash
$ composer require fattureincloud/fattureincloud-php-sdk
To install the bindings via [Composer](https://getcomposer.org/), add the following to `composer.json`:

```json
{
"repositories": [
{
"type": "vcs",
"url": "https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}.git"
}
],
"require": {
"{{gitUserId}}/{{gitRepoId}}": "*@dev"
}
}
```

Then run `composer install`

### Manual Installation

There are three options:
- [recommended] download the latest release of the fattureincloud-php-sdk [Phar Archive](https://github.com/fattureincloud/fattureincloud-php-sdk/releases) and simply include it in your project.
Download the files and include `autoload.php`:

```php
require_once('./fattureincloud-php-sdk.phar');
<?php
require_once('/path/to/{{packageName}}/vendor/autoload.php');
```
- download our sdk using [php-download](https://php-download.com/package/fattureincloud/fattureincloud-php-sdk) and simply include it in your project.
- create your own custom autoloader and download all the dependencies (transitive included) as explained [here](https://ehikioya.com/how-to-install-php-packages-without-composer/).

## Getting Started

Expand All @@ -50,7 +60,7 @@ $apiInstance = new {{invokerPackage}}\Api\{{classname}}(
new GuzzleHttp\Client(){{#hasAuthMethods}},
$config{{/hasAuthMethods}}
);
{{#allParams}}${{paramName}} = {{#isPrimitiveType}}{{{example}}}{{/isPrimitiveType}}{{^isPrimitiveType}}new {{{dataType}}}{{/isPrimitiveType}}; // {{{dataType}}}{{#description}} | {{{.}}}{{/description}}
{{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}}{{#description}} | {{{.}}}{{/description}}
{{/allParams}}

try {
Expand All @@ -76,11 +86,9 @@ Class | Method | HTTP request | Description
{{/models}}

## Authorization
{{^authMethods}}
All endpoints do not require authorization.
{{/authMethods}}
{{^authMethods}}Endpoints do not require authorization.{{/authMethods}}
{{#hasAuthMethods}}Authentication schemes defined for the API:{{/hasAuthMethods}}
{{#authMethods}}
{{#last}} Authentication schemes defined for the API:{{/last}}
### {{{name}}}
{{#isApiKey}}

Expand All @@ -98,6 +106,10 @@ All endpoints do not require authorization.

- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
{{/isBasicBearer}}
{{#isHttpSignature}}

- **Type**: HTTP signature authentication
{{/isHttpSignature}}
{{/isBasic}}
{{#isOAuth}}

Expand Down Expand Up @@ -135,4 +147,5 @@ This PHP package is automatically generated by the [OpenAPI Generator](https://o
{{^hideGenerationTimestamp}}
- Build date: `{{generatedDate}}`
{{/hideGenerationTimestamp}}
- Generator version: `{{generatorVersion}}`
- Build package: `{{generatorClass}}`
6 changes: 3 additions & 3 deletions templates/openapi-generator/php/api_doc.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ All URIs are relative to {{basePath}}, except if the operation defines another b
{{#-first}}
- Variables:
{{/-first}}
- {{{name}}}: {{{description}}}{{^description}} No description provided{{/description}}{{#enumValues}}
- {{{name}}}: {{{description}}}{{^description}} No description provided{{/description}}{{#enumValues}}
{{#-first}}
- Allowed values:
{{/-first}}
- {{{.}}}{{/enumValues}}{{#defaultValue}}
- {{{.}}}{{/enumValues}}{{#defaultValue}}
- Default value: {{{.}}}
{{/defaultValue}}{{/variables}}{{/servers}}
{{{summary}}}{{#notes}}
Expand All @@ -47,7 +47,7 @@ $apiInstance = new {{invokerPackage}}\Api\{{classname}}(
$config{{/hasAuthMethods}}
);
{{^vendorExtensions.x-group-parameters}}
{{#allParams}}${{paramName}} = {{#isPrimitiveType}}{{{example}}}{{/isPrimitiveType}}{{^isPrimitiveType}}new {{{dataType}}}{{/isPrimitiveType}}; // {{{dataType}}}{{#description}} | {{{.}}}{{/description}}
{{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}}{{#description}} | {{{.}}}{{/description}}
{{/allParams}}{{#servers}}{{#-first}}
$hostIndex = 0;
$variables = [{{#variables}}
Expand Down
10 changes: 5 additions & 5 deletions templates/openapi-generator/php/composer.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"php": "^7.4 || ^8.0",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^7.4.5",
"guzzlehttp/psr7": "^2.1.1"
"guzzlehttp/guzzle": "^7.3",
"guzzlehttp/psr7": "^1.7 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"friendsofphp/php-cs-fixer": "^3.4"
"phpunit/phpunit": "^8.0 || ^9.0",
"friendsofphp/php-cs-fixer": "^3.5"
},
"autoload": {
"psr-4": { "{{{escapedInvokerPackage}}}\\" : "{{{srcBasePath}}}/" }
Expand Down
34 changes: 17 additions & 17 deletions templates/openapi-generator/php/model_generic.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
*
* @var boolean[]
*/
protected static $openAPINullables = [
protected static array $openAPINullables = [
{{#vars}}'{{name}}' => {{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}}{{^-last}},
{{/-last}}{{/vars}}
{{/-last}}{{/vars}}
];

/**
* If a nullable field gets set to null, insert it here
*
* @var boolean[]
*/
protected $openAPINullablesSetToNull = [];
protected array $openAPINullablesSetToNull = [];

/**
* Array of property to type mappings. Used for (de)serialization
Expand Down Expand Up @@ -93,7 +93,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
*
* @param boolean[] $openAPINullablesSetToNull
*/
private function setOpenAPINullablesSetToNull($openAPINullablesSetToNull): void
private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
{
$this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
}
Expand Down Expand Up @@ -234,7 +234,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
* @param mixed[] $data Associated array of property values
* initializing the model
*/
public function __construct($data = null)
public function __construct(array $data = null)
{
{{#parentSchema}}
parent::__construct($data);
Expand All @@ -251,15 +251,15 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
}

/**
* Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
* is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
* $this->openAPINullablesSetToNull array
*
* @param string $variableName
* @param array $fields
* @param mixed $defaultValue
*/
private function setIfExists(string $variableName, $fields, $defaultValue): void
* Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
* is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
* $this->openAPINullablesSetToNull array
*
* @param string $variableName
* @param array $fields
* @param mixed $defaultValue
*/
private function setIfExists(string $variableName, array $fields, $defaultValue): void
{
if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
$this->openAPINullablesSetToNull[] = $variableName;
Expand Down Expand Up @@ -365,7 +365,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
/**
* Gets {{name}}
*
* @return {{#allowableValues}}string{{/allowableValues}}{{^allowableValues}}{{{dataType}}}{{/allowableValues}}{{^required}}|null{{/required}}
* @return {{{dataType}}}{{^required}}|null{{/required}}
{{#deprecated}}
* @deprecated
{{/deprecated}}
Expand All @@ -376,9 +376,9 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
}

/**
* Sets {{name}}{{#allowableValues}}, the accepted values are available in {{dataType}}{{/allowableValues}}
* Sets {{name}}
*
* @param {{#allowableValues}}string{{/allowableValues}}{{^allowableValues}}{{{dataType}}}{{/allowableValues}}{{^required}}|null{{/required}} ${{name}}{{#description}} {{{.}}}{{/description}}{{^description}} {{{name}}}{{/description}}
* @param {{{dataType}}}{{^required}}|null{{/required}} ${{name}}{{#description}} {{{.}}}{{/description}}{{^description}} {{{name}}}{{/description}}
*
* @return self
{{#deprecated}}
Expand Down
8 changes: 2 additions & 6 deletions templates/openapi-generator/php/phpunit.xml.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">{{apiSrcPath}}</directory>
<directory suffix=".php">./lib/Filter</directory>
<directory suffix=".php">./lib/OAuth2</directory>
<directory suffix=".php">{{modelSrcPath}}</directory>
<directory suffix=".php">{{#lambda.forwardslash}}{{apiSrcPath}}{{/lambda.forwardslash}}</directory>
<directory suffix=".php">{{#lambda.forwardslash}}{{modelSrcPath}}{{/lambda.forwardslash}}</directory>
</include>
</coverage>
<testsuites>
<testsuite name="tests">
<directory>{{apiTestPath}}</directory>
<directory>./test/Filter</directory>
<directory>./test/OAuth2</directory>
<directory>{{modelTestPath}}</directory>
</testsuite>
</testsuites>
Expand Down

0 comments on commit 572e0f5

Please sign in to comment.