diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1698a6f..3db924b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [1.11.1] - 2022-11-14
+
+### Fixed
+- Handling of `*Of` in PHP generation.
+
## [1.11.0] - 2022-09-18
### Added
@@ -218,6 +223,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Local file resolver in references.
+[1.11.1]: https://github.com/swaggest/json-cli/compare/v1.10.1...v1.11.1
[1.11.0]: https://github.com/swaggest/json-cli/compare/v1.10.0...v1.11.0
[1.10.0]: https://github.com/swaggest/json-cli/compare/v1.9.1...v1.10.0
[1.9.1]: https://github.com/swaggest/json-cli/compare/v1.9.0...v1.9.1
diff --git a/composer.json b/composer.json
index 91cd8d8..08c6279 100644
--- a/composer.json
+++ b/composer.json
@@ -17,12 +17,12 @@
"salsify/json-streaming-parser": "^7.0",
"swaggest/json-schema": "^0.12.41",
"swaggest/go-code-builder": "0.4.51",
- "swaggest/php-code-builder": "^0.2.37",
+ "swaggest/php-code-builder": "^0.2.38",
"swaggest/code-builder": "^0.3.5",
"swaggest/json-schema-maker": "^0.3.7"
},
"require-dev": {
- "phperf/phpunit": "4.8.37"
+ "phperf/phpunit": "4.8.38"
},
"autoload": {
"psr-4": {
diff --git a/composer.lock b/composer.lock
index 5cad22a..7319ea5 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "cd728febd6af031ef0d87e8508d225e8",
+ "content-hash": "b2ae2df3901d2dafef3c1c97e2b23ecb",
"packages": [
{
"name": "php-yaoi/php-yaoi",
@@ -321,16 +321,16 @@
},
{
"name": "swaggest/json-diff",
- "version": "v3.9.0",
+ "version": "v3.10.4",
"source": {
"type": "git",
"url": "https://github.com/swaggest/json-diff.git",
- "reference": "ff3a7921e9f1aa096067eb541fcfd0e7611c558c"
+ "reference": "f4e511708060ff7511a3743fab4aa484a062bcfb"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/swaggest/json-diff/zipball/ff3a7921e9f1aa096067eb541fcfd0e7611c558c",
- "reference": "ff3a7921e9f1aa096067eb541fcfd0e7611c558c",
+ "url": "https://api.github.com/repos/swaggest/json-diff/zipball/f4e511708060ff7511a3743fab4aa484a062bcfb",
+ "reference": "f4e511708060ff7511a3743fab4aa484a062bcfb",
"shasum": ""
},
"require": {
@@ -358,9 +358,9 @@
"description": "JSON diff/rearrange/patch/pointer library for PHP",
"support": {
"issues": "https://github.com/swaggest/json-diff/issues",
- "source": "https://github.com/swaggest/json-diff/tree/v3.9.0"
+ "source": "https://github.com/swaggest/json-diff/tree/v3.10.4"
},
- "time": "2022-08-29T15:04:08+00:00"
+ "time": "2022-11-09T13:21:05+00:00"
},
{
"name": "swaggest/json-schema",
@@ -465,16 +465,16 @@
},
{
"name": "swaggest/php-code-builder",
- "version": "v0.2.37",
+ "version": "v0.2.38",
"source": {
"type": "git",
"url": "https://github.com/swaggest/php-code-builder.git",
- "reference": "fc0f412529d0cbc969487628a9023154ca2f74f0"
+ "reference": "7720eb5ffae2e33937688066ee5aab83476b907a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/swaggest/php-code-builder/zipball/fc0f412529d0cbc969487628a9023154ca2f74f0",
- "reference": "fc0f412529d0cbc969487628a9023154ca2f74f0",
+ "url": "https://api.github.com/repos/swaggest/php-code-builder/zipball/7720eb5ffae2e33937688066ee5aab83476b907a",
+ "reference": "7720eb5ffae2e33937688066ee5aab83476b907a",
"shasum": ""
},
"require": {
@@ -484,7 +484,7 @@
"swaggest/json-schema": "^0.12.33"
},
"require-dev": {
- "phperf/phpunit": "4.8.37"
+ "phperf/phpunit": "4.8.38"
},
"type": "library",
"autoload": {
@@ -510,9 +510,9 @@
],
"support": {
"issues": "https://github.com/swaggest/php-code-builder/issues",
- "source": "https://github.com/swaggest/php-code-builder/tree/v0.2.37"
+ "source": "https://github.com/swaggest/php-code-builder/tree/v0.2.38"
},
- "time": "2022-09-15T23:10:34+00:00"
+ "time": "2022-11-14T19:24:11+00:00"
},
{
"name": "symfony/polyfill-ctype",
@@ -964,16 +964,16 @@
},
{
"name": "phperf/phpunit",
- "version": "4.8.37",
+ "version": "4.8.38",
"source": {
"type": "git",
"url": "https://github.com/phperf/phpunit.git",
- "reference": "172e60fa83313e0a5385bb7cfbd390cf6dedf37c"
+ "reference": "34de0591973c2603bae61514070e7861a1966776"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phperf/phpunit/zipball/172e60fa83313e0a5385bb7cfbd390cf6dedf37c",
- "reference": "172e60fa83313e0a5385bb7cfbd390cf6dedf37c",
+ "url": "https://api.github.com/repos/phperf/phpunit/zipball/34de0591973c2603bae61514070e7861a1966776",
+ "reference": "34de0591973c2603bae61514070e7861a1966776",
"shasum": ""
},
"require": {
@@ -1039,9 +1039,9 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
- "source": "https://github.com/phperf/phpunit/tree/4.8.37"
+ "source": "https://github.com/phperf/phpunit/tree/4.8.38"
},
- "time": "2022-01-23T22:14:49+00:00"
+ "time": "2022-04-28T19:15:24+00:00"
},
{
"name": "phpspec/prophecy",
diff --git a/src/App.php b/src/App.php
index f5e3f90..2b23585 100644
--- a/src/App.php
+++ b/src/App.php
@@ -7,7 +7,7 @@
class App extends Command\Application
{
- public static $ver = 'v1.11.0';
+ public static $ver = 'v1.11.1';
public $diff;
public $apply;
diff --git a/src/GenPhp.php b/src/GenPhp.php
index 9007910..5f45c3e 100644
--- a/src/GenPhp.php
+++ b/src/GenPhp.php
@@ -40,7 +40,7 @@ public static function setUpDefinition(Command\Definition $definition, $options)
->setIsRequired();
$options->rootName = Command\Option::create()->setType()
- ->setDescription('Go root struct name, default "Structure", only used for # pointer');
+ ->setDescription('Root class name, default "Structure", only used for # pointer');
static::setupBuilderOptions($options);
Base::setupGenOptions($definition, $options);
diff --git a/tests/assets/issue39.json b/tests/assets/issue39.json
new file mode 100644
index 0000000..54d0fca
--- /dev/null
+++ b/tests/assets/issue39.json
@@ -0,0 +1,58 @@
+{
+ "id": "/Test",
+ "type": "object",
+ "properties": {
+ "label": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "number"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "test1": {
+ "type": "string"
+ }
+ }
+ },
+ {
+ "type": "object",
+ "properties": {
+ "test2": {
+ "type": "string"
+ }
+ }
+ }
+ ]
+ },
+ "label2": {
+ "oneOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "number"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "test1": {
+ "type": "string"
+ }
+ }
+ },
+ {
+ "type": "object",
+ "properties": {
+ "test2": {
+ "type": "string"
+ }
+ }
+ }
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/assets/issue39_2.json b/tests/assets/issue39_2.json
new file mode 100644
index 0000000..e776b50
--- /dev/null
+++ b/tests/assets/issue39_2.json
@@ -0,0 +1,21 @@
+{
+ "id": "/Test",
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "test1": {
+ "type": "string"
+ }
+ }
+ },
+ {
+ "type": "object",
+ "properties": {
+ "test2": {
+ "type": "integer"
+ }
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/tests/assets/markdown/issue39/entities.md b/tests/assets/markdown/issue39/entities.md
new file mode 100644
index 0000000..2fe50f6
--- /dev/null
+++ b/tests/assets/markdown/issue39/entities.md
@@ -0,0 +1,55 @@
+# Types
+
+ * [`Label2OneOf2`](#label2oneof2)
+ * [`Label2OneOf3`](#label2oneof3)
+ * [`LabelAnyOf2`](#labelanyof2)
+ * [`LabelAnyOf3`](#labelanyof3)
+ * [`Propertyb14a7b`](#propertyb14a7b)
+
+
+
+
+### Label2OneOf2
+
+
+
+|Property|Type |
+|--------|--------|
+|`test1` |`String`|
+
+
+### Label2OneOf3
+
+
+
+|Property|Type |
+|--------|--------|
+|`test2` |`String`|
+
+
+### LabelAnyOf2
+
+
+
+|Property|Type |
+|--------|--------|
+|`test1` |`String`|
+
+
+### LabelAnyOf3
+
+
+
+|Property|Type |
+|--------|--------|
+|`test2` |`String`|
+
+
+### Propertyb14a7b
+
+
+
+|Property|Type |
+|--------|------------------------------------------------------------------------------------|
+|`label` |`Number`, `Number`, [`LabelAnyOf2`](#labelanyof2), [`LabelAnyOf3`](#labelanyof3) |
+|`label2`|`Number`, `Number`, [`Label2OneOf2`](#label2oneof2), [`Label2OneOf3`](#label2oneof3)|
diff --git a/tests/assets/markdown/issue39/entities2.md b/tests/assets/markdown/issue39/entities2.md
new file mode 100644
index 0000000..ceebbbf
--- /dev/null
+++ b/tests/assets/markdown/issue39/entities2.md
@@ -0,0 +1,24 @@
+# Types
+
+ * [`AnyOf0`](#anyof0)
+ * [`AnyOf1`](#anyof1)
+
+
+
+
+### AnyOf0
+
+
+
+|Property|Type |
+|--------|--------|
+|`test1` |`String`|
+
+
+### AnyOf1
+
+
+
+|Property|Type |
+|--------|--------|
+|`test2` |`Number`|
diff --git a/tests/assets/php/AsyncAPI/Operation.php b/tests/assets/php/AsyncAPI/OperationOneOf1.php
similarity index 98%
rename from tests/assets/php/AsyncAPI/Operation.php
rename to tests/assets/php/AsyncAPI/OperationOneOf1.php
index d0dee0e..d7f17cd 100644
--- a/tests/assets/php/AsyncAPI/Operation.php
+++ b/tests/assets/php/AsyncAPI/OperationOneOf1.php
@@ -14,7 +14,7 @@
use Swaggest\JsonSchema\Structure\ClassStructure;
-class Operation extends ClassStructure
+class OperationOneOf1 extends ClassStructure
{
const X_PROPERTY_PATTERN = '^x-';
diff --git a/tests/assets/php/AsyncAPI/Stream.php b/tests/assets/php/AsyncAPI/Stream.php
index 4d1cf98..30b782b 100644
--- a/tests/assets/php/AsyncAPI/Stream.php
+++ b/tests/assets/php/AsyncAPI/Stream.php
@@ -22,7 +22,7 @@ class Stream extends ClassStructure
{
const X_PROPERTY_PATTERN = '^x-';
- /** @var StreamFraming */
+ /** @var StreamFramingOneOf0|StreamFramingOneOf1 */
public $framing;
/** @var Message[]|array */
@@ -44,8 +44,8 @@ public static function setUpProperties($properties, Schema $ownerSchema)
$x->description = "Any property starting with x- is valid.";
$x->setFromRef('#/definitions/vendorExtension');
$properties->framing->setPatternProperty('^x-', $x);
- $properties->framing->oneOf[0] = StreamFraming::schema();
- $properties->framing->oneOf[1] = StreamFraming::schema();
+ $properties->framing->oneOf[0] = StreamFramingOneOf0::schema();
+ $properties->framing->oneOf[1] = StreamFramingOneOf1::schema();
$properties->framing->title = "Stream Framing Object";
$properties->framing->minProperties = 1;
$properties->read = Schema::arr();
diff --git a/tests/assets/php/AsyncAPI/StreamFramingOneOf0.php b/tests/assets/php/AsyncAPI/StreamFramingOneOf0.php
new file mode 100644
index 0000000..eb80ac3
--- /dev/null
+++ b/tests/assets/php/AsyncAPI/StreamFramingOneOf0.php
@@ -0,0 +1,46 @@
+type = Schema::string();
+ $properties->type->enum = array(
+ self::CHUNKED,
+ );
+ $properties->delimiter = Schema::string();
+ $properties->delimiter->enum = array(
+ self::R_N,
+ self::N,
+ );
+ $properties->delimiter->default = "\\r\\n";
+ $ownerSchema->additionalProperties = false;
+ }
+}
\ No newline at end of file
diff --git a/tests/assets/php/AsyncAPI/StreamFraming.php b/tests/assets/php/AsyncAPI/StreamFramingOneOf1.php
similarity index 95%
rename from tests/assets/php/AsyncAPI/StreamFraming.php
rename to tests/assets/php/AsyncAPI/StreamFramingOneOf1.php
index 3fb3ac3..35f2f25 100644
--- a/tests/assets/php/AsyncAPI/StreamFraming.php
+++ b/tests/assets/php/AsyncAPI/StreamFramingOneOf1.php
@@ -11,7 +11,7 @@
use Swaggest\JsonSchema\Structure\ClassStructure;
-class StreamFraming extends ClassStructure
+class StreamFramingOneOf1 extends ClassStructure
{
const SSE = 'sse';
diff --git a/tests/assets/php/AsyncAPI/TopicItem.php b/tests/assets/php/AsyncAPI/TopicItem.php
index 8360ceb..a72d5df 100644
--- a/tests/assets/php/AsyncAPI/TopicItem.php
+++ b/tests/assets/php/AsyncAPI/TopicItem.php
@@ -27,10 +27,10 @@ class TopicItem extends ClassStructure
/** @var Parameter[]|array */
public $parameters;
- /** @var Message|Operation */
+ /** @var Message|OperationOneOf1 */
public $publish;
- /** @var Message|Operation */
+ /** @var Message|OperationOneOf1 */
public $subscribe;
/** @var bool */
@@ -50,11 +50,11 @@ public static function setUpProperties($properties, Schema $ownerSchema)
$properties->parameters->uniqueItems = true;
$properties->publish = new Schema();
$properties->publish->oneOf[0] = Message::schema();
- $properties->publish->oneOf[1] = Operation::schema();
+ $properties->publish->oneOf[1] = OperationOneOf1::schema();
$properties->publish->setFromRef('#/definitions/operation');
$properties->subscribe = new Schema();
$properties->subscribe->oneOf[0] = Message::schema();
- $properties->subscribe->oneOf[1] = Operation::schema();
+ $properties->subscribe->oneOf[1] = OperationOneOf1::schema();
$properties->subscribe->setFromRef('#/definitions/operation');
$properties->deprecated = Schema::boolean();
$properties->deprecated->default = false;
diff --git a/tests/assets/php/Issue39/Label2OneOf2.php b/tests/assets/php/Issue39/Label2OneOf2.php
new file mode 100644
index 0000000..1c57635
--- /dev/null
+++ b/tests/assets/php/Issue39/Label2OneOf2.php
@@ -0,0 +1,28 @@
+test1 = Schema::string();
+ $ownerSchema->type = Schema::OBJECT;
+ }
+}
\ No newline at end of file
diff --git a/tests/assets/php/Issue39/Label2OneOf3.php b/tests/assets/php/Issue39/Label2OneOf3.php
new file mode 100644
index 0000000..9565d57
--- /dev/null
+++ b/tests/assets/php/Issue39/Label2OneOf3.php
@@ -0,0 +1,28 @@
+test2 = Schema::string();
+ $ownerSchema->type = Schema::OBJECT;
+ }
+}
\ No newline at end of file
diff --git a/tests/assets/php/Issue39/LabelAnyOf2.php b/tests/assets/php/Issue39/LabelAnyOf2.php
new file mode 100644
index 0000000..4cf0e41
--- /dev/null
+++ b/tests/assets/php/Issue39/LabelAnyOf2.php
@@ -0,0 +1,28 @@
+test1 = Schema::string();
+ $ownerSchema->type = Schema::OBJECT;
+ }
+}
\ No newline at end of file
diff --git a/tests/assets/php/Issue39/LabelAnyOf3.php b/tests/assets/php/Issue39/LabelAnyOf3.php
new file mode 100644
index 0000000..86f366b
--- /dev/null
+++ b/tests/assets/php/Issue39/LabelAnyOf3.php
@@ -0,0 +1,28 @@
+test2 = Schema::string();
+ $ownerSchema->type = Schema::OBJECT;
+ }
+}
\ No newline at end of file
diff --git a/tests/assets/php/Issue39/Structure.php b/tests/assets/php/Issue39/Structure.php
new file mode 100644
index 0000000..4276db0
--- /dev/null
+++ b/tests/assets/php/Issue39/Structure.php
@@ -0,0 +1,41 @@
+label = new Schema();
+ $properties->label->anyOf[0] = Schema::integer();
+ $properties->label->anyOf[1] = Schema::number();
+ $properties->label->anyOf[2] = LabelAnyOf2::schema();
+ $properties->label->anyOf[3] = LabelAnyOf3::schema();
+ $properties->label2 = new Schema();
+ $properties->label2->oneOf[0] = Schema::integer();
+ $properties->label2->oneOf[1] = Schema::number();
+ $properties->label2->oneOf[2] = Label2OneOf2::schema();
+ $properties->label2->oneOf[3] = Label2OneOf3::schema();
+ $ownerSchema->type = Schema::OBJECT;
+ $ownerSchema->id = "/Test";
+ }
+}
\ No newline at end of file
diff --git a/tests/assets/php/Issue39_2/AnyOf0.php b/tests/assets/php/Issue39_2/AnyOf0.php
new file mode 100644
index 0000000..729399c
--- /dev/null
+++ b/tests/assets/php/Issue39_2/AnyOf0.php
@@ -0,0 +1,28 @@
+test1 = Schema::string();
+ $ownerSchema->type = Schema::OBJECT;
+ }
+}
\ No newline at end of file
diff --git a/tests/assets/php/Issue39_2/AnyOf1.php b/tests/assets/php/Issue39_2/AnyOf1.php
new file mode 100644
index 0000000..a6dfd92
--- /dev/null
+++ b/tests/assets/php/Issue39_2/AnyOf1.php
@@ -0,0 +1,28 @@
+test2 = Schema::integer();
+ $ownerSchema->type = Schema::OBJECT;
+ }
+}
\ No newline at end of file
diff --git a/tests/src/GenMarkdownTest.php b/tests/src/GenMarkdownTest.php
index 977ef52..ce0545e 100644
--- a/tests/src/GenMarkdownTest.php
+++ b/tests/src/GenMarkdownTest.php
@@ -85,4 +85,41 @@ public function testAsyncAPIStreetLights()
}
+
+ public function testIssue39()
+ {
+ $d = new GenMarkdown();
+ $d->schema = __DIR__ . '/../../tests/assets/issue39.json';
+
+ $d->setResponse(new Response());
+ ob_start();
+ $d->performAction();
+ $res = ob_get_clean();
+
+ $this->assertSame(
+ str_replace('', App::$ver,
+ file_get_contents(__DIR__ . '/../../tests/assets/markdown/issue39/entities.md')),
+ $res
+ );
+
+ }
+
+ public function testIssue39_2()
+ {
+ $d = new GenMarkdown();
+ $d->schema = __DIR__ . '/../../tests/assets/issue39_2.json';
+
+ $d->setResponse(new Response());
+ ob_start();
+ $d->performAction();
+ $res = ob_get_clean();
+
+ $this->assertSame(
+ str_replace('', App::$ver,
+ file_get_contents(__DIR__ . '/../../tests/assets/markdown/issue39/entities2.md')),
+ $res
+ );
+
+ }
+
}
\ No newline at end of file
diff --git a/tests/src/GenPhpTest.php b/tests/src/GenPhpTest.php
index 47f479e..ffaac17 100644
--- a/tests/src/GenPhpTest.php
+++ b/tests/src/GenPhpTest.php
@@ -92,4 +92,50 @@ public function testAsyncAPIStreetLights()
$this->assertSame('', $out, "Generated files changed");
}
+ function testIssue39() {
+ $d = new GenPhp();
+ $d->schema = __DIR__ . '/../../tests/assets/issue39.json';
+ $d->ns = 'Issue39';
+ $d->nsPath = __DIR__ . '/../assets/php/Issue39';
+
+ $d->setResponse(new Response());
+ ob_start();
+ try {
+ $d->performAction();
+ } catch (ExitCode $exception) {
+ $res = ob_get_clean();
+ $this->fail($res);
+ return;
+ }
+
+ ob_get_clean();
+
+ exec('git diff ' . $d->nsPath, $out);
+ $out = implode("\n", $out);
+ $this->assertSame('', $out, "Generated files changed");
+ }
+
+ function testIssue39_2() {
+ $d = new GenPhp();
+ $d->schema = __DIR__ . '/../../tests/assets/issue39_2.json';
+ $d->ns = 'Issue39_2';
+ $d->nsPath = __DIR__ . '/../assets/php/Issue39_2';
+
+ $d->setResponse(new Response());
+ ob_start();
+ try {
+ $d->performAction();
+ } catch (ExitCode $exception) {
+ $res = ob_get_clean();
+ $this->fail($res);
+ return;
+ }
+
+ ob_get_clean();
+
+ exec('git diff ' . $d->nsPath, $out);
+ $out = implode("\n", $out);
+ $this->assertSame('', $out, "Generated files changed");
+ }
+
}
\ No newline at end of file