Skip to content

Commit b8b0ed5

Browse files
authored
Merge pull request #37 from DoclerLabs/generatorVersionToReadme
Add generator version to readme
2 parents 95b81a8 + 0d82f35 commit b8b0ed5

File tree

11 files changed

+29
-3
lines changed

11 files changed

+29
-3
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ vendor
66
.phpunit.result.cache
77
phpstan.neon
88
phpunit.xml
9-
build
109
.php_cs.cache

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [5.6.0] - 2021-05-10
8+
### Added
9+
- Api Client Generator version to README generation
10+
711
## [5.5.0] - 2021-04-27
812
### Added
913
- Support for `default` property on required request parameters.

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ RUN composer install
1010

1111
FROM php:7.4-cli-alpine
1212

13+
ARG API_CLIENT_GENERATOR_VERSION
14+
ENV API_CLIENT_GENERATOR_VERSION=$API_CLIENT_GENERATOR_VERSION
15+
1316
COPY . /generator
1417
COPY --from=dependencies /dependencies/vendor /generator/vendor
1518

hooks/build

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env sh
2+
3+
docker build --build-arg API_CLIENT_GENERATOR_VERSION=`git describe --tags` -f $DOCKERFILE_PATH -t $IMAGE_NAME .

src/Input/Configuration.php

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Configuration
2424
private string $codeStyleConfig;
2525
private string $packageName;
2626
private string $phpVersion;
27+
private ?string $generatorVersion;
2728
private string $composerJsonTemplateDir;
2829
private string $readmeMdTemplateDir;
2930
private string $httpMessage;
@@ -37,6 +38,7 @@ public function __construct(
3738
string $codeStyleConfig,
3839
string $packageName,
3940
string $phpVersion,
41+
?string $generatorVersion,
4042
string $composerJsonTemplateDir,
4143
string $readmeMdTemplateDir,
4244
string $httpMessage,
@@ -61,6 +63,7 @@ public function __construct(
6163
$this->codeStyleConfig = $codeStyleConfig;
6264
$this->packageName = $packageName;
6365
$this->phpVersion = $phpVersion;
66+
$this->generatorVersion = $generatorVersion;
6467
$this->composerJsonTemplateDir = $composerJsonTemplateDir;
6568
$this->readmeMdTemplateDir = $readmeMdTemplateDir;
6669
$this->httpMessage = $httpMessage;
@@ -102,6 +105,11 @@ public function getPhpVersion(): string
102105
return $this->phpVersion;
103106
}
104107

108+
public function getGeneratorVersion(): ?string
109+
{
110+
return $this->generatorVersion;
111+
}
112+
105113
public function getComposerJsonTemplateDir(): string
106114
{
107115
return $this->composerJsonTemplateDir;

src/Meta/ReadmeMdTemplate.php

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function render(Specification $specification, MetaFileCollection $fileReg
3636
'specification' => $specification,
3737
'packageName' => $this->configuration->getPackageName(),
3838
'phpVersion' => $this->configuration->getPhpVersion(),
39+
'generatorVersion' => $this->configuration->getGeneratorVersion(),
3940
'namespace' => $this->configuration->getBaseNamespace(),
4041
'exampleOperation' => $this->pickExampleOperation($specification),
4142
'operationsGroupedByTags' => $this->groupOperationsByTags($specification),

src/ServiceProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function register(Container $pimple): void
8080
getenv('CODE_STYLE') ?: Configuration::DEFAULT_CODE_STYLE_CONFIG,
8181
getenv('PACKAGE') ?: '',
8282
getenv('CLIENT_PHP_VERSION') ?: Configuration::DEFAULT_PHP_VERSION,
83+
getenv('API_CLIENT_GENERATOR_VERSION') ?: null,
8384
getenv('COMPOSER_JSON_TEMPLATE_DIR') ?: Configuration::DEFAULT_TEMPLATE_DIRECTORY,
8485
getenv('README_MD_TEMPLATE_DIR') ?: Configuration::DEFAULT_TEMPLATE_DIRECTORY,
8586
getenv('HTTP_MESSAGE') ?: Configuration::DEFAULT_HTTP_MESSAGE,

template/README.md.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ docker run -it \
1212
-e OUTPUT_DIR=/client \
1313
-e PACKAGE={{ packageName }} \
1414
-e CLIENT_PHP_VERSION={{ phpVersion }} \
15-
dhlabs/api-client-generator
15+
dhlabs/api-client-generator{{ generatorVersion is not empty ? ":#{generatorVersion}" }}
1616
```
1717

1818
## Usage

test/suite/functional/ConfigurationBuilder.php

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ConfigurationBuilder
1313
private string $codeStyleConfig;
1414
private string $packageName;
1515
private string $phpVersion;
16+
private string $generatorVersion;
1617
private string $composerJsonTemplateDir;
1718
private string $readmeMdTemplateDir;
1819
private string $httpMessage;
@@ -27,6 +28,7 @@ private function __construct()
2728
$this->codeStyleConfig = __DIR__ . '/../../../.php_cs.php';
2829
$this->packageName = 'test/test-api-client';
2930
$this->phpVersion = Configuration::DEFAULT_PHP_VERSION;
31+
$this->generatorVersion = '5.6.0';
3032
$this->composerJsonTemplateDir = Configuration::DEFAULT_TEMPLATE_DIRECTORY;
3133
$this->readmeMdTemplateDir = Configuration::DEFAULT_TEMPLATE_DIRECTORY;
3234
$this->httpMessage = Configuration::DEFAULT_HTTP_MESSAGE;
@@ -125,6 +127,7 @@ public function build(): Configuration
125127
$this->codeStyleConfig,
126128
$this->packageName,
127129
$this->phpVersion,
130+
$this->generatorVersion,
128131
$this->composerJsonTemplateDir,
129132
$this->readmeMdTemplateDir,
130133
$this->httpMessage,

test/suite/functional/Meta/ReadmeMd/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ docker run -it \
1212
-e OUTPUT_DIR=/client \
1313
-e PACKAGE=test/test-api-client \
1414
-e CLIENT_PHP_VERSION=7.4 \
15-
dhlabs/api-client-generator
15+
dhlabs/api-client-generator:5.6.0
1616
```
1717

1818
## Usage

test/suite/unit/Input/ConfigurationTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function testValidConfiguration(
2121
string $codeStyleConfig,
2222
string $packageName,
2323
string $phpVersion,
24+
string $generatorVersion,
2425
string $composerJsonTemplateDir,
2526
string $readmeMdTemplateDir,
2627
string $httpMessage,
@@ -34,6 +35,7 @@ public function testValidConfiguration(
3435
$codeStyleConfig,
3536
$packageName,
3637
$phpVersion,
38+
$generatorVersion,
3739
$composerJsonTemplateDir,
3840
$readmeMdTemplateDir,
3941
$httpMessage,
@@ -47,6 +49,7 @@ public function testValidConfiguration(
4749
self::assertEquals($codeStyleConfig, $sut->getCodeStyleConfig());
4850
self::assertEquals($packageName, $sut->getPackageName());
4951
self::assertEquals($phpVersion, $sut->getPhpVersion());
52+
self::assertEquals($generatorVersion, $sut->getGeneratorVersion());
5053
self::assertEquals($composerJsonTemplateDir, $sut->getComposerJsonTemplateDir());
5154
self::assertEquals($readmeMdTemplateDir, $sut->getReadmeMdTemplateDir());
5255
self::assertEquals($httpMessage, $sut->getHttpMessage());
@@ -64,6 +67,7 @@ public function validConfigurationOptions(): array
6467
'/dir/.php_cs.php',
6568
'test/test-api-client',
6669
'7.1',
70+
'5.6.0',
6771
__DIR__,
6872
__DIR__,
6973
Configuration::DEFAULT_HTTP_MESSAGE,

0 commit comments

Comments
 (0)