Skip to content

Commit

Permalink
Add OpenAPI generator configuration and templates
Browse files Browse the repository at this point in the history
Introduced configuration for PHP client generation using OpenAPI Generator.
Updated .gitignore to include .idea directory and created necessary templates and configurations for code generation.
  • Loading branch information
tups committed Nov 24, 2024
1 parent ab71297 commit bf1fb50
Show file tree
Hide file tree
Showing 27 changed files with 4,002 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
vendor
vendor
.idea
25 changes: 25 additions & 0 deletions .openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

.gitignore
70 changes: 70 additions & 0 deletions config-openapi-generator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# config-openapi-generator.yml
generatorName: php-nextgen
outputDir: .
inputSpec: https://api.brevo.com/v3/swagger_definition_v3.yml
gitHost: github.com
gitUserId: getbrevo
gitRepoId: brevo-php
templateDirectory: ./template/php-nextgen
templateDir: ./template/php-nextgen

# Package configuration
invokerPackage: Brevo\Client
artifactVersion: 3.0.0
packageName: Brevo\Client
srcBasePath: lib
variableNamingConvention: camelCase

# Server configuration
serverVariables:
host: https://api.brevo.com/v3

# HTTP client configuration
httpUserAgent: brevo_clientAPI/v3.0.0/php

# PHP specific configurations
modelPackage: Models
apiPackage: Api
composerVendorName: getbrevo
composerProjectName: brevo-php

# Composer metadata
artifactDescription: "Brevo's API v3 Php Library"
infoEmail: contact@brevo.com
infoName: "Brevo Developers"
infoUrl: https://www.brevo.com/
licenseName: MIT
licenseUrl: https://raw.githubusercontent.com/getbrevo/brevo-php/refs/heads/main/LICENSE.md
artifactKeywords:
- brevo
- swagger
- php
- sdk
- api
composerAuthorName: "Brevo Developers"
composerAuthorEmail: contact@brevo.com
composerHomepage: https://github.com/getbrevo/brevo-php

# Organization information
developerOrganization: "Brevo Developers"
developerOrganizationUrl: https://www.brevo.com/
artifactUrl: https://github.com/getbrevo/brevo-php

# Code generation options
sortParamsByRequiredFlag: true
sortModelPropertiesByRequiredFlag: true
ensureUniqueParams: true
hideGenerationTimestamp: true
legacyDiscriminatorBehavior: true

# PHP quality settings
phpLegacySupport: false
phpUnitVer: 9.5.0
disallowAdditionalPropertiesIfNotPresent: false


files:
model_abstract.mustache:
destinationFilename: lib/Models/AbstractModel.php
templateType: "SupportingFiles"

29 changes: 29 additions & 0 deletions template/php-nextgen/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* @generated
* @link https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/HEAD/doc/config.rst
*/
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('vendor')
->exclude('test')
->exclude('tests')
;

$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR12' => true,
'phpdoc_order' => true,
'array_syntax' => [ 'syntax' => 'short' ],
'strict_comparison' => true,
'strict_param' => true,
'no_trailing_whitespace' => false,
'no_trailing_whitespace_in_comment' => false,
'braces' => false,
'single_blank_line_at_eof' => false,
'blank_line_after_namespace' => false,
'no_leading_import_slash' => false,
])
->setFinder($finder)
;
11 changes: 11 additions & 0 deletions template/php-nextgen/.phplint.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
path:
- ./{{srcBasePath}}
- ./{{testBasePath}}
jobs: 10
extensions:
- php
exclude:
- vendor
warning: true
memory-limit: -1
no-cache: true
12 changes: 12 additions & 0 deletions template/php-nextgen/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php
# Jammy Jellyfish environment has preinstalled PHP 8.1
# Focal Fossa doesn't fit since it contains preinstalled PHP 7.4 only
# https://docs.travis-ci.com/user/reference/jammy/#php-support
dist: jammy
os:
- linux
php:
- 8.1
- 8.2
before_install: "composer install"
script: "vendor/bin/phpunit"
109 changes: 109 additions & 0 deletions template/php-nextgen/ApiException.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
/**
* ApiException
* PHP version 8.1
*
* @package {{invokerPackage}}
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/

{{>partial_header}}
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

namespace {{invokerPackage}};

use Exception;
use stdClass;

/**
* ApiException Class Doc Comment
*
* @package {{invokerPackage}}
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
class ApiException extends Exception
{
/**
* The HTTP body of the server response either as Json or string.
*
* @var stdClass|string|null
*/
protected stdClass|string|null $responseBody;
/**
* The HTTP header of the server response.
*
* @var string[][]|null
*/
protected ?array $responseHeaders;
/**
* The deserialized response object
*
* @var mixed
*/
protected mixed $responseObject = null;
/**
* Constructor
*
* @param string $message Error message
* @param int $code HTTP status code
* @param string[][]|null $responseHeaders HTTP response header
* @param stdClass|string|null $responseBody HTTP decoded body of the server response either as stdClass or string
*/
public function __construct(string $message = "", int $code = 0, ?array $responseHeaders = [], stdClass|string|null $responseBody = null)
{
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
}

/**
* Gets the HTTP response header
*
* @return string[][]|null HTTP response header
*/
public function getResponseHeaders(): ?array
{
return $this->responseHeaders;
}

/**
* Gets the HTTP body of the server response either as Json or string
*
* @return stdClass|string|null HTTP body of the server response either as \stdClass or string
*/
public function getResponseBody(): stdClass|string|null
{
return $this->responseBody;
}

/**
* Sets the deserialized response object (during deserialization)
*
* @param mixed $obj Deserialized response object
*
* @return void
*/
public function setResponseObject(mixed $obj): void
{
$this->responseObject = $obj;
}

/**
* Gets the deserialized response object (during deserialization)
*
* @return mixed the deserialized response object
*/
public function getResponseObject(): mixed
{
return $this->responseObject;
}
}
Loading

0 comments on commit bf1fb50

Please sign in to comment.