Skip to content

Commit 1c52109

Browse files
committed
Update to use php-json-schema-model-generator-production
1 parent 7d768df commit 1c52109

31 files changed

+66
-48
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ Simple example from a PHP application: you define and document an API with swagg
3636
The recommended way to install php-json-schema-model-generator is through [Composer](http://getcomposer.org):
3737
```
3838
$ composer require --dev wol-soft/php-json-schema-model-generator
39-
$ composer require wol-soft/php-json-schema-model-generator-exception
39+
$ composer require wol-soft/php-json-schema-model-generator-production
4040
```
41-
To avoid adding all dependencies of the php-json-schema-model-generator to your production dependencies it's recommended to add the library as a dev-dependency and include the php-json-schema-model-generator-exception library. The exception library provides all classes to run the generated code. Generating the classes should either be a step done in the development environment (if you decide to commit the models) or as a build step of your application.
41+
To avoid adding all dependencies of the php-json-schema-model-generator to your production dependencies it's recommended to add the library as a dev-dependency and include the php-json-schema-model-generator-production library. The exception library provides all classes to run the generated code. Generating the classes should either be a step done in the development environment (if you decide to commit the models) or as a build step of your application.
4242

4343
## Basic usage ##
4444

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
],
1313
"require": {
1414
"symplify/easy-coding-standard": "^6.0.4",
15-
"wol-soft/php-json-schema-model-generator-exception": "^0.1.0",
15+
"wol-soft/php-json-schema-model-generator-production": "^0.4.0",
1616
"wol-soft/php-micro-template": "^1.3.1",
17+
1718
"php": ">=7.2",
1819
"ext-json": "*",
1920
"ext-mbstring": "*"

docs/source/gettingStarted.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The recommended way to install php-json-model-generator is through `Composer <ht
99
.. code-block:: rconsole
1010
1111
composer require --dev wol-soft/php-json-schema-model-generator
12-
composer require wol-soft/php-json-schema-model-generator-exception
12+
composer require wol-soft/php-json-schema-model-generator-production
1313
1414
To avoid adding all dependencies of the php-json-model-generator to your production dependencies it's recommended to add the library as a dev-dependency and include the php-json-model-generator-exception library. The exception library provides all classes to run the generated code. Generating the classes should either be a step done in the development environment (if you decide to commit the models) or as a build step of your application.
1515

@@ -150,10 +150,10 @@ Collect errors vs. early return
150150
151151
By default the complete input is validated and in case of failing validations all error messages will be thrown in a single exception implementing the ErrorRegistryExceptionInterface interface. If set to false the first failing validation will throw an exception.
152152

153-
The exceptions are implemented in the php-json-schema-model-generator-exception repository. Default exceptions:
153+
The exceptions are implemented in the php-json-schema-model-generator-production repository. Default exceptions:
154154

155-
* Error collection enabled: **PHPModelGeneratorException\ErrorRegistryException**
156-
* Error collection disabled: **PHPModelGeneratorException\ValidationException**
155+
* Error collection enabled: **PHPModelGenerator\\Exception\\ErrorRegistryException**
156+
* Error collection disabled: **PHPModelGenerator\\Exception\\ValidationException**
157157

158158
.. code-block:: php
159159
@@ -210,6 +210,8 @@ Generated interface:
210210
public function toArray(): array;
211211
public function toJSON(): string;
212212
213+
The generated class will implement the interface **PHPModelGenerator\\Interfaces\\SerializationInterface** implemented in the php-json-schema-model-generator-production repository. This interface can be used to write additional generic modules to handle the generated models.
214+
213215
Output generation process
214216
^^^^^^^^^^^^^^^^^^^^^^^^^
215217

src/Exception/PHPModelGeneratorException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Exception;
88

99
/**
10-
* Class PHPModelGeneratorException
10+
* Class PHPModelGenerator\Exception
1111
*
1212
* @package PHPModelGenerator\Exception
1313
*/

src/Model/GeneratorConfiguration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use PHPModelGenerator\Utils\ClassNameGenerator;
88
use PHPModelGenerator\Utils\ClassNameGeneratorInterface;
9-
use PHPModelGeneratorException\ErrorRegistryException;
10-
use PHPModelGeneratorException\ValidationException;
9+
use PHPModelGenerator\Exception\ErrorRegistryException;
10+
use PHPModelGenerator\Exception\ValidationException;
1111

1212
/**
1313
* Class GeneratorConfiguration

src/Model/Schema.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ public function addProperty(PropertyInterface $property): self
8181
{
8282
if (!isset($this->properties[$property->getName()])) {
8383
$this->properties[$property->getName()] = $property;
84+
} else {
85+
// TODO tests:
86+
// testConditionalObjectProperty
87+
// testInvalidConditionalObjectPropertyThrowsAnException
88+
// testInvalidValuesForMultipleValuesInCompositionThrowsAnException
89+
// throw new SchemaException("Duplicate attribute name {$property->getName()}");
8490
}
8591

8692
return $this;

src/Model/SchemaDefinition/SchemaDefinition.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PHPModelGenerator\Model\SchemaDefinition;
66

7-
use PHPModelGenerator\Exception\PHPModelGeneratorException;
7+
use PHPModelGenerator\Exception\PHPModelGenerator\Exception;
88
use PHPModelGenerator\Exception\SchemaException;
99
use PHPModelGenerator\Model\Property\PropertyInterface;
1010
use PHPModelGenerator\Model\Property\PropertyProxy;
@@ -65,7 +65,7 @@ public function getSchema(): Schema
6565
*
6666
* @return PropertyInterface
6767
*
68-
* @throws PHPModelGeneratorException
68+
* @throws PHPModelGenerator\Exception
6969
* @throws SchemaException
7070
*/
7171
public function resolveReference(
@@ -100,7 +100,7 @@ public function resolveReference(
100100
$structure
101101
)
102102
);
103-
} catch (PHPModelGeneratorException $exception) {
103+
} catch (PHPModelGenerator\Exception $exception) {
104104
$this->resolvedPaths->offsetUnset($key);
105105
throw $exception;
106106
}

src/Templates/Exception/ComposedValueException.phptpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Invalid value for {{ propertyName }} declined by composition constraint.\n"
22
. sprintf(' {{ composedErrorMessage }}', $succeededCompositionElements)
33
. array_reduce(
44
$compositionErrorCollection,
5-
function (string $carry, \PHPModelGeneratorException\ErrorRegistryExceptionInterface $exception) use (&$i) {
5+
function (string $carry, \PHPModelGenerator\Exception\ErrorRegistryExceptionInterface $exception) use (&$i) {
66
return "$carry\n - Composition element #" . ++$i . (
77
$exception->getErrors()
88
? ": Failed\n * " . implode("\n * ", $exception->getErrors())

src/Templates/Model.phptpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ declare(strict_types = 1);
1717
{% if namespace %} * @package {{ namespace }} {% endif %}
1818
*/
1919
class {{ class }}
20+
{% if generatorConfiguration.hasSerializationEnabled() %}implements PHPModelGenerator\Interfaces\SerializationInterface{% endif %}
2021
{
2122
{% foreach properties as property %}
2223
/** @var {{ property.getTypeHint() }}{% if property.getDescription() %} {{ property.getDescription() }}{% endif %} */

tests/AbstractPHPModelGeneratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
use FilesystemIterator;
66
use PHPModelGenerator\Utils\ClassNameGenerator;
7-
use PHPModelGeneratorException\ErrorRegistryException;
7+
use PHPModelGenerator\Exception\ErrorRegistryException;
88
use PHPModelGenerator\Exception\FileSystemException;
99
use PHPModelGenerator\Exception\RenderException;
1010
use PHPModelGenerator\Exception\SchemaException;
11-
use PHPModelGeneratorException\ValidationException;
11+
use PHPModelGenerator\Exception\ValidationException;
1212
use PHPModelGenerator\ModelGenerator;
1313
use PHPModelGenerator\Model\GeneratorConfiguration;
1414
use PHPUnit\Framework\TestCase;

tests/Basic/AdditionalPropertiesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPModelGenerator\Tests\Basic;
44

55
use PHPModelGenerator\Model\GeneratorConfiguration;
6-
use PHPModelGeneratorException\ValidationException;
6+
use PHPModelGenerator\Exception\ValidationException;
77
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
88
use stdClass;
99

tests/Basic/BasicSchemaGenerationTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPModelGenerator\Exception\FileSystemException;
66
use PHPModelGenerator\Exception\SchemaException;
7+
use PHPModelGenerator\Interfaces\SerializationInterface;
78
use PHPModelGenerator\Model\GeneratorConfiguration;
89
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
910

@@ -74,6 +75,8 @@ public function testSerializationFunctionsAreNotGeneratedByDefault(): void
7475

7576
$this->assertFalse(is_callable([$object, 'toArray']));
7677
$this->assertFalse(is_callable([$object, 'toJSON']));
78+
79+
$this->assertFalse($object instanceof SerializationInterface);
7780
}
7881

7982
public function testSerializationFunctionsAreGeneratedWithEnabledSerialization(): void
@@ -87,6 +90,8 @@ public function testSerializationFunctionsAreGeneratedWithEnabledSerialization()
8790

8891
$this->assertEquals(['property' => 'Hello'], $object->toArray());
8992
$this->assertEquals('{"property":"Hello"}', $object->toJSON());
93+
94+
$this->assertTrue($object instanceof SerializationInterface);
9095
}
9196

9297
/**

tests/Basic/ErrorCollectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PHPModelGenerator\Model\GeneratorConfiguration;
88
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
9-
use PHPModelGeneratorException\ErrorRegistryException;
9+
use PHPModelGenerator\Exception\ErrorRegistryException;
1010
use stdClass;
1111

1212
/**

tests/Basic/ObjectSizeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PHPModelGenerator\Tests\Basic;
44

5-
use PHPModelGeneratorException\ValidationException;
5+
use PHPModelGenerator\Exception\ValidationException;
66
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
77

88
/**

tests/ComposedValue/ComposedAllOfTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PHPModelGenerator\Tests\ComposedValue;
44

5-
use PHPModelGeneratorException\ValidationException;
5+
use PHPModelGenerator\Exception\ValidationException;
66
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
77
use stdClass;
88

tests/ComposedValue/ComposedAnyOfTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PHPModelGenerator\Tests\ComposedValue;
44

5-
use PHPModelGeneratorException\ValidationException;
5+
use PHPModelGenerator\Exception\ValidationException;
66
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
77
use stdClass;
88

tests/ComposedValue/ComposedNotTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PHPModelGenerator\Exception\SchemaException;
88
use PHPModelGenerator\Model\GeneratorConfiguration;
99
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
10-
use PHPModelGeneratorException\ValidationException;
10+
use PHPModelGenerator\Exception\ValidationException;
1111
use stdClass;
1212

1313
/**

tests/ComposedValue/ComposedOneOfTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPModelGenerator\Tests\ComposedValue;
44

55
use PHPModelGenerator\Model\GeneratorConfiguration;
6-
use PHPModelGeneratorException\ValidationException;
6+
use PHPModelGenerator\Exception\ValidationException;
77
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
88
use stdClass;
99

tests/Objects/AbstractNumericPropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PHPModelGenerator\Tests\Objects;
44

5-
use PHPModelGeneratorException\ValidationException;
5+
use PHPModelGenerator\Exception\ValidationException;
66
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
77

88
/**

tests/Objects/BooleanPropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPModelGenerator\Tests\Objects;
44

55
use PHPModelGenerator\Exception\FileSystemException;
6-
use PHPModelGeneratorException\ValidationException;
6+
use PHPModelGenerator\Exception\ValidationException;
77
use PHPModelGenerator\Exception\RenderException;
88
use PHPModelGenerator\Exception\SchemaException;
99
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;

tests/Objects/ConstPropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPModelGenerator\Tests\Objects;
44

55
use PHPModelGenerator\Exception\FileSystemException;
6-
use PHPModelGeneratorException\ValidationException;
6+
use PHPModelGenerator\Exception\ValidationException;
77
use PHPModelGenerator\Exception\RenderException;
88
use PHPModelGenerator\Exception\SchemaException;
99
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;

tests/Objects/EnumPropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPModelGenerator\Tests\Objects;
44

55
use PHPModelGenerator\Exception\FileSystemException;
6-
use PHPModelGeneratorException\ValidationException;
6+
use PHPModelGenerator\Exception\ValidationException;
77
use PHPModelGenerator\Exception\RenderException;
88
use PHPModelGenerator\Exception\SchemaException;
99
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;

tests/Objects/IntegerPropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPModelGenerator\Tests\Objects;
44

55
use PHPModelGenerator\Exception\FileSystemException;
6-
use PHPModelGeneratorException\ValidationException;
6+
use PHPModelGenerator\Exception\ValidationException;
77
use PHPModelGenerator\Exception\RenderException;
88
use PHPModelGenerator\Exception\SchemaException;
99
use stdClass;

tests/Objects/MultiTypePropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PHPModelGenerator\Exception\RenderException;
77
use PHPModelGenerator\Exception\SchemaException;
88
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
9-
use PHPModelGeneratorException\ValidationException;
9+
use PHPModelGenerator\Exception\ValidationException;
1010
use stdClass;
1111

1212
/**

tests/Objects/NullPropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPModelGenerator\Tests\Objects;
44

55
use PHPModelGenerator\Exception\FileSystemException;
6-
use PHPModelGeneratorException\ValidationException;
6+
use PHPModelGenerator\Exception\ValidationException;
77
use PHPModelGenerator\Exception\RenderException;
88
use PHPModelGenerator\Exception\SchemaException;
99
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;

tests/Objects/NumberPropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPModelGenerator\Tests\Objects;
44

55
use PHPModelGenerator\Exception\FileSystemException;
6-
use PHPModelGeneratorException\ValidationException;
6+
use PHPModelGenerator\Exception\ValidationException;
77
use PHPModelGenerator\Exception\RenderException;
88
use PHPModelGenerator\Exception\SchemaException;
99
use stdClass;

tests/Objects/ObjectPropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPModelGenerator\Tests\Objects;
44

55
use PHPModelGenerator\Exception\FileSystemException;
6-
use PHPModelGeneratorException\ValidationException;
6+
use PHPModelGenerator\Exception\ValidationException;
77
use PHPModelGenerator\Exception\RenderException;
88
use PHPModelGenerator\Exception\SchemaException;
99
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;

tests/Objects/ReferencePropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPModelGenerator\Tests\Objects;
44

55
use PHPModelGenerator\Exception\FileSystemException;
6-
use PHPModelGeneratorException\ValidationException;
6+
use PHPModelGenerator\Exception\ValidationException;
77
use PHPModelGenerator\Exception\RenderException;
88
use PHPModelGenerator\Exception\SchemaException;
99
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;

tests/Objects/RequiredPropertyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace PHPModelGenerator\Tests\Basic;
44

55
use PHPModelGenerator\Exception\FileSystemException;
6-
use PHPModelGeneratorException\ValidationException;
6+
use PHPModelGenerator\Exception\ValidationException;
77
use PHPModelGenerator\Exception\RenderException;
88
use PHPModelGenerator\Exception\SchemaException;
99
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;

tests/manual/schema/person.json

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
{
2-
"id": "Person",
2+
"$id": "example",
33
"type": "object",
44
"properties": {
5-
"name": {
6-
"type": "string",
7-
"description": "The name of the person",
8-
"example": "Lawrence"
9-
},
10-
"age": {
11-
"type": "integer",
12-
"description": "The age of the person",
13-
"example": 42
5+
"example": {
6+
"allOf": [
7+
{
8+
"type": "number",
9+
"multipleOf": 5
10+
},
11+
{
12+
"type": "number",
13+
"multipleOf": 3
14+
}
15+
]
1416
}
15-
},
16-
"required": [
17-
"name"
18-
]
17+
}
1918
}

tests/manual/test.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
$generator
1515
->generateModelDirectory(__DIR__ . '/result')
1616
->generateModels(__DIR__ . '/schema', __DIR__ . '/result');
17+
18+
require_once __DIR__ . '/result/Example.php';
19+
20+
new ManualSchema\Example(['example' => 5]);

0 commit comments

Comments
 (0)