diff --git a/CHANGELOG.md b/CHANGELOG.md index 486ee8d..a8432fd 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). +## [0.4.46] - 2021-08-29 + +### Fixed +- Infinite recursion with JSON Schema draft-07 reference in 3rd party schema. + ## [0.4.45] - 2021-07-16 ### Fixed @@ -267,6 +272,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Removed unnecessary regexp dependency, #7. +[0.4.46]: https://github.com/swaggest/go-code-builder/compare/v0.4.45...v0.4.46 [0.4.45]: https://github.com/swaggest/go-code-builder/compare/v0.4.44...v0.4.45 [0.4.44]: https://github.com/swaggest/go-code-builder/compare/v0.4.43...v0.4.44 [0.4.43]: https://github.com/swaggest/go-code-builder/compare/v0.4.42...v0.4.43 diff --git a/composer.json b/composer.json index 09587ee..83adac3 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "swaggest/code-builder": "^0.3.1|dev-master", "php": ">=5.6.0", "phplang/scope-exit": "^1.0", - "swaggest/json-schema": "^0.12.4", + "swaggest/json-schema": "^0.12.37", "swaggest/json-schema-maker": "^0.3.2" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 44ad7bc..bbe6f44 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": "1ba1127ab9edaf8a718cccbf54173c23", + "content-hash": "008cd8a8c92d4ac5252019a92066ae3a", "packages": [ { "name": "php-yaoi/php-yaoi", @@ -49,6 +49,10 @@ "keywords": [ "framework" ], + "support": { + "issues": "https://github.com/php-yaoi/php-yaoi/issues", + "source": "https://github.com/php-yaoi/php-yaoi/tree/master" + }, "time": "2017-06-13T09:10:15+00:00" }, { @@ -93,20 +97,24 @@ "exit", "scope" ], + "support": { + "issues": "https://github.com/phplang/scope-exit/issues", + "source": "https://github.com/phplang/scope-exit/tree/master" + }, "time": "2016-09-17T00:15:18+00:00" }, { "name": "psr/log", - "version": "1.1.3", + "version": "1.1.4", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", "shasum": "" }, "require": { @@ -130,7 +138,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "description": "Common interface for logging libraries", @@ -140,20 +148,23 @@ "psr", "psr-3" ], - "time": "2020-03-23T09:12:05+00:00" + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.4" + }, + "time": "2021-05-03T11:20:27+00:00" }, { "name": "swaggest/code-builder", - "version": "dev-master", + "version": "v0.3.4", "source": { "type": "git", "url": "https://github.com/swaggest/code-builder.git", - "reference": "ef92f2a3aa3640d5ba02e001c6a40adad7f695b3" + "reference": "bf5d8c2866ae1b3079d7899244eab070ebbe9fb8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swaggest/code-builder/zipball/ef92f2a3aa3640d5ba02e001c6a40adad7f695b3", - "reference": "ef92f2a3aa3640d5ba02e001c6a40adad7f695b3", + "url": "https://api.github.com/repos/swaggest/code-builder/zipball/bf5d8c2866ae1b3079d7899244eab070ebbe9fb8", + "reference": "bf5d8c2866ae1b3079d7899244eab070ebbe9fb8", "shasum": "" }, "require": { @@ -187,20 +198,24 @@ "keywords": [ "library" ], - "time": "2020-09-08T20:09:18+00:00" + "support": { + "issues": "https://github.com/swaggest/code-builder/issues", + "source": "https://github.com/swaggest/code-builder/tree/v0.3.4" + }, + "time": "2021-04-23T07:27:29+00:00" }, { "name": "swaggest/json-diff", - "version": "v3.7.5", + "version": "v3.8.1", "source": { "type": "git", "url": "https://github.com/swaggest/json-diff.git", - "reference": "e452a9c6444905a486280c7d56503a6468303f69" + "reference": "d2184358c5ef5ecaa1f6b4c2bce175fac2d25670" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swaggest/json-diff/zipball/e452a9c6444905a486280c7d56503a6468303f69", - "reference": "e452a9c6444905a486280c7d56503a6468303f69", + "url": "https://api.github.com/repos/swaggest/json-diff/zipball/d2184358c5ef5ecaa1f6b4c2bce175fac2d25670", + "reference": "d2184358c5ef5ecaa1f6b4c2bce175fac2d25670", "shasum": "" }, "require": { @@ -226,20 +241,24 @@ } ], "description": "JSON diff/rearrange/patch/pointer library for PHP", - "time": "2020-05-26T21:53:21+00:00" + "support": { + "issues": "https://github.com/swaggest/json-diff/issues", + "source": "https://github.com/swaggest/json-diff/tree/v3.8.1" + }, + "time": "2020-09-25T17:47:07+00:00" }, { "name": "swaggest/json-schema", - "version": "v0.12.29", + "version": "v0.12.37", "source": { "type": "git", "url": "https://github.com/swaggest/php-json-schema.git", - "reference": "7564d4a5fc8c068479698a30e5a7c589ea32a9c6" + "reference": "1d7cce2dac6844a8a612672ad5936e8c4145e96a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swaggest/php-json-schema/zipball/7564d4a5fc8c068479698a30e5a7c589ea32a9c6", - "reference": "7564d4a5fc8c068479698a30e5a7c589ea32a9c6", + "url": "https://api.github.com/repos/swaggest/php-json-schema/zipball/1d7cce2dac6844a8a612672ad5936e8c4145e96a", + "reference": "1d7cce2dac6844a8a612672ad5936e8c4145e96a", "shasum": "" }, "require": { @@ -250,8 +269,8 @@ "swaggest/json-diff": "^3.5.1" }, "require-dev": { - "phpunit/php-code-coverage": "2.2.4", - "phpunit/phpunit": "4.8.35" + "phpunit/php-code-coverage": "^4", + "phpunit/phpunit": "^5" }, "type": "library", "autoload": { @@ -270,7 +289,12 @@ } ], "description": "High definition PHP structures with JSON-schema based validation", - "time": "2020-03-19T08:41:40+00:00" + "support": { + "email": "vearutop@gmail.com", + "issues": "https://github.com/swaggest/php-json-schema/issues", + "source": "https://github.com/swaggest/php-json-schema/tree/v0.12.37" + }, + "time": "2021-08-29T14:47:54+00:00" }, { "name": "swaggest/json-schema-maker", @@ -316,6 +340,10 @@ "keywords": [ "json-schema" ], + "support": { + "issues": "https://github.com/swaggest/json-schema-maker/issues", + "source": "https://github.com/swaggest/json-schema-maker/tree/master" + }, "time": "2020-09-08T19:48:57+00:00" } ], @@ -372,6 +400,10 @@ "constructor", "instantiate" ], + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/master" + }, "time": "2015-06-14T21:17:01+00:00" }, { @@ -417,6 +449,10 @@ "object", "object graph" ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.x" + }, "time": "2017-10-19T19:58:43+00:00" }, { @@ -471,6 +507,10 @@ "reflection", "static analysis" ], + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", + "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/master" + }, "time": "2017-09-11T18:02:19+00:00" }, { @@ -516,6 +556,10 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/release/3.x" + }, "time": "2017-11-10T14:09:06+00:00" }, { @@ -563,6 +607,10 @@ "email": "me@mikevanriel.com" } ], + "support": { + "issues": "https://github.com/phpDocumentor/TypeResolver/issues", + "source": "https://github.com/phpDocumentor/TypeResolver/tree/master" + }, "time": "2017-07-14T14:27:02+00:00" }, { @@ -626,6 +674,10 @@ "spy", "stub" ], + "support": { + "issues": "https://github.com/phpspec/prophecy/issues", + "source": "https://github.com/phpspec/prophecy/tree/v1.10.3" + }, "time": "2020-03-05T15:02:03+00:00" }, { @@ -689,6 +741,11 @@ "testing", "xunit" ], + "support": { + "irc": "irc://irc.freenode.net/phpunit", + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/4.0" + }, "time": "2017-04-02T07:44:40+00:00" }, { @@ -736,6 +793,11 @@ "filesystem", "iterator" ], + "support": { + "irc": "irc://irc.freenode.net/phpunit", + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/1.4.5" + }, "time": "2017-11-27T13:52:08+00:00" }, { @@ -777,6 +839,10 @@ "keywords": [ "template" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/1.2.1" + }, "time": "2015-06-21T13:50:34+00:00" }, { @@ -826,6 +892,10 @@ "keywords": [ "timer" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/master" + }, "time": "2017-02-26T11:10:40+00:00" }, { @@ -875,6 +945,11 @@ "keywords": [ "tokenizer" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-token-stream/issues", + "source": "https://github.com/sebastianbergmann/php-token-stream/tree/1.4" + }, + "abandoned": true, "time": "2017-12-04T08:55:13+00:00" }, { @@ -957,6 +1032,10 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "source": "https://github.com/sebastianbergmann/phpunit/tree/5.7.27" + }, "time": "2018-02-01T05:50:59+00:00" }, { @@ -1016,28 +1095,33 @@ "mock", "xunit" ], + "support": { + "irc": "irc://irc.freenode.net/phpunit", + "issues": "https://github.com/sebastianbergmann/phpunit-mock-objects/issues", + "source": "https://github.com/sebastianbergmann/phpunit-mock-objects/tree/3.4" + }, "abandoned": true, "time": "2017-06-30T09:13:00+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/1de8cd5c010cb153fcd68b8d0f64606f523f7619", + "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": ">=5.6" }, "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0" + "phpunit/phpunit": "^8.5" }, "type": "library", "extra": { @@ -1062,7 +1146,17 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04T06:30:41+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/1.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T08:15:22+00:00" }, { "name": "sebastian/comparator", @@ -1126,6 +1220,10 @@ "compare", "equality" ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/1.2" + }, "time": "2017-01-29T09:50:25+00:00" }, { @@ -1178,6 +1276,10 @@ "keywords": [ "diff" ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/1.4" + }, "time": "2017-05-22T07:24:03+00:00" }, { @@ -1228,6 +1330,10 @@ "environment", "hhvm" ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/master" + }, "time": "2016-11-26T07:53:53+00:00" }, { @@ -1295,6 +1401,10 @@ "export", "exporter" ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/master" + }, "time": "2016-11-19T08:54:04+00:00" }, { @@ -1346,6 +1456,10 @@ "keywords": [ "global state" ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/1.1.1" + }, "time": "2015-10-12T03:26:01+00:00" }, { @@ -1392,6 +1506,10 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/master" + }, "time": "2017-02-18T15:18:39+00:00" }, { @@ -1445,6 +1563,10 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/master" + }, "time": "2016-11-19T07:33:16+00:00" }, { @@ -1487,6 +1609,10 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "support": { + "issues": "https://github.com/sebastianbergmann/resource-operations/issues", + "source": "https://github.com/sebastianbergmann/resource-operations/tree/master" + }, "time": "2015-07-28T20:34:47+00:00" }, { @@ -1530,20 +1656,24 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/master" + }, "time": "2016-10-03T07:35:21+00:00" }, { "name": "symfony/console", - "version": "v3.4.44", + "version": "v3.4.47", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "71da881ad579f0cd66aef8677e4cf6217d8ecd0c" + "reference": "a10b1da6fc93080c180bba7219b5ff5b7518fe81" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/71da881ad579f0cd66aef8677e4cf6217d8ecd0c", - "reference": "71da881ad579f0cd66aef8677e4cf6217d8ecd0c", + "url": "https://api.github.com/repos/symfony/console/zipball/a10b1da6fc93080c180bba7219b5ff5b7518fe81", + "reference": "a10b1da6fc93080c180bba7219b5ff5b7518fe81", "shasum": "" }, "require": { @@ -1573,11 +1703,6 @@ "symfony/process": "" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.4-dev" - } - }, "autoload": { "psr-4": { "Symfony\\Component\\Console\\": "" @@ -1602,6 +1727,9 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/console/tree/v3.4.47" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -1616,20 +1744,20 @@ "type": "tidelift" } ], - "time": "2020-08-09T08:16:57+00:00" + "time": "2020-10-24T10:57:07+00:00" }, { "name": "symfony/debug", - "version": "v3.4.44", + "version": "v3.4.47", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "0893a0b07c499a1530614d65869ea6a7b1b8a164" + "reference": "ab42889de57fdfcfcc0759ab102e2fd4ea72dcae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/0893a0b07c499a1530614d65869ea6a7b1b8a164", - "reference": "0893a0b07c499a1530614d65869ea6a7b1b8a164", + "url": "https://api.github.com/repos/symfony/debug/zipball/ab42889de57fdfcfcc0759ab102e2fd4ea72dcae", + "reference": "ab42889de57fdfcfcc0759ab102e2fd4ea72dcae", "shasum": "" }, "require": { @@ -1643,11 +1771,6 @@ "symfony/http-kernel": "~2.8|~3.0|~4.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.4-dev" - } - }, "autoload": { "psr-4": { "Symfony\\Component\\Debug\\": "" @@ -1672,6 +1795,9 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/debug/tree/v3.4.47" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -1686,20 +1812,20 @@ "type": "tidelift" } ], - "time": "2020-08-09T08:13:48+00:00" + "time": "2020-10-24T10:57:07+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.18.1", + "version": "v1.19.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "1c302646f6efc070cd46856e600e5e0684d6b454" + "reference": "aed596913b70fae57be53d86faa2e9ef85a2297b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1c302646f6efc070cd46856e600e5e0684d6b454", - "reference": "1c302646f6efc070cd46856e600e5e0684d6b454", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/aed596913b70fae57be53d86faa2e9ef85a2297b", + "reference": "aed596913b70fae57be53d86faa2e9ef85a2297b", "shasum": "" }, "require": { @@ -1711,7 +1837,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -1748,6 +1874,9 @@ "polyfill", "portable" ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.19.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -1762,20 +1891,20 @@ "type": "tidelift" } ], - "time": "2020-07-14T12:35:20+00:00" + "time": "2020-10-23T09:01:57+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.18.1", + "version": "v1.19.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a" + "reference": "b5f7b932ee6fa802fc792eabd77c4c88084517ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/a6977d63bf9a0ad4c65cd352709e230876f9904a", - "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b5f7b932ee6fa802fc792eabd77c4c88084517ce", + "reference": "b5f7b932ee6fa802fc792eabd77c4c88084517ce", "shasum": "" }, "require": { @@ -1787,7 +1916,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -1825,6 +1954,9 @@ "portable", "shim" ], + "support": { + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.19.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -1839,20 +1971,20 @@ "type": "tidelift" } ], - "time": "2020-07-14T12:35:20+00:00" + "time": "2020-10-23T09:01:57+00:00" }, { "name": "symfony/yaml", - "version": "v3.4.44", + "version": "v3.4.47", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "4152e36b0f305c2a57aa0233dee56ec27bca4f06" + "reference": "88289caa3c166321883f67fe5130188ebbb47094" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/4152e36b0f305c2a57aa0233dee56ec27bca4f06", - "reference": "4152e36b0f305c2a57aa0233dee56ec27bca4f06", + "url": "https://api.github.com/repos/symfony/yaml/zipball/88289caa3c166321883f67fe5130188ebbb47094", + "reference": "88289caa3c166321883f67fe5130188ebbb47094", "shasum": "" }, "require": { @@ -1869,11 +2001,6 @@ "symfony/console": "For validating YAML files using the lint command" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.4-dev" - } - }, "autoload": { "psr-4": { "Symfony\\Component\\Yaml\\": "" @@ -1898,6 +2025,9 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/yaml/tree/v3.4.47" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -1912,7 +2042,7 @@ "type": "tidelift" } ], - "time": "2020-08-26T06:32:27+00:00" + "time": "2020-10-24T10:57:07+00:00" }, { "name": "victorjonsson/markdowndocs", @@ -1956,6 +2086,10 @@ ], "description": "Command line tool for generating markdown-formatted class documentation", "homepage": "https://github.com/victorjonsson/PHP-Markdown-Documentation-Generator", + "support": { + "issues": "https://github.com/victorjonsson/PHP-Markdown-Documentation-Generator/issues", + "source": "https://github.com/victorjonsson/PHP-Markdown-Documentation-Generator/tree/master" + }, "time": "2017-04-20T09:52:47+00:00" }, { @@ -1963,12 +2097,12 @@ "version": "1.9.1", "source": { "type": "git", - "url": "https://github.com/webmozart/assert.git", + "url": "https://github.com/webmozarts/assert.git", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "shasum": "" }, @@ -2005,6 +2139,10 @@ "check", "validate" ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.9.1" + }, "time": "2020-07-08T17:02:28+00:00" } ], @@ -2023,5 +2161,5 @@ "platform-overrides": { "php": "5.6.1" }, - "plugin-api-version": "1.1.0" + "plugin-api-version": "2.1.0" } diff --git a/src/JsonSchema/GoBuilder.php b/src/JsonSchema/GoBuilder.php index 16904a6..3d24e90 100644 --- a/src/JsonSchema/GoBuilder.php +++ b/src/JsonSchema/GoBuilder.php @@ -73,7 +73,7 @@ public function getCode() } /** - * @param Schema $schema + * @param Schema|\stdClass $schema * @param string $path * @param StructDef|null $parentStruct * @param bool $isRequired @@ -88,11 +88,13 @@ public function getType($schema, $path = '#', StructDef $parentStruct = null, $i return $this->generatedStructs[$path]->structDef->getType(); } - if (!is_bool($schema) && (null !== $refs = $schema->getFromRefs()) && !in_array(false, $refs)) { + if (!is_bool($schema) && !$schema instanceof \stdClass + && (null !== $refs = $schema->getFromRefs()) && !in_array(false, $refs)) { foreach ($refs as $ref) { if (isset($this->generatedStructs[$ref])) { return $this->generatedStructs[$ref]->structDef->getType(); } + $path = $ref; } } @@ -106,6 +108,11 @@ public function getType($schema, $path = '#', StructDef $parentStruct = null, $i if ($s instanceof \stdClass) { $s = Schema::import($s); } + + if ($s->id === 'http://json-schema.org/draft-04/schema#') { + $path = 'jsonSchema'; + } + $typeBuilder = new TypeBuilder($s, $path, $this, $parentStruct, $isRequired); $result = $typeBuilder->build(); return $result; @@ -226,7 +233,11 @@ private function makeStruct(Schema $schema, $path) foreach ($schema->properties->toArray() as $name => $property) { $property = self::unboolSchema($property); - if ($property->{TypeBuilder::X_GENERATE} === false || + if ($property instanceof Wrapper) { + $property = $property->exportSchema(); + } + + if ((isset($property->{TypeBuilder::X_GENERATE}) && $property->{TypeBuilder::X_GENERATE} === false) || ($this->options->requireXGenerate && empty($property->{TypeBuilder::X_GENERATE}))) { continue; } diff --git a/tests/resources/asyncapi-2.1.0.json b/tests/resources/asyncapi-2.1.0.json new file mode 100644 index 0000000..6f5a53a --- /dev/null +++ b/tests/resources/asyncapi-2.1.0.json @@ -0,0 +1,1476 @@ +{ + "title": "AsyncAPI 2.1.0 schema.", + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": [ + "asyncapi", + "info", + "channels" + ], + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "asyncapi": { + "type": "string", + "enum": [ + "2.1.0" + ], + "description": "The AsyncAPI specification version of this document." + }, + "id": { + "type": "string", + "description": "A unique id representing the application.", + "format": "uri" + }, + "info": { + "$ref": "#/definitions/info" + }, + "servers": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/server" + } + }, + "defaultContentType": { + "type": "string" + }, + "channels": { + "$ref": "#/definitions/channels" + }, + "components": { + "$ref": "#/definitions/components" + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/tag" + }, + "uniqueItems": true + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + } + }, + "definitions": { + "Reference": { + "type": "object", + "required": [ + "$ref" + ], + "properties": { + "$ref": { + "$ref": "#/definitions/ReferenceObject" + } + } + }, + "ReferenceObject": { + "type": "string", + "format": "uri-reference" + }, + "info": { + "type": "object", + "description": "General information about the API.", + "required": [ + "version", + "title" + ], + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "title": { + "type": "string", + "description": "A unique and precise title of the API." + }, + "version": { + "type": "string", + "description": "A semantic version number of the API." + }, + "description": { + "type": "string", + "description": "A longer description of the API. Should be different from the title. CommonMark is allowed." + }, + "termsOfService": { + "type": "string", + "description": "A URL to the Terms of Service for the API. MUST be in the format of a URL.", + "format": "uri" + }, + "contact": { + "$ref": "#/definitions/contact" + }, + "license": { + "$ref": "#/definitions/license" + } + } + }, + "contact": { + "type": "object", + "description": "Contact information for the owners of the API.", + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "description": "The identifying name of the contact person/organization." + }, + "url": { + "type": "string", + "description": "The URL pointing to the contact information.", + "format": "uri" + }, + "email": { + "type": "string", + "description": "The email address of the contact person/organization.", + "format": "email" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + } + }, + "license": { + "type": "object", + "required": [ + "name" + ], + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "description": "The name of the license type. It's encouraged to use an OSI compatible license." + }, + "url": { + "type": "string", + "description": "The URL pointing to the license.", + "format": "uri" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + } + }, + "server": { + "type": "object", + "description": "An object representing a Server.", + "required": [ + "url", + "protocol" + ], + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "url": { + "type": "string" + }, + "description": { + "type": "string" + }, + "protocol": { + "type": "string", + "description": "The transfer protocol." + }, + "protocolVersion": { + "type": "string" + }, + "variables": { + "$ref": "#/definitions/serverVariables" + }, + "security": { + "type": "array", + "items": { + "$ref": "#/definitions/SecurityRequirement" + } + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + } + } + }, + "serverVariables": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/serverVariable" + } + }, + "serverVariable": { + "type": "object", + "description": "An object representing a Server Variable for server URL template substitution.", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "enum": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + }, + "default": { + "type": "string" + }, + "description": { + "type": "string" + }, + "examples": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "channels": { + "type": "object", + "propertyNames": { + "type": "string", + "format": "uri-template", + "minLength": 1 + }, + "additionalProperties": { + "$ref": "#/definitions/channelItem" + } + }, + "components": { + "type": "object", + "description": "An object to hold a set of reusable objects for different aspects of the AsyncAPI Specification.", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "schemas": { + "$ref": "#/definitions/schemas" + }, + "messages": { + "$ref": "#/definitions/messages" + }, + "securitySchemes": { + "type": "object", + "patternProperties": { + "^[\\w\\d\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/SecurityScheme" + } + ] + } + } + }, + "parameters": { + "$ref": "#/definitions/parameters" + }, + "correlationIds": { + "type": "object", + "patternProperties": { + "^[\\w\\d\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/correlationId" + } + ] + } + } + }, + "operationTraits": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/operationTrait" + } + }, + "messageTraits": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/messageTrait" + } + }, + "serverBindings": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/bindingsObject" + } + }, + "channelBindings": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/bindingsObject" + } + }, + "operationBindings": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/bindingsObject" + } + }, + "messageBindings": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/bindingsObject" + } + } + } + }, + "schemas": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/schema" + }, + "description": "JSON objects describing schemas the API uses." + }, + "messages": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/message" + }, + "description": "JSON objects describing the messages being consumed and produced by the API." + }, + "parameters": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/parameter" + }, + "description": "JSON objects describing re-usable channel parameters." + }, + "schema": { + "allOf": [ + { + "$ref": "http://json-schema.org/draft-07/schema#" + }, + { + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "additionalProperties": { + "anyOf": [ + { + "$ref": "#/definitions/schema" + }, + { + "type": "boolean" + } + ], + "default": {} + }, + "items": { + "anyOf": [ + { + "$ref": "#/definitions/schema" + }, + { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/schema" + } + } + ], + "default": {} + }, + "allOf": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/schema" + } + }, + "oneOf": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/schema" + } + }, + "anyOf": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/schema" + } + }, + "not": { + "$ref": "#/definitions/schema" + }, + "properties": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/schema" + }, + "default": {} + }, + "patternProperties": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/schema" + }, + "default": {} + }, + "propertyNames": { + "$ref": "#/definitions/schema" + }, + "contains": { + "$ref": "#/definitions/schema" + }, + "discriminator": { + "type": "string" + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "deprecated": { + "type": "boolean", + "default": false + } + } + } + ] + }, + "externalDocs": { + "type": "object", + "additionalProperties": false, + "description": "information about external documentation", + "required": [ + "url" + ], + "properties": { + "description": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + } + }, + "channelItem": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "$ref": { + "$ref": "#/definitions/ReferenceObject" + }, + "parameters": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/parameter" + } + }, + "description": { + "type": "string", + "description": "A description of the channel." + }, + "publish": { + "$ref": "#/definitions/operation" + }, + "subscribe": { + "$ref": "#/definitions/operation" + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + } + } + }, + "parameter": { + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "description": { + "type": "string", + "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." + }, + "schema": { + "$ref": "#/definitions/schema" + }, + "location": { + "type": "string", + "description": "A runtime expression that specifies the location of the parameter value", + "pattern": "^\\$message\\.(header|payload)\\#(\\/(([^\\/~])|(~[01]))*)*" + }, + "$ref": { + "$ref": "#/definitions/ReferenceObject" + } + } + }, + "operation": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "traits": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/operationTrait" + }, + { + "type": "array", + "items": [ + { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/operationTrait" + } + ] + }, + { + "type": "object", + "additionalItems": true + } + ] + } + ] + } + }, + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/tag" + }, + "uniqueItems": true + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "operationId": { + "type": "string" + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + }, + "message": { + "$ref": "#/definitions/message" + } + } + }, + "message": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "oneOf": [ + { + "type": "object", + "required": [ + "oneOf" + ], + "additionalProperties": false, + "properties": { + "oneOf": { + "type": "array", + "items": { + "$ref": "#/definitions/message" + } + } + } + }, + { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "schemaFormat": { + "type": "string" + }, + "contentType": { + "type": "string" + }, + "headers": { + "allOf": [ + { + "$ref": "#/definitions/schema" + }, + { + "properties": { + "type": { + "const": "object" + } + } + } + ] + }, + "payload": {}, + "correlationId": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/correlationId" + } + ] + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/tag" + }, + "uniqueItems": true + }, + "summary": { + "type": "string", + "description": "A brief summary of the message." + }, + "name": { + "type": "string", + "description": "Name of the message." + }, + "title": { + "type": "string", + "description": "A human-friendly title for the message." + }, + "description": { + "type": "string", + "description": "A longer description of the message. CommonMark is allowed." + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "examples": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "anyOf": [ + {"required": ["payload"] }, + {"required": ["headers"] } + ], + "properties": { + "name": { + "type": "string", + "description": "Machine readable name of the message example." + }, + "summary": { + "type": "string", + "description": "A brief summary of the message example." + }, + "headers": { + "type": "object" + }, + "payload": {} + } + } + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + }, + "traits": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/messageTrait" + }, + { + "type": "array", + "items": [ + { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/messageTrait" + } + ] + }, + { + "type": "object", + "additionalItems": true + } + ] + } + ] + } + } + } + } + ] + } + ] + }, + "bindingsObject": { + "type": "object", + "additionalProperties": true, + "properties": { + "http": {}, + "ws": {}, + "amqp": {}, + "amqp1": {}, + "mqtt": {}, + "mqtt5": {}, + "kafka": {}, + "nats": {}, + "jms": {}, + "sns": {}, + "sqs": {}, + "stomp": {}, + "redis": {}, + "ibmmq": {} + } + }, + "correlationId": { + "type": "object", + "required": [ + "location" + ], + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "description": { + "type": "string", + "description": "A optional description of the correlation ID. GitHub Flavored Markdown is allowed." + }, + "location": { + "type": "string", + "description": "A runtime expression that specifies the location of the correlation ID", + "pattern": "^\\$message\\.(header|payload)\\#(\\/(([^\\/~])|(~[01]))*)*" + } + } + }, + "specificationExtension": { + "description": "Any property starting with x- is valid.", + "additionalProperties": true, + "additionalItems": true + }, + "tag": { + "type": "object", + "additionalProperties": false, + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + } + }, + "operationTrait": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/tag" + }, + "uniqueItems": true + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "operationId": { + "type": "string" + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + } + } + }, + "messageTrait": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "schemaFormat": { + "type": "string" + }, + "contentType": { + "type": "string" + }, + "headers": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/schema" + } + ] + }, + "correlationId": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/correlationId" + } + ] + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/tag" + }, + "uniqueItems": true + }, + "summary": { + "type": "string", + "description": "A brief summary of the message." + }, + "name": { + "type": "string", + "description": "Name of the message." + }, + "title": { + "type": "string", + "description": "A human-friendly title for the message." + }, + "description": { + "type": "string", + "description": "A longer description of the message. CommonMark is allowed." + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "examples": { + "type": "array", + "items": { + "type": "object" + } + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + } + } + }, + "SecurityScheme": { + "oneOf": [ + { + "$ref": "#/definitions/userPassword" + }, + { + "$ref": "#/definitions/apiKey" + }, + { + "$ref": "#/definitions/X509" + }, + { + "$ref": "#/definitions/symmetricEncryption" + }, + { + "$ref": "#/definitions/asymmetricEncryption" + }, + { + "$ref": "#/definitions/HTTPSecurityScheme" + }, + { + "$ref": "#/definitions/oauth2Flows" + }, + { + "$ref": "#/definitions/openIdConnect" + }, + { + "$ref": "#/definitions/SaslSecurityScheme" + } + ] + }, + "userPassword": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "userPassword" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "apiKey": { + "type": "object", + "required": [ + "type", + "in" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "apiKey" + ] + }, + "in": { + "type": "string", + "enum": [ + "user", + "password" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "X509": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "X509" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "symmetricEncryption": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "symmetricEncryption" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "asymmetricEncryption": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "asymmetricEncryption" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "HTTPSecurityScheme": { + "oneOf": [ + { + "$ref": "#/definitions/NonBearerHTTPSecurityScheme" + }, + { + "$ref": "#/definitions/BearerHTTPSecurityScheme" + }, + { + "$ref": "#/definitions/APIKeyHTTPSecurityScheme" + } + ] + }, + "NonBearerHTTPSecurityScheme": { + "not": { + "type": "object", + "properties": { + "scheme": { + "type": "string", + "enum": [ + "bearer" + ] + } + } + }, + "type": "object", + "required": [ + "scheme", + "type" + ], + "properties": { + "scheme": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "http" + ] + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "BearerHTTPSecurityScheme": { + "type": "object", + "required": [ + "type", + "scheme" + ], + "properties": { + "scheme": { + "type": "string", + "enum": [ + "bearer" + ] + }, + "bearerFormat": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "http" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "APIKeyHTTPSecurityScheme": { + "type": "object", + "required": [ + "type", + "name", + "in" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "httpApiKey" + ] + }, + "name": { + "type": "string" + }, + "in": { + "type": "string", + "enum": [ + "header", + "query", + "cookie" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "SaslSecurityScheme": { + "oneOf": [ + { + "$ref": "#/definitions/SaslPlainSecurityScheme" + }, + { + "$ref": "#/definitions/SaslScramSecurityScheme" + }, + { + "$ref": "#/definitions/SaslGssapiSecurityScheme" + } + ] + }, + "SaslPlainSecurityScheme": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "plain" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "SaslScramSecurityScheme": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "scramSha256", + "scramSha512" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "SaslGssapiSecurityScheme": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "gssapi" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "oauth2Flows": { + "type": "object", + "required": [ + "type", + "flows" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "oauth2" + ] + }, + "description": { + "type": "string" + }, + "flows": { + "type": "object", + "properties": { + "implicit": { + "allOf": [ + { + "$ref": "#/definitions/oauth2Flow" + }, + { + "required": [ + "authorizationUrl", + "scopes" + ] + }, + { + "not": { + "required": [ + "tokenUrl" + ] + } + } + ] + }, + "password": { + "allOf": [ + { + "$ref": "#/definitions/oauth2Flow" + }, + { + "required": [ + "tokenUrl", + "scopes" + ] + }, + { + "not": { + "required": [ + "authorizationUrl" + ] + } + } + ] + }, + "clientCredentials": { + "allOf": [ + { + "$ref": "#/definitions/oauth2Flow" + }, + { + "required": [ + "tokenUrl", + "scopes" + ] + }, + { + "not": { + "required": [ + "authorizationUrl" + ] + } + } + ] + }, + "authorizationCode": { + "allOf": [ + { + "$ref": "#/definitions/oauth2Flow" + }, + { + "required": [ + "authorizationUrl", + "tokenUrl", + "scopes" + ] + } + ] + } + }, + "additionalProperties": false + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + } + }, + "oauth2Flow": { + "type": "object", + "properties": { + "authorizationUrl": { + "type": "string", + "format": "uri" + }, + "tokenUrl": { + "type": "string", + "format": "uri" + }, + "refreshUrl": { + "type": "string", + "format": "uri" + }, + "scopes": { + "$ref": "#/definitions/oauth2Scopes" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "oauth2Scopes": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "openIdConnect": { + "type": "object", + "required": [ + "type", + "openIdConnectUrl" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "openIdConnect" + ] + }, + "description": { + "type": "string" + }, + "openIdConnectUrl": { + "type": "string", + "format": "uri" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "SecurityRequirement": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + } + } + } +} diff --git a/tests/resources/go/asyncapi-2.1.0.json b/tests/resources/go/asyncapi-2.1.0.json new file mode 100644 index 0000000..6f5a53a --- /dev/null +++ b/tests/resources/go/asyncapi-2.1.0.json @@ -0,0 +1,1476 @@ +{ + "title": "AsyncAPI 2.1.0 schema.", + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": [ + "asyncapi", + "info", + "channels" + ], + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "asyncapi": { + "type": "string", + "enum": [ + "2.1.0" + ], + "description": "The AsyncAPI specification version of this document." + }, + "id": { + "type": "string", + "description": "A unique id representing the application.", + "format": "uri" + }, + "info": { + "$ref": "#/definitions/info" + }, + "servers": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/server" + } + }, + "defaultContentType": { + "type": "string" + }, + "channels": { + "$ref": "#/definitions/channels" + }, + "components": { + "$ref": "#/definitions/components" + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/tag" + }, + "uniqueItems": true + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + } + }, + "definitions": { + "Reference": { + "type": "object", + "required": [ + "$ref" + ], + "properties": { + "$ref": { + "$ref": "#/definitions/ReferenceObject" + } + } + }, + "ReferenceObject": { + "type": "string", + "format": "uri-reference" + }, + "info": { + "type": "object", + "description": "General information about the API.", + "required": [ + "version", + "title" + ], + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "title": { + "type": "string", + "description": "A unique and precise title of the API." + }, + "version": { + "type": "string", + "description": "A semantic version number of the API." + }, + "description": { + "type": "string", + "description": "A longer description of the API. Should be different from the title. CommonMark is allowed." + }, + "termsOfService": { + "type": "string", + "description": "A URL to the Terms of Service for the API. MUST be in the format of a URL.", + "format": "uri" + }, + "contact": { + "$ref": "#/definitions/contact" + }, + "license": { + "$ref": "#/definitions/license" + } + } + }, + "contact": { + "type": "object", + "description": "Contact information for the owners of the API.", + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "description": "The identifying name of the contact person/organization." + }, + "url": { + "type": "string", + "description": "The URL pointing to the contact information.", + "format": "uri" + }, + "email": { + "type": "string", + "description": "The email address of the contact person/organization.", + "format": "email" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + } + }, + "license": { + "type": "object", + "required": [ + "name" + ], + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "description": "The name of the license type. It's encouraged to use an OSI compatible license." + }, + "url": { + "type": "string", + "description": "The URL pointing to the license.", + "format": "uri" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + } + }, + "server": { + "type": "object", + "description": "An object representing a Server.", + "required": [ + "url", + "protocol" + ], + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "url": { + "type": "string" + }, + "description": { + "type": "string" + }, + "protocol": { + "type": "string", + "description": "The transfer protocol." + }, + "protocolVersion": { + "type": "string" + }, + "variables": { + "$ref": "#/definitions/serverVariables" + }, + "security": { + "type": "array", + "items": { + "$ref": "#/definitions/SecurityRequirement" + } + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + } + } + }, + "serverVariables": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/serverVariable" + } + }, + "serverVariable": { + "type": "object", + "description": "An object representing a Server Variable for server URL template substitution.", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "enum": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + }, + "default": { + "type": "string" + }, + "description": { + "type": "string" + }, + "examples": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "channels": { + "type": "object", + "propertyNames": { + "type": "string", + "format": "uri-template", + "minLength": 1 + }, + "additionalProperties": { + "$ref": "#/definitions/channelItem" + } + }, + "components": { + "type": "object", + "description": "An object to hold a set of reusable objects for different aspects of the AsyncAPI Specification.", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "schemas": { + "$ref": "#/definitions/schemas" + }, + "messages": { + "$ref": "#/definitions/messages" + }, + "securitySchemes": { + "type": "object", + "patternProperties": { + "^[\\w\\d\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/SecurityScheme" + } + ] + } + } + }, + "parameters": { + "$ref": "#/definitions/parameters" + }, + "correlationIds": { + "type": "object", + "patternProperties": { + "^[\\w\\d\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/correlationId" + } + ] + } + } + }, + "operationTraits": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/operationTrait" + } + }, + "messageTraits": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/messageTrait" + } + }, + "serverBindings": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/bindingsObject" + } + }, + "channelBindings": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/bindingsObject" + } + }, + "operationBindings": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/bindingsObject" + } + }, + "messageBindings": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/bindingsObject" + } + } + } + }, + "schemas": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/schema" + }, + "description": "JSON objects describing schemas the API uses." + }, + "messages": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/message" + }, + "description": "JSON objects describing the messages being consumed and produced by the API." + }, + "parameters": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/parameter" + }, + "description": "JSON objects describing re-usable channel parameters." + }, + "schema": { + "allOf": [ + { + "$ref": "http://json-schema.org/draft-07/schema#" + }, + { + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "additionalProperties": { + "anyOf": [ + { + "$ref": "#/definitions/schema" + }, + { + "type": "boolean" + } + ], + "default": {} + }, + "items": { + "anyOf": [ + { + "$ref": "#/definitions/schema" + }, + { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/schema" + } + } + ], + "default": {} + }, + "allOf": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/schema" + } + }, + "oneOf": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/schema" + } + }, + "anyOf": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/schema" + } + }, + "not": { + "$ref": "#/definitions/schema" + }, + "properties": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/schema" + }, + "default": {} + }, + "patternProperties": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/schema" + }, + "default": {} + }, + "propertyNames": { + "$ref": "#/definitions/schema" + }, + "contains": { + "$ref": "#/definitions/schema" + }, + "discriminator": { + "type": "string" + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "deprecated": { + "type": "boolean", + "default": false + } + } + } + ] + }, + "externalDocs": { + "type": "object", + "additionalProperties": false, + "description": "information about external documentation", + "required": [ + "url" + ], + "properties": { + "description": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + } + }, + "channelItem": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "$ref": { + "$ref": "#/definitions/ReferenceObject" + }, + "parameters": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/parameter" + } + }, + "description": { + "type": "string", + "description": "A description of the channel." + }, + "publish": { + "$ref": "#/definitions/operation" + }, + "subscribe": { + "$ref": "#/definitions/operation" + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + } + } + }, + "parameter": { + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "description": { + "type": "string", + "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." + }, + "schema": { + "$ref": "#/definitions/schema" + }, + "location": { + "type": "string", + "description": "A runtime expression that specifies the location of the parameter value", + "pattern": "^\\$message\\.(header|payload)\\#(\\/(([^\\/~])|(~[01]))*)*" + }, + "$ref": { + "$ref": "#/definitions/ReferenceObject" + } + } + }, + "operation": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "traits": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/operationTrait" + }, + { + "type": "array", + "items": [ + { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/operationTrait" + } + ] + }, + { + "type": "object", + "additionalItems": true + } + ] + } + ] + } + }, + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/tag" + }, + "uniqueItems": true + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "operationId": { + "type": "string" + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + }, + "message": { + "$ref": "#/definitions/message" + } + } + }, + "message": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "oneOf": [ + { + "type": "object", + "required": [ + "oneOf" + ], + "additionalProperties": false, + "properties": { + "oneOf": { + "type": "array", + "items": { + "$ref": "#/definitions/message" + } + } + } + }, + { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "schemaFormat": { + "type": "string" + }, + "contentType": { + "type": "string" + }, + "headers": { + "allOf": [ + { + "$ref": "#/definitions/schema" + }, + { + "properties": { + "type": { + "const": "object" + } + } + } + ] + }, + "payload": {}, + "correlationId": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/correlationId" + } + ] + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/tag" + }, + "uniqueItems": true + }, + "summary": { + "type": "string", + "description": "A brief summary of the message." + }, + "name": { + "type": "string", + "description": "Name of the message." + }, + "title": { + "type": "string", + "description": "A human-friendly title for the message." + }, + "description": { + "type": "string", + "description": "A longer description of the message. CommonMark is allowed." + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "examples": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "anyOf": [ + {"required": ["payload"] }, + {"required": ["headers"] } + ], + "properties": { + "name": { + "type": "string", + "description": "Machine readable name of the message example." + }, + "summary": { + "type": "string", + "description": "A brief summary of the message example." + }, + "headers": { + "type": "object" + }, + "payload": {} + } + } + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + }, + "traits": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/messageTrait" + }, + { + "type": "array", + "items": [ + { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/messageTrait" + } + ] + }, + { + "type": "object", + "additionalItems": true + } + ] + } + ] + } + } + } + } + ] + } + ] + }, + "bindingsObject": { + "type": "object", + "additionalProperties": true, + "properties": { + "http": {}, + "ws": {}, + "amqp": {}, + "amqp1": {}, + "mqtt": {}, + "mqtt5": {}, + "kafka": {}, + "nats": {}, + "jms": {}, + "sns": {}, + "sqs": {}, + "stomp": {}, + "redis": {}, + "ibmmq": {} + } + }, + "correlationId": { + "type": "object", + "required": [ + "location" + ], + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "description": { + "type": "string", + "description": "A optional description of the correlation ID. GitHub Flavored Markdown is allowed." + }, + "location": { + "type": "string", + "description": "A runtime expression that specifies the location of the correlation ID", + "pattern": "^\\$message\\.(header|payload)\\#(\\/(([^\\/~])|(~[01]))*)*" + } + } + }, + "specificationExtension": { + "description": "Any property starting with x- is valid.", + "additionalProperties": true, + "additionalItems": true + }, + "tag": { + "type": "object", + "additionalProperties": false, + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + } + }, + "operationTrait": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/tag" + }, + "uniqueItems": true + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "operationId": { + "type": "string" + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + } + } + }, + "messageTrait": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "properties": { + "schemaFormat": { + "type": "string" + }, + "contentType": { + "type": "string" + }, + "headers": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/schema" + } + ] + }, + "correlationId": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/correlationId" + } + ] + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/tag" + }, + "uniqueItems": true + }, + "summary": { + "type": "string", + "description": "A brief summary of the message." + }, + "name": { + "type": "string", + "description": "Name of the message." + }, + "title": { + "type": "string", + "description": "A human-friendly title for the message." + }, + "description": { + "type": "string", + "description": "A longer description of the message. CommonMark is allowed." + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "examples": { + "type": "array", + "items": { + "type": "object" + } + }, + "bindings": { + "$ref": "#/definitions/bindingsObject" + } + } + }, + "SecurityScheme": { + "oneOf": [ + { + "$ref": "#/definitions/userPassword" + }, + { + "$ref": "#/definitions/apiKey" + }, + { + "$ref": "#/definitions/X509" + }, + { + "$ref": "#/definitions/symmetricEncryption" + }, + { + "$ref": "#/definitions/asymmetricEncryption" + }, + { + "$ref": "#/definitions/HTTPSecurityScheme" + }, + { + "$ref": "#/definitions/oauth2Flows" + }, + { + "$ref": "#/definitions/openIdConnect" + }, + { + "$ref": "#/definitions/SaslSecurityScheme" + } + ] + }, + "userPassword": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "userPassword" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "apiKey": { + "type": "object", + "required": [ + "type", + "in" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "apiKey" + ] + }, + "in": { + "type": "string", + "enum": [ + "user", + "password" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "X509": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "X509" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "symmetricEncryption": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "symmetricEncryption" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "asymmetricEncryption": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "asymmetricEncryption" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "HTTPSecurityScheme": { + "oneOf": [ + { + "$ref": "#/definitions/NonBearerHTTPSecurityScheme" + }, + { + "$ref": "#/definitions/BearerHTTPSecurityScheme" + }, + { + "$ref": "#/definitions/APIKeyHTTPSecurityScheme" + } + ] + }, + "NonBearerHTTPSecurityScheme": { + "not": { + "type": "object", + "properties": { + "scheme": { + "type": "string", + "enum": [ + "bearer" + ] + } + } + }, + "type": "object", + "required": [ + "scheme", + "type" + ], + "properties": { + "scheme": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "http" + ] + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "BearerHTTPSecurityScheme": { + "type": "object", + "required": [ + "type", + "scheme" + ], + "properties": { + "scheme": { + "type": "string", + "enum": [ + "bearer" + ] + }, + "bearerFormat": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "http" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "APIKeyHTTPSecurityScheme": { + "type": "object", + "required": [ + "type", + "name", + "in" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "httpApiKey" + ] + }, + "name": { + "type": "string" + }, + "in": { + "type": "string", + "enum": [ + "header", + "query", + "cookie" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "SaslSecurityScheme": { + "oneOf": [ + { + "$ref": "#/definitions/SaslPlainSecurityScheme" + }, + { + "$ref": "#/definitions/SaslScramSecurityScheme" + }, + { + "$ref": "#/definitions/SaslGssapiSecurityScheme" + } + ] + }, + "SaslPlainSecurityScheme": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "plain" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "SaslScramSecurityScheme": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "scramSha256", + "scramSha512" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "SaslGssapiSecurityScheme": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "gssapi" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "oauth2Flows": { + "type": "object", + "required": [ + "type", + "flows" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "oauth2" + ] + }, + "description": { + "type": "string" + }, + "flows": { + "type": "object", + "properties": { + "implicit": { + "allOf": [ + { + "$ref": "#/definitions/oauth2Flow" + }, + { + "required": [ + "authorizationUrl", + "scopes" + ] + }, + { + "not": { + "required": [ + "tokenUrl" + ] + } + } + ] + }, + "password": { + "allOf": [ + { + "$ref": "#/definitions/oauth2Flow" + }, + { + "required": [ + "tokenUrl", + "scopes" + ] + }, + { + "not": { + "required": [ + "authorizationUrl" + ] + } + } + ] + }, + "clientCredentials": { + "allOf": [ + { + "$ref": "#/definitions/oauth2Flow" + }, + { + "required": [ + "tokenUrl", + "scopes" + ] + }, + { + "not": { + "required": [ + "authorizationUrl" + ] + } + } + ] + }, + "authorizationCode": { + "allOf": [ + { + "$ref": "#/definitions/oauth2Flow" + }, + { + "required": [ + "authorizationUrl", + "tokenUrl", + "scopes" + ] + } + ] + } + }, + "additionalProperties": false + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + } + }, + "oauth2Flow": { + "type": "object", + "properties": { + "authorizationUrl": { + "type": "string", + "format": "uri" + }, + "tokenUrl": { + "type": "string", + "format": "uri" + }, + "refreshUrl": { + "type": "string", + "format": "uri" + }, + "scopes": { + "$ref": "#/definitions/oauth2Scopes" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "oauth2Scopes": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "openIdConnect": { + "type": "object", + "required": [ + "type", + "openIdConnectUrl" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "openIdConnect" + ] + }, + "description": { + "type": "string" + }, + "openIdConnectUrl": { + "type": "string", + "format": "uri" + } + }, + "patternProperties": { + "^x-[\\w\\d\\.\\-\\_]+$": { + "$ref": "#/definitions/specificationExtension" + } + }, + "additionalProperties": false + }, + "SecurityRequirement": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + } + } + } +} diff --git a/tests/resources/go/asyncapi21/entities.go b/tests/resources/go/asyncapi21/entities.go new file mode 100644 index 0000000..922909b --- /dev/null +++ b/tests/resources/go/asyncapi21/entities.go @@ -0,0 +1,5259 @@ +package entities + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "regexp" +) + +// AsyncAPI structure is generated from "#". +// +// AsyncAPI 2.1.0 schema. +type AsyncAPI struct { + // A unique id representing the application. + // Format: uri. + ID string `json:"id,omitempty"` + // General information about the API. + // Required. + Info Info `json:"info"` + Servers map[string]Server `json:"servers,omitempty"` + DefaultContentType string `json:"defaultContentType,omitempty"` + Channels map[string]ChannelItem `json:"channels"` // Required. + Components *Components `json:"components,omitempty"` // An object to hold a set of reusable objects for different aspects of the AsyncAPI Specification. + Tags []Tag `json:"tags,omitempty"` + ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` // Information about external documentation. + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalAsyncAPI AsyncAPI + +var knownKeysAsyncAPI = []string{ + "id", + "info", + "servers", + "defaultContentType", + "channels", + "components", + "tags", + "externalDocs", + "asyncapi", +} + +var requireKeysAsyncAPI = []string{ + "asyncapi", + "info", + "channels", +} + +// UnmarshalJSON decodes JSON. +func (a *AsyncAPI) UnmarshalJSON(data []byte) error { + var err error + + ma := marshalAsyncAPI(*a) + + err = json.Unmarshal(data, &ma) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysAsyncAPI { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["asyncapi"]; exists && string(v) != `"2.1.0"` { + return fmt.Errorf(`bad const value for "asyncapi" ("2.1.0" expected, %s received)`, v) + } + + delete(rawMap, "asyncapi") + + for _, key := range knownKeysAsyncAPI { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ma.MapOfAnything == nil { + ma.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ma.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in AsyncAPI: %v", offendingKeys) + } + + *a = AsyncAPI(ma) + + return nil +} + +var ( + // constAsyncAPI is unconditionally added to JSON. + constAsyncAPI = json.RawMessage(`{"asyncapi":"2.1.0"}`) +) + +// MarshalJSON encodes JSON. +func (a AsyncAPI) MarshalJSON() ([]byte, error) { + return marshalUnion(constAsyncAPI, marshalAsyncAPI(a), a.MapOfAnything) +} + +// Info structure is generated from "#/definitions/info". +// +// General information about the API. +type Info struct { + // A unique and precise title of the API. + // Required. + Title string `json:"title"` + // A semantic version number of the API. + // Required. + Version string `json:"version"` + Description string `json:"description,omitempty"` // A longer description of the API. Should be different from the title. CommonMark is allowed. + // A URL to the Terms of Service for the API. MUST be in the format of a URL. + // Format: uri. + TermsOfService string `json:"termsOfService,omitempty"` + Contact *Contact `json:"contact,omitempty"` // Contact information for the owners of the API. + License *License `json:"license,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalInfo Info + +var knownKeysInfo = []string{ + "title", + "version", + "description", + "termsOfService", + "contact", + "license", +} + +var requireKeysInfo = []string{ + "version", + "title", +} + +// UnmarshalJSON decodes JSON. +func (i *Info) UnmarshalJSON(data []byte) error { + var err error + + mi := marshalInfo(*i) + + err = json.Unmarshal(data, &mi) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysInfo { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + for _, key := range knownKeysInfo { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mi.MapOfAnything == nil { + mi.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mi.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in Info: %v", offendingKeys) + } + + *i = Info(mi) + + return nil +} + +// MarshalJSON encodes JSON. +func (i Info) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalInfo(i), i.MapOfAnything) +} + +// Contact structure is generated from "#/definitions/contact". +// +// Contact information for the owners of the API. +type Contact struct { + Name string `json:"name,omitempty"` // The identifying name of the contact person/organization. + // The URL pointing to the contact information. + // Format: uri. + URL string `json:"url,omitempty"` + // The email address of the contact person/organization. + // Format: email. + Email string `json:"email,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalContact Contact + +var knownKeysContact = []string{ + "name", + "url", + "email", +} + +// UnmarshalJSON decodes JSON. +func (c *Contact) UnmarshalJSON(data []byte) error { + var err error + + mc := marshalContact(*c) + + err = json.Unmarshal(data, &mc) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range knownKeysContact { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mc.MapOfAnything == nil { + mc.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mc.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in Contact: %v", offendingKeys) + } + + *c = Contact(mc) + + return nil +} + +// MarshalJSON encodes JSON. +func (c Contact) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalContact(c), c.MapOfAnything) +} + +// License structure is generated from "#/definitions/license". +type License struct { + // The name of the license type. It's encouraged to use an OSI compatible license. + // Required. + Name string `json:"name"` + // The URL pointing to the license. + // Format: uri. + URL string `json:"url,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalLicense License + +var knownKeysLicense = []string{ + "name", + "url", +} + +var requireKeysLicense = []string{ + "name", +} + +// UnmarshalJSON decodes JSON. +func (l *License) UnmarshalJSON(data []byte) error { + var err error + + ml := marshalLicense(*l) + + err = json.Unmarshal(data, &ml) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysLicense { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + for _, key := range knownKeysLicense { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ml.MapOfAnything == nil { + ml.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ml.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in License: %v", offendingKeys) + } + + *l = License(ml) + + return nil +} + +// MarshalJSON encodes JSON. +func (l License) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalLicense(l), l.MapOfAnything) +} + +// Server structure is generated from "#/definitions/server". +// +// An object representing a Server. +type Server struct { + URL string `json:"url"` // Required. + Description string `json:"description,omitempty"` + // The transfer protocol. + // Required. + Protocol string `json:"protocol"` + ProtocolVersion string `json:"protocolVersion,omitempty"` + Variables map[string]ServerVariable `json:"variables,omitempty"` + Security []map[string][]string `json:"security,omitempty"` + Bindings *BindingsObject `json:"bindings,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalServer Server + +var knownKeysServer = []string{ + "url", + "description", + "protocol", + "protocolVersion", + "variables", + "security", + "bindings", +} + +var requireKeysServer = []string{ + "url", + "protocol", +} + +// UnmarshalJSON decodes JSON. +func (s *Server) UnmarshalJSON(data []byte) error { + var err error + + ms := marshalServer(*s) + + err = json.Unmarshal(data, &ms) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysServer { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + for _, key := range knownKeysServer { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ms.MapOfAnything == nil { + ms.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ms.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in Server: %v", offendingKeys) + } + + *s = Server(ms) + + return nil +} + +// MarshalJSON encodes JSON. +func (s Server) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalServer(s), s.MapOfAnything) +} + +// ServerVariable structure is generated from "#/definitions/serverVariable". +// +// An object representing a Server Variable for server URL template substitution. +type ServerVariable struct { + Enum []string `json:"enum,omitempty"` + Default string `json:"default,omitempty"` + Description string `json:"description,omitempty"` + Examples []string `json:"examples,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalServerVariable ServerVariable + +var knownKeysServerVariable = []string{ + "enum", + "default", + "description", + "examples", +} + +// UnmarshalJSON decodes JSON. +func (s *ServerVariable) UnmarshalJSON(data []byte) error { + var err error + + ms := marshalServerVariable(*s) + + err = json.Unmarshal(data, &ms) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range knownKeysServerVariable { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ms.MapOfAnything == nil { + ms.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ms.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in ServerVariable: %v", offendingKeys) + } + + *s = ServerVariable(ms) + + return nil +} + +// MarshalJSON encodes JSON. +func (s ServerVariable) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalServerVariable(s), s.MapOfAnything) +} + +// BindingsObject structure is generated from "#/definitions/bindingsObject". +type BindingsObject struct { + HTTP *interface{} `json:"http,omitempty"` + Ws *interface{} `json:"ws,omitempty"` + Amqp *interface{} `json:"amqp,omitempty"` + Amqp1 *interface{} `json:"amqp1,omitempty"` + Mqtt *interface{} `json:"mqtt,omitempty"` + Mqtt5 *interface{} `json:"mqtt5,omitempty"` + Kafka *interface{} `json:"kafka,omitempty"` + Nats *interface{} `json:"nats,omitempty"` + Jms *interface{} `json:"jms,omitempty"` + Sns *interface{} `json:"sns,omitempty"` + Sqs *interface{} `json:"sqs,omitempty"` + Stomp *interface{} `json:"stomp,omitempty"` + Redis *interface{} `json:"redis,omitempty"` + Ibmmq *interface{} `json:"ibmmq,omitempty"` + AdditionalProperties map[string]interface{} `json:"-"` // All unmatched properties. +} + +type marshalBindingsObject BindingsObject + +var knownKeysBindingsObject = []string{ + "http", + "ws", + "amqp", + "amqp1", + "mqtt", + "mqtt5", + "kafka", + "nats", + "jms", + "sns", + "sqs", + "stomp", + "redis", + "ibmmq", +} + +// UnmarshalJSON decodes JSON. +func (b *BindingsObject) UnmarshalJSON(data []byte) error { + var err error + + mb := marshalBindingsObject(*b) + + err = json.Unmarshal(data, &mb) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + if mb.HTTP == nil { + if _, ok := rawMap["http"]; ok { + var v interface{} + mb.HTTP = &v + } + } + + if mb.Ws == nil { + if _, ok := rawMap["ws"]; ok { + var v interface{} + mb.Ws = &v + } + } + + if mb.Amqp == nil { + if _, ok := rawMap["amqp"]; ok { + var v interface{} + mb.Amqp = &v + } + } + + if mb.Amqp1 == nil { + if _, ok := rawMap["amqp1"]; ok { + var v interface{} + mb.Amqp1 = &v + } + } + + if mb.Mqtt == nil { + if _, ok := rawMap["mqtt"]; ok { + var v interface{} + mb.Mqtt = &v + } + } + + if mb.Mqtt5 == nil { + if _, ok := rawMap["mqtt5"]; ok { + var v interface{} + mb.Mqtt5 = &v + } + } + + if mb.Kafka == nil { + if _, ok := rawMap["kafka"]; ok { + var v interface{} + mb.Kafka = &v + } + } + + if mb.Nats == nil { + if _, ok := rawMap["nats"]; ok { + var v interface{} + mb.Nats = &v + } + } + + if mb.Jms == nil { + if _, ok := rawMap["jms"]; ok { + var v interface{} + mb.Jms = &v + } + } + + if mb.Sns == nil { + if _, ok := rawMap["sns"]; ok { + var v interface{} + mb.Sns = &v + } + } + + if mb.Sqs == nil { + if _, ok := rawMap["sqs"]; ok { + var v interface{} + mb.Sqs = &v + } + } + + if mb.Stomp == nil { + if _, ok := rawMap["stomp"]; ok { + var v interface{} + mb.Stomp = &v + } + } + + if mb.Redis == nil { + if _, ok := rawMap["redis"]; ok { + var v interface{} + mb.Redis = &v + } + } + + if mb.Ibmmq == nil { + if _, ok := rawMap["ibmmq"]; ok { + var v interface{} + mb.Ibmmq = &v + } + } + + for _, key := range knownKeysBindingsObject { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + if mb.AdditionalProperties == nil { + mb.AdditionalProperties = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mb.AdditionalProperties[key] = val + } + + *b = BindingsObject(mb) + + return nil +} + +// MarshalJSON encodes JSON. +func (b BindingsObject) MarshalJSON() ([]byte, error) { + if len(b.AdditionalProperties) == 0 { + return json.Marshal(marshalBindingsObject(b)) + } + + return marshalUnion(marshalBindingsObject(b), b.AdditionalProperties) +} + +// ChannelItem structure is generated from "#/definitions/channelItem". +type ChannelItem struct { + Ref string `json:"$ref,omitempty"` // Format: uri-reference. + Parameters map[string]Parameter `json:"parameters,omitempty"` + Description string `json:"description,omitempty"` // A description of the channel. + Publish *Operation `json:"publish,omitempty"` + Subscribe *Operation `json:"subscribe,omitempty"` + Deprecated bool `json:"deprecated,omitempty"` + Bindings *BindingsObject `json:"bindings,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalChannelItem ChannelItem + +var knownKeysChannelItem = []string{ + "$ref", + "parameters", + "description", + "publish", + "subscribe", + "deprecated", + "bindings", +} + +// UnmarshalJSON decodes JSON. +func (c *ChannelItem) UnmarshalJSON(data []byte) error { + var err error + + mc := marshalChannelItem(*c) + + err = json.Unmarshal(data, &mc) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range knownKeysChannelItem { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mc.MapOfAnything == nil { + mc.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mc.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in ChannelItem: %v", offendingKeys) + } + + *c = ChannelItem(mc) + + return nil +} + +// MarshalJSON encodes JSON. +func (c ChannelItem) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalChannelItem(c), c.MapOfAnything) +} + +// Parameter structure is generated from "#/definitions/parameter". +type Parameter struct { + Description string `json:"description,omitempty"` // A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed. + Schema *Schema `json:"schema,omitempty"` + // A runtime expression that specifies the location of the parameter value. + // Value must match pattern: `^\$message\.(header|payload)\#(\/(([^\/~])|(~[01]))*)*`. + Location string `json:"location,omitempty"` + Ref string `json:"$ref,omitempty"` // Format: uri-reference. + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalParameter Parameter + +var knownKeysParameter = []string{ + "description", + "schema", + "location", + "$ref", +} + +// UnmarshalJSON decodes JSON. +func (p *Parameter) UnmarshalJSON(data []byte) error { + var err error + + mp := marshalParameter(*p) + + err = json.Unmarshal(data, &mp) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range knownKeysParameter { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mp.MapOfAnything == nil { + mp.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mp.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in Parameter: %v", offendingKeys) + } + + *p = Parameter(mp) + + return nil +} + +// MarshalJSON encodes JSON. +func (p Parameter) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalParameter(p), p.MapOfAnything) +} + +// JSONSchema structure is generated from "jsonSchema". +// +// Core schema meta-schema. +type JSONSchema struct { + ID string `json:"id,omitempty"` // Format: uri. + Schema string `json:"$schema,omitempty"` // Format: uri. + Title string `json:"title,omitempty"` + Description string `json:"description,omitempty"` + Default *interface{} `json:"default,omitempty"` + MultipleOf float64 `json:"multipleOf,omitempty"` + Maximum float64 `json:"maximum,omitempty"` + ExclusiveMaximum *JSONSchemaExclusiveMaximum `json:"exclusiveMaximum,omitempty"` + Minimum float64 `json:"minimum,omitempty"` + ExclusiveMinimum *JSONSchemaExclusiveMinimum `json:"exclusiveMinimum,omitempty"` + MaxLength int64 `json:"maxLength,omitempty"` + MinLength int64 `json:"minLength,omitempty"` + Pattern string `json:"pattern,omitempty"` // Format: regex. + ExtraProperties map[string]interface{} `json:"-"` // All unmatched properties. + TypeObject *JSONSchema `json:"-"` + TypeBoolean *bool `json:"-"` + AdditionalItems *JSONSchemaAdditionalItems `json:"additionalItems,omitempty"` + Items *JSONSchemaItems `json:"items,omitempty"` + MaxItems int64 `json:"maxItems,omitempty"` + MinItems int64 `json:"minItems,omitempty"` + UniqueItems bool `json:"uniqueItems,omitempty"` + MaxProperties int64 `json:"maxProperties,omitempty"` + MinProperties int64 `json:"minProperties,omitempty"` + Required []string `json:"required,omitempty"` + AdditionalProperties *JSONSchemaAdditionalProperties `json:"additionalProperties,omitempty"` + Definitions map[string]interface{} `json:"definitions,omitempty"` + Properties map[string]interface{} `json:"properties,omitempty"` + PatternProperties map[string]interface{} `json:"patternProperties,omitempty"` + Dependencies map[string]JSONSchemaDependenciesAdditionalProperties `json:"dependencies,omitempty"` + Enum []interface{} `json:"enum,omitempty"` + Type *JSONSchemaType `json:"type,omitempty"` + Format string `json:"format,omitempty"` + Ref string `json:"$ref,omitempty"` // Format: uri-reference. + AllOf []interface{} `json:"allOf,omitempty"` + AnyOf []interface{} `json:"anyOf,omitempty"` + OneOf []interface{} `json:"oneOf,omitempty"` + Not *JSONSchema `json:"not,omitempty"` // Core schema meta-schema. + Const *interface{} `json:"const,omitempty"` + Contains *JSONSchema `json:"contains,omitempty"` // Core schema meta-schema. + PropertyNames *JSONSchema `json:"propertyNames,omitempty"` // Core schema meta-schema. + If *JSONSchema `json:"if,omitempty"` // Core schema meta-schema. + Then *JSONSchema `json:"then,omitempty"` // Core schema meta-schema. + Else *JSONSchema `json:"else,omitempty"` // Core schema meta-schema. + ContentEncoding string `json:"contentEncoding,omitempty"` + ContentMediaType string `json:"contentMediaType,omitempty"` +} + +type marshalJSONSchema JSONSchema + +var knownKeysJSONSchema = []string{ + "id", + "$schema", + "title", + "description", + "default", + "multipleOf", + "maximum", + "exclusiveMaximum", + "minimum", + "exclusiveMinimum", + "maxLength", + "minLength", + "pattern", + "additionalItems", + "items", + "maxItems", + "minItems", + "uniqueItems", + "maxProperties", + "minProperties", + "required", + "additionalProperties", + "definitions", + "properties", + "patternProperties", + "dependencies", + "enum", + "type", + "format", + "$ref", + "allOf", + "anyOf", + "oneOf", + "not", + "const", + "contains", + "propertyNames", + "if", + "then", + "else", + "contentEncoding", + "contentMediaType", +} + +// UnmarshalJSON decodes JSON. +func (j *JSONSchema) UnmarshalJSON(data []byte) error { + var err error + + mj := marshalJSONSchema(*j) + + err = json.Unmarshal(data, &mj) + if err != nil { + return err + } + + typeValid := false + + if !typeValid { + err = json.Unmarshal(data, &mj.TypeObject) + if err != nil { + mj.TypeObject = nil + } else { + typeValid = true + } + } + + if !typeValid { + err = json.Unmarshal(data, &mj.TypeBoolean) + if err != nil { + mj.TypeBoolean = nil + } else { + typeValid = true + } + } + + if !typeValid { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + if mj.Default == nil { + if _, ok := rawMap["default"]; ok { + var v interface{} + mj.Default = &v + } + } + + if mj.Const == nil { + if _, ok := rawMap["const"]; ok { + var v interface{} + mj.Const = &v + } + } + + for _, key := range knownKeysJSONSchema { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + if mj.ExtraProperties == nil { + mj.ExtraProperties = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mj.ExtraProperties[key] = val + } + + *j = JSONSchema(mj) + + return nil +} + +// MarshalJSON encodes JSON. +func (j JSONSchema) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalJSONSchema(j), j.ExtraProperties, j.TypeObject, j.TypeBoolean) +} + +// JSONSchemaExclusiveMaximum structure is generated from "jsonSchema->exclusiveMaximum". +type JSONSchemaExclusiveMaximum struct { + TypeBoolean *bool `json:"-"` + TypeNumber *float64 `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (j *JSONSchemaExclusiveMaximum) UnmarshalJSON(data []byte) error { + var err error + + typeValid := false + + if !typeValid { + err = json.Unmarshal(data, &j.TypeBoolean) + if err != nil { + j.TypeBoolean = nil + } else { + typeValid = true + } + } + + if !typeValid { + err = json.Unmarshal(data, &j.TypeNumber) + if err != nil { + j.TypeNumber = nil + } else { + typeValid = true + } + } + + if !typeValid { + return err + } + + return nil +} + +// MarshalJSON encodes JSON. +func (j JSONSchemaExclusiveMaximum) MarshalJSON() ([]byte, error) { + return marshalUnion(j.TypeBoolean, j.TypeNumber) +} + +// JSONSchemaExclusiveMinimum structure is generated from "jsonSchema->exclusiveMinimum". +type JSONSchemaExclusiveMinimum struct { + TypeBoolean *bool `json:"-"` + TypeNumber *float64 `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (j *JSONSchemaExclusiveMinimum) UnmarshalJSON(data []byte) error { + var err error + + typeValid := false + + if !typeValid { + err = json.Unmarshal(data, &j.TypeBoolean) + if err != nil { + j.TypeBoolean = nil + } else { + typeValid = true + } + } + + if !typeValid { + err = json.Unmarshal(data, &j.TypeNumber) + if err != nil { + j.TypeNumber = nil + } else { + typeValid = true + } + } + + if !typeValid { + return err + } + + return nil +} + +// MarshalJSON encodes JSON. +func (j JSONSchemaExclusiveMinimum) MarshalJSON() ([]byte, error) { + return marshalUnion(j.TypeBoolean, j.TypeNumber) +} + +// JSONSchemaAdditionalItems structure is generated from "jsonSchema->additionalItems". +type JSONSchemaAdditionalItems struct { + Bool *bool `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (j *JSONSchemaAdditionalItems) UnmarshalJSON(data []byte) error { + var err error + + anyOfErrors := make(map[string]error, 1) + anyOfValid := 0 + + err = json.Unmarshal(data, &j.Bool) + if err != nil { + anyOfErrors["Bool"] = err + j.Bool = nil + } else { + anyOfValid++ + } + + if anyOfValid == 0 { + return fmt.Errorf("anyOf constraint for JSONSchemaAdditionalItems failed with %d valid results: %v", anyOfValid, anyOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (j JSONSchemaAdditionalItems) MarshalJSON() ([]byte, error) { + return marshalUnion(j.Bool) +} + +// JSONSchemaItems structure is generated from "jsonSchema->items". +type JSONSchemaItems struct { + SliceOfAnything []interface{} `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (j *JSONSchemaItems) UnmarshalJSON(data []byte) error { + var err error + + anyOfErrors := make(map[string]error, 1) + anyOfValid := 0 + + err = json.Unmarshal(data, &j.SliceOfAnything) + if err != nil { + anyOfErrors["SliceOfAnything"] = err + j.SliceOfAnything = nil + } else { + anyOfValid++ + } + + if anyOfValid == 0 { + return fmt.Errorf("anyOf constraint for JSONSchemaItems failed with %d valid results: %v", anyOfValid, anyOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (j JSONSchemaItems) MarshalJSON() ([]byte, error) { + return marshalUnion(j.SliceOfAnything) +} + +// JSONSchemaAdditionalProperties structure is generated from "jsonSchema->additionalProperties". +type JSONSchemaAdditionalProperties struct { + Bool *bool `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (j *JSONSchemaAdditionalProperties) UnmarshalJSON(data []byte) error { + var err error + + anyOfErrors := make(map[string]error, 1) + anyOfValid := 0 + + err = json.Unmarshal(data, &j.Bool) + if err != nil { + anyOfErrors["Bool"] = err + j.Bool = nil + } else { + anyOfValid++ + } + + if anyOfValid == 0 { + return fmt.Errorf("anyOf constraint for JSONSchemaAdditionalProperties failed with %d valid results: %v", anyOfValid, anyOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (j JSONSchemaAdditionalProperties) MarshalJSON() ([]byte, error) { + return marshalUnion(j.Bool) +} + +// JSONSchemaDependenciesAdditionalProperties structure is generated from "jsonSchema->dependencies->additionalProperties". +type JSONSchemaDependenciesAdditionalProperties struct { + SliceOfStringValues []string `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (j *JSONSchemaDependenciesAdditionalProperties) UnmarshalJSON(data []byte) error { + var err error + + anyOfErrors := make(map[string]error, 1) + anyOfValid := 0 + + err = json.Unmarshal(data, &j.SliceOfStringValues) + if err != nil { + anyOfErrors["SliceOfStringValues"] = err + j.SliceOfStringValues = nil + } else { + anyOfValid++ + } + + if anyOfValid == 0 { + return fmt.Errorf("anyOf constraint for JSONSchemaDependenciesAdditionalProperties failed with %d valid results: %v", anyOfValid, anyOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (j JSONSchemaDependenciesAdditionalProperties) MarshalJSON() ([]byte, error) { + return marshalUnion(j.SliceOfStringValues) +} + +// JSONSchemaType structure is generated from "jsonSchema->type". +type JSONSchemaType struct { + AnyOf0 *JSONSchemaTypeAnyOf0 `json:"-"` + SliceOfJSONSchemaTypeAnyOf1ItemsValues []JSONSchemaTypeAnyOf1Items `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (j *JSONSchemaType) UnmarshalJSON(data []byte) error { + var err error + + anyOfErrors := make(map[string]error, 2) + anyOfValid := 0 + + err = json.Unmarshal(data, &j.AnyOf0) + if err != nil { + anyOfErrors["AnyOf0"] = err + j.AnyOf0 = nil + } else { + anyOfValid++ + } + + err = json.Unmarshal(data, &j.SliceOfJSONSchemaTypeAnyOf1ItemsValues) + if err != nil { + anyOfErrors["SliceOfJSONSchemaTypeAnyOf1ItemsValues"] = err + j.SliceOfJSONSchemaTypeAnyOf1ItemsValues = nil + } else { + anyOfValid++ + } + + if anyOfValid == 0 { + return fmt.Errorf("anyOf constraint for JSONSchemaType failed with %d valid results: %v", anyOfValid, anyOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (j JSONSchemaType) MarshalJSON() ([]byte, error) { + return marshalUnion(j.AnyOf0, j.SliceOfJSONSchemaTypeAnyOf1ItemsValues) +} + +// SchemaAllOf1 structure is generated from "#/definitions/schema/allOf/1". +type SchemaAllOf1 struct { + AdditionalProperties *SchemaAllOf1AdditionalProperties `json:"additionalProperties,omitempty"` + Items *SchemaAllOf1Items `json:"items,omitempty"` + AllOf []Schema `json:"allOf,omitempty"` + OneOf []Schema `json:"oneOf,omitempty"` + AnyOf []Schema `json:"anyOf,omitempty"` + Not *Schema `json:"not,omitempty"` + Properties map[string]Schema `json:"properties,omitempty"` + PatternProperties map[string]Schema `json:"patternProperties,omitempty"` + PropertyNames *Schema `json:"propertyNames,omitempty"` + Contains *Schema `json:"contains,omitempty"` + Discriminator string `json:"discriminator,omitempty"` + ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` // Information about external documentation. + Deprecated bool `json:"deprecated,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. + ExtraProperties map[string]interface{} `json:"-"` // All unmatched properties. +} + +type marshalSchemaAllOf1 SchemaAllOf1 + +var knownKeysSchemaAllOf1 = []string{ + "additionalProperties", + "items", + "allOf", + "oneOf", + "anyOf", + "not", + "properties", + "patternProperties", + "propertyNames", + "contains", + "discriminator", + "externalDocs", + "deprecated", +} + +// UnmarshalJSON decodes JSON. +func (s *SchemaAllOf1) UnmarshalJSON(data []byte) error { + var err error + + ms := marshalSchemaAllOf1(*s) + + err = json.Unmarshal(data, &ms) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range knownKeysSchemaAllOf1 { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ms.MapOfAnything == nil { + ms.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ms.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + for key, rawValue := range rawMap { + if ms.ExtraProperties == nil { + ms.ExtraProperties = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ms.ExtraProperties[key] = val + } + + *s = SchemaAllOf1(ms) + + return nil +} + +// MarshalJSON encodes JSON. +func (s SchemaAllOf1) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalSchemaAllOf1(s), s.MapOfAnything, s.ExtraProperties) +} + +// Schema structure is generated from "#/definitions/schema". +type Schema struct { + AllOf1 *SchemaAllOf1 `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (s *Schema) UnmarshalJSON(data []byte) error { + var err error + + err = json.Unmarshal(data, &s.AllOf1) + if err != nil { + return err + } + + return nil +} + +// MarshalJSON encodes JSON. +func (s Schema) MarshalJSON() ([]byte, error) { + return marshalUnion(s.AllOf1) +} + +// SchemaAllOf1AdditionalProperties structure is generated from "#/definitions/schema/allOf/1->additionalProperties". +type SchemaAllOf1AdditionalProperties struct { + Schema *Schema `json:"-"` + Bool *bool `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (s *SchemaAllOf1AdditionalProperties) UnmarshalJSON(data []byte) error { + var err error + + anyOfErrors := make(map[string]error, 2) + anyOfValid := 0 + + err = json.Unmarshal(data, &s.Schema) + if err != nil { + anyOfErrors["Schema"] = err + s.Schema = nil + } else { + anyOfValid++ + } + + err = json.Unmarshal(data, &s.Bool) + if err != nil { + anyOfErrors["Bool"] = err + s.Bool = nil + } else { + anyOfValid++ + } + + if anyOfValid == 0 { + return fmt.Errorf("anyOf constraint for SchemaAllOf1AdditionalProperties failed with %d valid results: %v", anyOfValid, anyOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (s SchemaAllOf1AdditionalProperties) MarshalJSON() ([]byte, error) { + return marshalUnion(s.Schema, s.Bool) +} + +// SchemaAllOf1Items structure is generated from "#/definitions/schema/allOf/1->items". +type SchemaAllOf1Items struct { + Schema *Schema `json:"-"` + SliceOfSchemaValues []Schema `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (s *SchemaAllOf1Items) UnmarshalJSON(data []byte) error { + var err error + + anyOfErrors := make(map[string]error, 2) + anyOfValid := 0 + + err = json.Unmarshal(data, &s.Schema) + if err != nil { + anyOfErrors["Schema"] = err + s.Schema = nil + } else { + anyOfValid++ + } + + err = json.Unmarshal(data, &s.SliceOfSchemaValues) + if err != nil { + anyOfErrors["SliceOfSchemaValues"] = err + s.SliceOfSchemaValues = nil + } else { + anyOfValid++ + } + + if anyOfValid == 0 { + return fmt.Errorf("anyOf constraint for SchemaAllOf1Items failed with %d valid results: %v", anyOfValid, anyOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (s SchemaAllOf1Items) MarshalJSON() ([]byte, error) { + return marshalUnion(s.Schema, s.SliceOfSchemaValues) +} + +// ExternalDocs structure is generated from "#/definitions/externalDocs". +// +// information about external documentation. +type ExternalDocs struct { + Description string `json:"description,omitempty"` + // Format: uri. + // Required. + URL string `json:"url"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalExternalDocs ExternalDocs + +var knownKeysExternalDocs = []string{ + "description", + "url", +} + +var requireKeysExternalDocs = []string{ + "url", +} + +// UnmarshalJSON decodes JSON. +func (e *ExternalDocs) UnmarshalJSON(data []byte) error { + var err error + + me := marshalExternalDocs(*e) + + err = json.Unmarshal(data, &me) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysExternalDocs { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + for _, key := range knownKeysExternalDocs { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if me.MapOfAnything == nil { + me.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + me.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in ExternalDocs: %v", offendingKeys) + } + + *e = ExternalDocs(me) + + return nil +} + +// MarshalJSON encodes JSON. +func (e ExternalDocs) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalExternalDocs(e), e.MapOfAnything) +} + +// Operation structure is generated from "#/definitions/operation". +type Operation struct { + Traits []OperationTraitsItems `json:"traits,omitempty"` + Summary string `json:"summary,omitempty"` + Description string `json:"description,omitempty"` + Tags []Tag `json:"tags,omitempty"` + ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` // Information about external documentation. + ID string `json:"operationId,omitempty"` + Bindings *BindingsObject `json:"bindings,omitempty"` + Message *Message `json:"message,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalOperation Operation + +var knownKeysOperation = []string{ + "traits", + "summary", + "description", + "tags", + "externalDocs", + "operationId", + "bindings", + "message", +} + +// UnmarshalJSON decodes JSON. +func (o *Operation) UnmarshalJSON(data []byte) error { + var err error + + mo := marshalOperation(*o) + + err = json.Unmarshal(data, &mo) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range knownKeysOperation { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mo.MapOfAnything == nil { + mo.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mo.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in Operation: %v", offendingKeys) + } + + *o = Operation(mo) + + return nil +} + +// MarshalJSON encodes JSON. +func (o Operation) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalOperation(o), o.MapOfAnything) +} + +// Reference structure is generated from "#/definitions/Reference". +type Reference struct { + // Format: uri-reference. + // Required. + Ref string `json:"$ref"` + AdditionalProperties map[string]interface{} `json:"-"` // All unmatched properties. +} + +type marshalReference Reference + +var knownKeysReference = []string{ + "$ref", +} + +var requireKeysReference = []string{ + "$ref", +} + +// UnmarshalJSON decodes JSON. +func (r *Reference) UnmarshalJSON(data []byte) error { + var err error + + mr := marshalReference(*r) + + err = json.Unmarshal(data, &mr) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysReference { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + for _, key := range knownKeysReference { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + if mr.AdditionalProperties == nil { + mr.AdditionalProperties = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mr.AdditionalProperties[key] = val + } + + *r = Reference(mr) + + return nil +} + +// MarshalJSON encodes JSON. +func (r Reference) MarshalJSON() ([]byte, error) { + if len(r.AdditionalProperties) == 0 { + return json.Marshal(marshalReference(r)) + } + + return marshalUnion(marshalReference(r), r.AdditionalProperties) +} + +// OperationTrait structure is generated from "#/definitions/operationTrait". +type OperationTrait struct { + Summary string `json:"summary,omitempty"` + Description string `json:"description,omitempty"` + Tags []Tag `json:"tags,omitempty"` + ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` // Information about external documentation. + OperationID string `json:"operationId,omitempty"` + Bindings *BindingsObject `json:"bindings,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalOperationTrait OperationTrait + +var knownKeysOperationTrait = []string{ + "summary", + "description", + "tags", + "externalDocs", + "operationId", + "bindings", +} + +// UnmarshalJSON decodes JSON. +func (o *OperationTrait) UnmarshalJSON(data []byte) error { + var err error + + mo := marshalOperationTrait(*o) + + err = json.Unmarshal(data, &mo) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range knownKeysOperationTrait { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mo.MapOfAnything == nil { + mo.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mo.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in OperationTrait: %v", offendingKeys) + } + + *o = OperationTrait(mo) + + return nil +} + +// MarshalJSON encodes JSON. +func (o OperationTrait) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalOperationTrait(o), o.MapOfAnything) +} + +// Tag structure is generated from "#/definitions/tag". +type Tag struct { + Name string `json:"name"` // Required. + Description string `json:"description,omitempty"` + ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` // Information about external documentation. + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalTag Tag + +var knownKeysTag = []string{ + "name", + "description", + "externalDocs", +} + +var requireKeysTag = []string{ + "name", +} + +// UnmarshalJSON decodes JSON. +func (t *Tag) UnmarshalJSON(data []byte) error { + var err error + + mt := marshalTag(*t) + + err = json.Unmarshal(data, &mt) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysTag { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + for _, key := range knownKeysTag { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mt.MapOfAnything == nil { + mt.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mt.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in Tag: %v", offendingKeys) + } + + *t = Tag(mt) + + return nil +} + +// MarshalJSON encodes JSON. +func (t Tag) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalTag(t), t.MapOfAnything) +} + +// OperationTraitsItems structure is generated from "#/definitions/operation->traits->items". +type OperationTraitsItems struct { + Reference *Reference `json:"-"` + OperationTrait *OperationTrait `json:"-"` + SliceOfAnything []interface{} `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (o *OperationTraitsItems) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 3) + oneOfValid := 0 + + err = json.Unmarshal(data, &o.Reference) + if err != nil { + oneOfErrors["Reference"] = err + o.Reference = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &o.OperationTrait) + if err != nil { + oneOfErrors["OperationTrait"] = err + o.OperationTrait = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &o.SliceOfAnything) + if err != nil { + oneOfErrors["SliceOfAnything"] = err + o.SliceOfAnything = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for OperationTraitsItems with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (o OperationTraitsItems) MarshalJSON() ([]byte, error) { + return marshalUnion(o.Reference, o.OperationTrait, o.SliceOfAnything) +} + +// MessageOneOf1OneOf0 structure is generated from "#/definitions/message/oneOf/1/oneOf/0". +type MessageOneOf1OneOf0 struct { + OneOf []Message `json:"oneOf"` // Required. +} + +type marshalMessageOneOf1OneOf0 MessageOneOf1OneOf0 + +var knownKeysMessageOneOf1OneOf0 = []string{ + "oneOf", +} + +var requireKeysMessageOneOf1OneOf0 = []string{ + "oneOf", +} + +// UnmarshalJSON decodes JSON. +func (m *MessageOneOf1OneOf0) UnmarshalJSON(data []byte) error { + var err error + + mm := marshalMessageOneOf1OneOf0(*m) + + err = json.Unmarshal(data, &mm) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysMessageOneOf1OneOf0 { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + for _, key := range knownKeysMessageOneOf1OneOf0 { + delete(rawMap, key) + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in MessageOneOf1OneOf0: %v", offendingKeys) + } + + *m = MessageOneOf1OneOf0(mm) + + return nil +} + + +// MessageOneOf1OneOf1 structure is generated from "#/definitions/message/oneOf/1/oneOf/1". +type MessageOneOf1OneOf1 struct { + SchemaFormat string `json:"schemaFormat,omitempty"` + ContentType string `json:"contentType,omitempty"` + Headers *MessageOneOf1OneOf1Headers `json:"headers,omitempty"` + Payload *interface{} `json:"payload,omitempty"` + CorrelationID *MessageOneOf1OneOf1CorrelationID `json:"correlationId,omitempty"` + Tags []Tag `json:"tags,omitempty"` + Summary string `json:"summary,omitempty"` // A brief summary of the message. + Name string `json:"name,omitempty"` // Name of the message. + Title string `json:"title,omitempty"` // A human-friendly title for the message. + Description string `json:"description,omitempty"` // A longer description of the message. CommonMark is allowed. + ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` // Information about external documentation. + Deprecated bool `json:"deprecated,omitempty"` + Examples []MessageOneOf1OneOf1ExamplesItems `json:"examples,omitempty"` + Bindings *BindingsObject `json:"bindings,omitempty"` + Traits []MessageOneOf1OneOf1TraitsItems `json:"traits,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalMessageOneOf1OneOf1 MessageOneOf1OneOf1 + +var knownKeysMessageOneOf1OneOf1 = []string{ + "schemaFormat", + "contentType", + "headers", + "payload", + "correlationId", + "tags", + "summary", + "name", + "title", + "description", + "externalDocs", + "deprecated", + "examples", + "bindings", + "traits", +} + +// UnmarshalJSON decodes JSON. +func (m *MessageOneOf1OneOf1) UnmarshalJSON(data []byte) error { + var err error + + mm := marshalMessageOneOf1OneOf1(*m) + + err = json.Unmarshal(data, &mm) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + if mm.Payload == nil { + if _, ok := rawMap["payload"]; ok { + var v interface{} + mm.Payload = &v + } + } + + for _, key := range knownKeysMessageOneOf1OneOf1 { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mm.MapOfAnything == nil { + mm.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mm.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in MessageOneOf1OneOf1: %v", offendingKeys) + } + + *m = MessageOneOf1OneOf1(mm) + + return nil +} + +// MarshalJSON encodes JSON. +func (m MessageOneOf1OneOf1) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalMessageOneOf1OneOf1(m), m.MapOfAnything) +} + +// MessageOneOf1OneOf1HeadersAllOf1 structure is generated from "#/definitions/message/oneOf/1/oneOf/1->headers/allOf/1". +type MessageOneOf1OneOf1HeadersAllOf1 struct { + AdditionalProperties map[string]interface{} `json:"-"` // All unmatched properties. +} + +// UnmarshalJSON decodes JSON. +func (m *MessageOneOf1OneOf1HeadersAllOf1) UnmarshalJSON(data []byte) error { + var err error + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + if v, exists := rawMap["type"]; exists && string(v) != `"object"` { + return fmt.Errorf(`bad const value for "type" ("object" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for key, rawValue := range rawMap { + if m.AdditionalProperties == nil { + m.AdditionalProperties = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + m.AdditionalProperties[key] = val + } + + return nil +} + +var ( + // constMessageOneOf1OneOf1HeadersAllOf1 is unconditionally added to JSON. + constMessageOneOf1OneOf1HeadersAllOf1 = json.RawMessage(`{"type":"object"}`) +) + +// MarshalJSON encodes JSON. +func (m MessageOneOf1OneOf1HeadersAllOf1) MarshalJSON() ([]byte, error) { + return marshalUnion(constMessageOneOf1OneOf1HeadersAllOf1, m.AdditionalProperties) +} + +// MessageOneOf1OneOf1Headers structure is generated from "#/definitions/message/oneOf/1/oneOf/1->headers". +type MessageOneOf1OneOf1Headers struct { + Schema *Schema `json:"-"` + AllOf1 *MessageOneOf1OneOf1HeadersAllOf1 `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (m *MessageOneOf1OneOf1Headers) UnmarshalJSON(data []byte) error { + var err error + + err = json.Unmarshal(data, &m.Schema) + if err != nil { + return err + } + + err = json.Unmarshal(data, &m.AllOf1) + if err != nil { + return err + } + + return nil +} + +// MarshalJSON encodes JSON. +func (m MessageOneOf1OneOf1Headers) MarshalJSON() ([]byte, error) { + return marshalUnion(m.Schema, m.AllOf1) +} + +// CorrelationID structure is generated from "#/definitions/correlationId". +type CorrelationID struct { + Description string `json:"description,omitempty"` // A optional description of the correlation ID. GitHub Flavored Markdown is allowed. + // A runtime expression that specifies the location of the correlation ID. + // Value must match pattern: `^\$message\.(header|payload)\#(\/(([^\/~])|(~[01]))*)*`. + // Required. + Location string `json:"location"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalCorrelationID CorrelationID + +var knownKeysCorrelationID = []string{ + "description", + "location", +} + +var requireKeysCorrelationID = []string{ + "location", +} + +// UnmarshalJSON decodes JSON. +func (c *CorrelationID) UnmarshalJSON(data []byte) error { + var err error + + mc := marshalCorrelationID(*c) + + err = json.Unmarshal(data, &mc) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysCorrelationID { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + for _, key := range knownKeysCorrelationID { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mc.MapOfAnything == nil { + mc.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mc.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in CorrelationID: %v", offendingKeys) + } + + *c = CorrelationID(mc) + + return nil +} + +// MarshalJSON encodes JSON. +func (c CorrelationID) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalCorrelationID(c), c.MapOfAnything) +} + +// MessageOneOf1OneOf1CorrelationID structure is generated from "#/definitions/message/oneOf/1/oneOf/1->correlationId". +type MessageOneOf1OneOf1CorrelationID struct { + Reference *Reference `json:"-"` + CorrelationID *CorrelationID `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (m *MessageOneOf1OneOf1CorrelationID) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 2) + oneOfValid := 0 + + err = json.Unmarshal(data, &m.Reference) + if err != nil { + oneOfErrors["Reference"] = err + m.Reference = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &m.CorrelationID) + if err != nil { + oneOfErrors["CorrelationID"] = err + m.CorrelationID = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for MessageOneOf1OneOf1CorrelationID with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (m MessageOneOf1OneOf1CorrelationID) MarshalJSON() ([]byte, error) { + return marshalUnion(m.Reference, m.CorrelationID) +} + +// MessageOneOf1OneOf1ExamplesItems structure is generated from "#/definitions/message/oneOf/1/oneOf/1->examples->items". +type MessageOneOf1OneOf1ExamplesItems struct { + Name string `json:"name,omitempty"` // Machine readable name of the message example. + Summary string `json:"summary,omitempty"` // A brief summary of the message example. + Headers map[string]interface{} `json:"headers,omitempty"` + Payload *interface{} `json:"payload,omitempty"` +} + +type marshalMessageOneOf1OneOf1ExamplesItems MessageOneOf1OneOf1ExamplesItems + +var knownKeysMessageOneOf1OneOf1ExamplesItems = []string{ + "name", + "summary", + "headers", + "payload", +} + +// UnmarshalJSON decodes JSON. +func (m *MessageOneOf1OneOf1ExamplesItems) UnmarshalJSON(data []byte) error { + var err error + + mm := marshalMessageOneOf1OneOf1ExamplesItems(*m) + + err = json.Unmarshal(data, &mm) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + if mm.Payload == nil { + if _, ok := rawMap["payload"]; ok { + var v interface{} + mm.Payload = &v + } + } + + for _, key := range knownKeysMessageOneOf1OneOf1ExamplesItems { + delete(rawMap, key) + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in MessageOneOf1OneOf1ExamplesItems: %v", offendingKeys) + } + + *m = MessageOneOf1OneOf1ExamplesItems(mm) + + return nil +} + + +// MessageTrait structure is generated from "#/definitions/messageTrait". +type MessageTrait struct { + SchemaFormat string `json:"schemaFormat,omitempty"` + ContentType string `json:"contentType,omitempty"` + Headers *MessageTraitHeaders `json:"headers,omitempty"` + CorrelationID *MessageTraitCorrelationID `json:"correlationId,omitempty"` + Tags []Tag `json:"tags,omitempty"` + Summary string `json:"summary,omitempty"` // A brief summary of the message. + Name string `json:"name,omitempty"` // Name of the message. + Title string `json:"title,omitempty"` // A human-friendly title for the message. + Description string `json:"description,omitempty"` // A longer description of the message. CommonMark is allowed. + ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` // Information about external documentation. + Deprecated bool `json:"deprecated,omitempty"` + Examples []map[string]interface{} `json:"examples,omitempty"` + Bindings *BindingsObject `json:"bindings,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalMessageTrait MessageTrait + +var knownKeysMessageTrait = []string{ + "schemaFormat", + "contentType", + "headers", + "correlationId", + "tags", + "summary", + "name", + "title", + "description", + "externalDocs", + "deprecated", + "examples", + "bindings", +} + +// UnmarshalJSON decodes JSON. +func (m *MessageTrait) UnmarshalJSON(data []byte) error { + var err error + + mm := marshalMessageTrait(*m) + + err = json.Unmarshal(data, &mm) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range knownKeysMessageTrait { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mm.MapOfAnything == nil { + mm.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mm.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in MessageTrait: %v", offendingKeys) + } + + *m = MessageTrait(mm) + + return nil +} + +// MarshalJSON encodes JSON. +func (m MessageTrait) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalMessageTrait(m), m.MapOfAnything) +} + +// MessageTraitHeaders structure is generated from "#/definitions/messageTrait->headers". +type MessageTraitHeaders struct { + Reference *Reference `json:"-"` + Schema *Schema `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (m *MessageTraitHeaders) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 2) + oneOfValid := 0 + + err = json.Unmarshal(data, &m.Reference) + if err != nil { + oneOfErrors["Reference"] = err + m.Reference = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &m.Schema) + if err != nil { + oneOfErrors["Schema"] = err + m.Schema = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for MessageTraitHeaders with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (m MessageTraitHeaders) MarshalJSON() ([]byte, error) { + return marshalUnion(m.Reference, m.Schema) +} + +// MessageTraitCorrelationID structure is generated from "#/definitions/messageTrait->correlationId". +type MessageTraitCorrelationID struct { + Reference *Reference `json:"-"` + CorrelationID *CorrelationID `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (m *MessageTraitCorrelationID) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 2) + oneOfValid := 0 + + err = json.Unmarshal(data, &m.Reference) + if err != nil { + oneOfErrors["Reference"] = err + m.Reference = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &m.CorrelationID) + if err != nil { + oneOfErrors["CorrelationID"] = err + m.CorrelationID = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for MessageTraitCorrelationID with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (m MessageTraitCorrelationID) MarshalJSON() ([]byte, error) { + return marshalUnion(m.Reference, m.CorrelationID) +} + +// MessageOneOf1OneOf1TraitsItems structure is generated from "#/definitions/message/oneOf/1/oneOf/1->traits->items". +type MessageOneOf1OneOf1TraitsItems struct { + Reference *Reference `json:"-"` + MessageTrait *MessageTrait `json:"-"` + SliceOfAnything []interface{} `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (m *MessageOneOf1OneOf1TraitsItems) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 3) + oneOfValid := 0 + + err = json.Unmarshal(data, &m.Reference) + if err != nil { + oneOfErrors["Reference"] = err + m.Reference = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &m.MessageTrait) + if err != nil { + oneOfErrors["MessageTrait"] = err + m.MessageTrait = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &m.SliceOfAnything) + if err != nil { + oneOfErrors["SliceOfAnything"] = err + m.SliceOfAnything = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for MessageOneOf1OneOf1TraitsItems with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (m MessageOneOf1OneOf1TraitsItems) MarshalJSON() ([]byte, error) { + return marshalUnion(m.Reference, m.MessageTrait, m.SliceOfAnything) +} + +// MessageOneOf1 structure is generated from "#/definitions/message/oneOf/1". +type MessageOneOf1 struct { + OneOf0 *MessageOneOf1OneOf0 `json:"-"` + OneOf1 *MessageOneOf1OneOf1 `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (m *MessageOneOf1) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 2) + oneOfValid := 0 + + err = json.Unmarshal(data, &m.OneOf0) + if err != nil { + oneOfErrors["OneOf0"] = err + m.OneOf0 = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &m.OneOf1) + if err != nil { + oneOfErrors["OneOf1"] = err + m.OneOf1 = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for MessageOneOf1 with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (m MessageOneOf1) MarshalJSON() ([]byte, error) { + return marshalUnion(m.OneOf0, m.OneOf1) +} + +// Message structure is generated from "#/definitions/message". +type Message struct { + Reference *Reference `json:"-"` + OneOf1 *MessageOneOf1 `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (m *Message) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 2) + oneOfValid := 0 + + err = json.Unmarshal(data, &m.Reference) + if err != nil { + oneOfErrors["Reference"] = err + m.Reference = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &m.OneOf1) + if err != nil { + oneOfErrors["OneOf1"] = err + m.OneOf1 = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for Message with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (m Message) MarshalJSON() ([]byte, error) { + return marshalUnion(m.Reference, m.OneOf1) +} + +// Components structure is generated from "#/definitions/components". +// +// An object to hold a set of reusable objects for different aspects of the AsyncAPI Specification. +type Components struct { + Schemas map[string]Schema `json:"schemas,omitempty"` // JSON objects describing schemas the API uses. + Messages map[string]Message `json:"messages,omitempty"` // JSON objects describing the messages being consumed and produced by the API. + SecuritySchemes *ComponentsSecuritySchemes `json:"securitySchemes,omitempty"` + Parameters map[string]Parameter `json:"parameters,omitempty"` // JSON objects describing re-usable channel parameters. + CorrelationIds *ComponentsCorrelationIds `json:"correlationIds,omitempty"` + OperationTraits map[string]OperationTrait `json:"operationTraits,omitempty"` + MessageTraits map[string]MessageTrait `json:"messageTraits,omitempty"` + ServerBindings map[string]BindingsObject `json:"serverBindings,omitempty"` + ChannelBindings map[string]BindingsObject `json:"channelBindings,omitempty"` + OperationBindings map[string]BindingsObject `json:"operationBindings,omitempty"` + MessageBindings map[string]BindingsObject `json:"messageBindings,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalComponents Components + +var knownKeysComponents = []string{ + "schemas", + "messages", + "securitySchemes", + "parameters", + "correlationIds", + "operationTraits", + "messageTraits", + "serverBindings", + "channelBindings", + "operationBindings", + "messageBindings", +} + +// UnmarshalJSON decodes JSON. +func (c *Components) UnmarshalJSON(data []byte) error { + var err error + + mc := marshalComponents(*c) + + err = json.Unmarshal(data, &mc) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range knownKeysComponents { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mc.MapOfAnything == nil { + mc.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mc.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in Components: %v", offendingKeys) + } + + *c = Components(mc) + + return nil +} + +// MarshalJSON encodes JSON. +func (c Components) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalComponents(c), c.MapOfAnything) +} + +// UserPassword structure is generated from "#/definitions/userPassword". +type UserPassword struct { + Description string `json:"description,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalUserPassword UserPassword + +var knownKeysUserPassword = []string{ + "description", + "type", +} + +var requireKeysUserPassword = []string{ + "type", +} + +// UnmarshalJSON decodes JSON. +func (u *UserPassword) UnmarshalJSON(data []byte) error { + var err error + + mu := marshalUserPassword(*u) + + err = json.Unmarshal(data, &mu) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysUserPassword { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["type"]; exists && string(v) != `"userPassword"` { + return fmt.Errorf(`bad const value for "type" ("userPassword" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysUserPassword { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mu.MapOfAnything == nil { + mu.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mu.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in UserPassword: %v", offendingKeys) + } + + *u = UserPassword(mu) + + return nil +} + +var ( + // constUserPassword is unconditionally added to JSON. + constUserPassword = json.RawMessage(`{"type":"userPassword"}`) +) + +// MarshalJSON encodes JSON. +func (u UserPassword) MarshalJSON() ([]byte, error) { + return marshalUnion(constUserPassword, marshalUserPassword(u), u.MapOfAnything) +} + +// APIKey structure is generated from "#/definitions/apiKey". +type APIKey struct { + In APIKeyIn `json:"in"` // Required. + Description string `json:"description,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalAPIKey APIKey + +var knownKeysAPIKey = []string{ + "in", + "description", + "type", +} + +var requireKeysAPIKey = []string{ + "type", + "in", +} + +// UnmarshalJSON decodes JSON. +func (a *APIKey) UnmarshalJSON(data []byte) error { + var err error + + ma := marshalAPIKey(*a) + + err = json.Unmarshal(data, &ma) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysAPIKey { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["type"]; exists && string(v) != `"apiKey"` { + return fmt.Errorf(`bad const value for "type" ("apiKey" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysAPIKey { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ma.MapOfAnything == nil { + ma.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ma.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in APIKey: %v", offendingKeys) + } + + *a = APIKey(ma) + + return nil +} + +var ( + // constAPIKey is unconditionally added to JSON. + constAPIKey = json.RawMessage(`{"type":"apiKey"}`) +) + +// MarshalJSON encodes JSON. +func (a APIKey) MarshalJSON() ([]byte, error) { + return marshalUnion(constAPIKey, marshalAPIKey(a), a.MapOfAnything) +} + +// X509 structure is generated from "#/definitions/X509". +type X509 struct { + Description string `json:"description,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalX509 X509 + +var knownKeysX509 = []string{ + "description", + "type", +} + +var requireKeysX509 = []string{ + "type", +} + +// UnmarshalJSON decodes JSON. +func (x *X509) UnmarshalJSON(data []byte) error { + var err error + + mx := marshalX509(*x) + + err = json.Unmarshal(data, &mx) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysX509 { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["type"]; exists && string(v) != `"X509"` { + return fmt.Errorf(`bad const value for "type" ("X509" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysX509 { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mx.MapOfAnything == nil { + mx.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mx.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in X509: %v", offendingKeys) + } + + *x = X509(mx) + + return nil +} + +var ( + // constX509 is unconditionally added to JSON. + constX509 = json.RawMessage(`{"type":"X509"}`) +) + +// MarshalJSON encodes JSON. +func (x X509) MarshalJSON() ([]byte, error) { + return marshalUnion(constX509, marshalX509(x), x.MapOfAnything) +} + +// SymmetricEncryption structure is generated from "#/definitions/symmetricEncryption". +type SymmetricEncryption struct { + Description string `json:"description,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalSymmetricEncryption SymmetricEncryption + +var knownKeysSymmetricEncryption = []string{ + "description", + "type", +} + +var requireKeysSymmetricEncryption = []string{ + "type", +} + +// UnmarshalJSON decodes JSON. +func (s *SymmetricEncryption) UnmarshalJSON(data []byte) error { + var err error + + ms := marshalSymmetricEncryption(*s) + + err = json.Unmarshal(data, &ms) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysSymmetricEncryption { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["type"]; exists && string(v) != `"symmetricEncryption"` { + return fmt.Errorf(`bad const value for "type" ("symmetricEncryption" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysSymmetricEncryption { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ms.MapOfAnything == nil { + ms.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ms.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in SymmetricEncryption: %v", offendingKeys) + } + + *s = SymmetricEncryption(ms) + + return nil +} + +var ( + // constSymmetricEncryption is unconditionally added to JSON. + constSymmetricEncryption = json.RawMessage(`{"type":"symmetricEncryption"}`) +) + +// MarshalJSON encodes JSON. +func (s SymmetricEncryption) MarshalJSON() ([]byte, error) { + return marshalUnion(constSymmetricEncryption, marshalSymmetricEncryption(s), s.MapOfAnything) +} + +// AsymmetricEncryption structure is generated from "#/definitions/asymmetricEncryption". +type AsymmetricEncryption struct { + Description string `json:"description,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalAsymmetricEncryption AsymmetricEncryption + +var knownKeysAsymmetricEncryption = []string{ + "description", + "type", +} + +var requireKeysAsymmetricEncryption = []string{ + "type", +} + +// UnmarshalJSON decodes JSON. +func (a *AsymmetricEncryption) UnmarshalJSON(data []byte) error { + var err error + + ma := marshalAsymmetricEncryption(*a) + + err = json.Unmarshal(data, &ma) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysAsymmetricEncryption { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["type"]; exists && string(v) != `"asymmetricEncryption"` { + return fmt.Errorf(`bad const value for "type" ("asymmetricEncryption" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysAsymmetricEncryption { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ma.MapOfAnything == nil { + ma.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ma.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in AsymmetricEncryption: %v", offendingKeys) + } + + *a = AsymmetricEncryption(ma) + + return nil +} + +var ( + // constAsymmetricEncryption is unconditionally added to JSON. + constAsymmetricEncryption = json.RawMessage(`{"type":"asymmetricEncryption"}`) +) + +// MarshalJSON encodes JSON. +func (a AsymmetricEncryption) MarshalJSON() ([]byte, error) { + return marshalUnion(constAsymmetricEncryption, marshalAsymmetricEncryption(a), a.MapOfAnything) +} + +// NonBearerHTTPSecurityScheme structure is generated from "#/definitions/NonBearerHTTPSecurityScheme". +type NonBearerHTTPSecurityScheme struct { + Scheme string `json:"scheme"` // Required. + Description string `json:"description,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalNonBearerHTTPSecurityScheme NonBearerHTTPSecurityScheme + +var knownKeysNonBearerHTTPSecurityScheme = []string{ + "scheme", + "description", + "type", +} + +var requireKeysNonBearerHTTPSecurityScheme = []string{ + "scheme", + "type", +} + +// UnmarshalJSON decodes JSON. +func (n *NonBearerHTTPSecurityScheme) UnmarshalJSON(data []byte) error { + var err error + + var not NonBearerHTTPSecuritySchemeNot + + if json.Unmarshal(data, ¬) == nil { + return errors.New("not constraint failed for NonBearerHTTPSecurityScheme") + } + + mn := marshalNonBearerHTTPSecurityScheme(*n) + + err = json.Unmarshal(data, &mn) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysNonBearerHTTPSecurityScheme { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["type"]; exists && string(v) != `"http"` { + return fmt.Errorf(`bad const value for "type" ("http" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysNonBearerHTTPSecurityScheme { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mn.MapOfAnything == nil { + mn.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mn.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in NonBearerHTTPSecurityScheme: %v", offendingKeys) + } + + *n = NonBearerHTTPSecurityScheme(mn) + + return nil +} + +var ( + // constNonBearerHTTPSecurityScheme is unconditionally added to JSON. + constNonBearerHTTPSecurityScheme = json.RawMessage(`{"type":"http"}`) +) + +// MarshalJSON encodes JSON. +func (n NonBearerHTTPSecurityScheme) MarshalJSON() ([]byte, error) { + return marshalUnion(constNonBearerHTTPSecurityScheme, marshalNonBearerHTTPSecurityScheme(n), n.MapOfAnything) +} + +// NonBearerHTTPSecuritySchemeNot structure is generated from "#/definitions/NonBearerHTTPSecurityScheme->not". +type NonBearerHTTPSecuritySchemeNot struct { + AdditionalProperties map[string]interface{} `json:"-"` // All unmatched properties. +} + +// UnmarshalJSON decodes JSON. +func (n *NonBearerHTTPSecuritySchemeNot) UnmarshalJSON(data []byte) error { + var err error + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + if v, exists := rawMap["scheme"]; exists && string(v) != `"bearer"` { + return fmt.Errorf(`bad const value for "scheme" ("bearer" expected, %s received)`, v) + } + + delete(rawMap, "scheme") + + for key, rawValue := range rawMap { + if n.AdditionalProperties == nil { + n.AdditionalProperties = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + n.AdditionalProperties[key] = val + } + + return nil +} + +var ( + // constNonBearerHTTPSecuritySchemeNot is unconditionally added to JSON. + constNonBearerHTTPSecuritySchemeNot = json.RawMessage(`{"scheme":"bearer"}`) +) + +// MarshalJSON encodes JSON. +func (n NonBearerHTTPSecuritySchemeNot) MarshalJSON() ([]byte, error) { + return marshalUnion(constNonBearerHTTPSecuritySchemeNot, n.AdditionalProperties) +} + +// BearerHTTPSecurityScheme structure is generated from "#/definitions/BearerHTTPSecurityScheme". +type BearerHTTPSecurityScheme struct { + BearerFormat string `json:"bearerFormat,omitempty"` + Description string `json:"description,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalBearerHTTPSecurityScheme BearerHTTPSecurityScheme + +var knownKeysBearerHTTPSecurityScheme = []string{ + "bearerFormat", + "description", + "scheme", + "type", +} + +var requireKeysBearerHTTPSecurityScheme = []string{ + "type", + "scheme", +} + +// UnmarshalJSON decodes JSON. +func (b *BearerHTTPSecurityScheme) UnmarshalJSON(data []byte) error { + var err error + + mb := marshalBearerHTTPSecurityScheme(*b) + + err = json.Unmarshal(data, &mb) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysBearerHTTPSecurityScheme { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["scheme"]; exists && string(v) != `"bearer"` { + return fmt.Errorf(`bad const value for "scheme" ("bearer" expected, %s received)`, v) + } + + delete(rawMap, "scheme") + + if v, exists := rawMap["type"]; exists && string(v) != `"http"` { + return fmt.Errorf(`bad const value for "type" ("http" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysBearerHTTPSecurityScheme { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mb.MapOfAnything == nil { + mb.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mb.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in BearerHTTPSecurityScheme: %v", offendingKeys) + } + + *b = BearerHTTPSecurityScheme(mb) + + return nil +} + +var ( + // constBearerHTTPSecurityScheme is unconditionally added to JSON. + constBearerHTTPSecurityScheme = json.RawMessage(`{"scheme":"bearer","type":"http"}`) +) + +// MarshalJSON encodes JSON. +func (b BearerHTTPSecurityScheme) MarshalJSON() ([]byte, error) { + return marshalUnion(constBearerHTTPSecurityScheme, marshalBearerHTTPSecurityScheme(b), b.MapOfAnything) +} + +// APIKeyHTTPSecurityScheme structure is generated from "#/definitions/APIKeyHTTPSecurityScheme". +type APIKeyHTTPSecurityScheme struct { + Name string `json:"name"` // Required. + In APIKeyHTTPSecuritySchemeIn `json:"in"` // Required. + Description string `json:"description,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalAPIKeyHTTPSecurityScheme APIKeyHTTPSecurityScheme + +var knownKeysAPIKeyHTTPSecurityScheme = []string{ + "name", + "in", + "description", + "type", +} + +var requireKeysAPIKeyHTTPSecurityScheme = []string{ + "type", + "name", + "in", +} + +// UnmarshalJSON decodes JSON. +func (a *APIKeyHTTPSecurityScheme) UnmarshalJSON(data []byte) error { + var err error + + ma := marshalAPIKeyHTTPSecurityScheme(*a) + + err = json.Unmarshal(data, &ma) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysAPIKeyHTTPSecurityScheme { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["type"]; exists && string(v) != `"httpApiKey"` { + return fmt.Errorf(`bad const value for "type" ("httpApiKey" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysAPIKeyHTTPSecurityScheme { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ma.MapOfAnything == nil { + ma.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ma.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in APIKeyHTTPSecurityScheme: %v", offendingKeys) + } + + *a = APIKeyHTTPSecurityScheme(ma) + + return nil +} + +var ( + // constAPIKeyHTTPSecurityScheme is unconditionally added to JSON. + constAPIKeyHTTPSecurityScheme = json.RawMessage(`{"type":"httpApiKey"}`) +) + +// MarshalJSON encodes JSON. +func (a APIKeyHTTPSecurityScheme) MarshalJSON() ([]byte, error) { + return marshalUnion(constAPIKeyHTTPSecurityScheme, marshalAPIKeyHTTPSecurityScheme(a), a.MapOfAnything) +} + +// HTTPSecurityScheme structure is generated from "#/definitions/HTTPSecurityScheme". +type HTTPSecurityScheme struct { + NonBearerHTTPSecurityScheme *NonBearerHTTPSecurityScheme `json:"-"` + BearerHTTPSecurityScheme *BearerHTTPSecurityScheme `json:"-"` + APIKeyHTTPSecurityScheme *APIKeyHTTPSecurityScheme `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (h *HTTPSecurityScheme) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 3) + oneOfValid := 0 + + err = json.Unmarshal(data, &h.NonBearerHTTPSecurityScheme) + if err != nil { + oneOfErrors["NonBearerHTTPSecurityScheme"] = err + h.NonBearerHTTPSecurityScheme = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &h.BearerHTTPSecurityScheme) + if err != nil { + oneOfErrors["BearerHTTPSecurityScheme"] = err + h.BearerHTTPSecurityScheme = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &h.APIKeyHTTPSecurityScheme) + if err != nil { + oneOfErrors["APIKeyHTTPSecurityScheme"] = err + h.APIKeyHTTPSecurityScheme = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for HTTPSecurityScheme with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (h HTTPSecurityScheme) MarshalJSON() ([]byte, error) { + return marshalUnion(h.NonBearerHTTPSecurityScheme, h.BearerHTTPSecurityScheme, h.APIKeyHTTPSecurityScheme) +} + +// Oauth2Flows structure is generated from "#/definitions/oauth2Flows". +type Oauth2Flows struct { + Description string `json:"description,omitempty"` + Flows Oauth2FlowsFlows `json:"flows"` // Required. + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. + AdditionalProperties map[string]interface{} `json:"-"` // All unmatched properties. +} + +type marshalOauth2Flows Oauth2Flows + +var knownKeysOauth2Flows = []string{ + "description", + "flows", + "type", +} + +var requireKeysOauth2Flows = []string{ + "type", + "flows", +} + +// UnmarshalJSON decodes JSON. +func (o *Oauth2Flows) UnmarshalJSON(data []byte) error { + var err error + + mo := marshalOauth2Flows(*o) + + err = json.Unmarshal(data, &mo) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysOauth2Flows { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["type"]; exists && string(v) != `"oauth2"` { + return fmt.Errorf(`bad const value for "type" ("oauth2" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysOauth2Flows { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mo.MapOfAnything == nil { + mo.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mo.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + for key, rawValue := range rawMap { + if mo.AdditionalProperties == nil { + mo.AdditionalProperties = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mo.AdditionalProperties[key] = val + } + + *o = Oauth2Flows(mo) + + return nil +} + +var ( + // constOauth2Flows is unconditionally added to JSON. + constOauth2Flows = json.RawMessage(`{"type":"oauth2"}`) +) + +// MarshalJSON encodes JSON. +func (o Oauth2Flows) MarshalJSON() ([]byte, error) { + return marshalUnion(constOauth2Flows, marshalOauth2Flows(o), o.MapOfAnything, o.AdditionalProperties) +} + +// Oauth2FlowsFlows structure is generated from "#/definitions/oauth2Flows->flows". +type Oauth2FlowsFlows struct { + Implicit *Oauth2Flow `json:"implicit,omitempty"` + Password *Oauth2Flow `json:"password,omitempty"` + ClientCredentials *Oauth2Flow `json:"clientCredentials,omitempty"` + AuthorizationCode *Oauth2Flow `json:"authorizationCode,omitempty"` +} + +type marshalOauth2FlowsFlows Oauth2FlowsFlows + +var knownKeysOauth2FlowsFlows = []string{ + "implicit", + "password", + "clientCredentials", + "authorizationCode", +} + +// UnmarshalJSON decodes JSON. +func (o *Oauth2FlowsFlows) UnmarshalJSON(data []byte) error { + var err error + + mo := marshalOauth2FlowsFlows(*o) + + err = json.Unmarshal(data, &mo) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range knownKeysOauth2FlowsFlows { + delete(rawMap, key) + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in Oauth2FlowsFlows: %v", offendingKeys) + } + + *o = Oauth2FlowsFlows(mo) + + return nil +} + + +// Oauth2Flow structure is generated from "#/definitions/oauth2Flow". +type Oauth2Flow struct { + AuthorizationURL string `json:"authorizationUrl,omitempty"` // Format: uri. + TokenURL string `json:"tokenUrl,omitempty"` // Format: uri. + RefreshURL string `json:"refreshUrl,omitempty"` // Format: uri. + Scopes map[string]string `json:"scopes,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalOauth2Flow Oauth2Flow + +var knownKeysOauth2Flow = []string{ + "authorizationUrl", + "tokenUrl", + "refreshUrl", + "scopes", +} + +// UnmarshalJSON decodes JSON. +func (o *Oauth2Flow) UnmarshalJSON(data []byte) error { + var err error + + mo := marshalOauth2Flow(*o) + + err = json.Unmarshal(data, &mo) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range knownKeysOauth2Flow { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mo.MapOfAnything == nil { + mo.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mo.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in Oauth2Flow: %v", offendingKeys) + } + + *o = Oauth2Flow(mo) + + return nil +} + +// MarshalJSON encodes JSON. +func (o Oauth2Flow) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalOauth2Flow(o), o.MapOfAnything) +} + +// OpenIDConnect structure is generated from "#/definitions/openIdConnect". +type OpenIDConnect struct { + Description string `json:"description,omitempty"` + // Format: uri. + // Required. + URL string `json:"openIdConnectUrl"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalOpenIDConnect OpenIDConnect + +var knownKeysOpenIDConnect = []string{ + "description", + "openIdConnectUrl", + "type", +} + +var requireKeysOpenIDConnect = []string{ + "type", + "openIdConnectUrl", +} + +// UnmarshalJSON decodes JSON. +func (o *OpenIDConnect) UnmarshalJSON(data []byte) error { + var err error + + mo := marshalOpenIDConnect(*o) + + err = json.Unmarshal(data, &mo) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysOpenIDConnect { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["type"]; exists && string(v) != `"openIdConnect"` { + return fmt.Errorf(`bad const value for "type" ("openIdConnect" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysOpenIDConnect { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if mo.MapOfAnything == nil { + mo.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + mo.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in OpenIDConnect: %v", offendingKeys) + } + + *o = OpenIDConnect(mo) + + return nil +} + +var ( + // constOpenIDConnect is unconditionally added to JSON. + constOpenIDConnect = json.RawMessage(`{"type":"openIdConnect"}`) +) + +// MarshalJSON encodes JSON. +func (o OpenIDConnect) MarshalJSON() ([]byte, error) { + return marshalUnion(constOpenIDConnect, marshalOpenIDConnect(o), o.MapOfAnything) +} + +// SaslPlainSecurityScheme structure is generated from "#/definitions/SaslPlainSecurityScheme". +type SaslPlainSecurityScheme struct { + Description string `json:"description,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalSaslPlainSecurityScheme SaslPlainSecurityScheme + +var knownKeysSaslPlainSecurityScheme = []string{ + "description", + "type", +} + +var requireKeysSaslPlainSecurityScheme = []string{ + "type", +} + +// UnmarshalJSON decodes JSON. +func (s *SaslPlainSecurityScheme) UnmarshalJSON(data []byte) error { + var err error + + ms := marshalSaslPlainSecurityScheme(*s) + + err = json.Unmarshal(data, &ms) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysSaslPlainSecurityScheme { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["type"]; exists && string(v) != `"plain"` { + return fmt.Errorf(`bad const value for "type" ("plain" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysSaslPlainSecurityScheme { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ms.MapOfAnything == nil { + ms.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ms.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in SaslPlainSecurityScheme: %v", offendingKeys) + } + + *s = SaslPlainSecurityScheme(ms) + + return nil +} + +var ( + // constSaslPlainSecurityScheme is unconditionally added to JSON. + constSaslPlainSecurityScheme = json.RawMessage(`{"type":"plain"}`) +) + +// MarshalJSON encodes JSON. +func (s SaslPlainSecurityScheme) MarshalJSON() ([]byte, error) { + return marshalUnion(constSaslPlainSecurityScheme, marshalSaslPlainSecurityScheme(s), s.MapOfAnything) +} + +// SaslScramSecurityScheme structure is generated from "#/definitions/SaslScramSecurityScheme". +type SaslScramSecurityScheme struct { + Type SaslScramSecuritySchemeType `json:"type"` // Required. + Description string `json:"description,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalSaslScramSecurityScheme SaslScramSecurityScheme + +var knownKeysSaslScramSecurityScheme = []string{ + "type", + "description", +} + +var requireKeysSaslScramSecurityScheme = []string{ + "type", +} + +// UnmarshalJSON decodes JSON. +func (s *SaslScramSecurityScheme) UnmarshalJSON(data []byte) error { + var err error + + ms := marshalSaslScramSecurityScheme(*s) + + err = json.Unmarshal(data, &ms) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysSaslScramSecurityScheme { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + for _, key := range knownKeysSaslScramSecurityScheme { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ms.MapOfAnything == nil { + ms.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ms.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in SaslScramSecurityScheme: %v", offendingKeys) + } + + *s = SaslScramSecurityScheme(ms) + + return nil +} + +// MarshalJSON encodes JSON. +func (s SaslScramSecurityScheme) MarshalJSON() ([]byte, error) { + return marshalUnion(marshalSaslScramSecurityScheme(s), s.MapOfAnything) +} + +// SaslGssapiSecurityScheme structure is generated from "#/definitions/SaslGssapiSecurityScheme". +type SaslGssapiSecurityScheme struct { + Description string `json:"description,omitempty"` + MapOfAnything map[string]interface{} `json:"-"` // Key must match pattern: `^x-[\w\d\.\-\_]+$`. +} + +type marshalSaslGssapiSecurityScheme SaslGssapiSecurityScheme + +var knownKeysSaslGssapiSecurityScheme = []string{ + "description", + "type", +} + +var requireKeysSaslGssapiSecurityScheme = []string{ + "type", +} + +// UnmarshalJSON decodes JSON. +func (s *SaslGssapiSecurityScheme) UnmarshalJSON(data []byte) error { + var err error + + ms := marshalSaslGssapiSecurityScheme(*s) + + err = json.Unmarshal(data, &ms) + if err != nil { + return err + } + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for _, key := range requireKeysSaslGssapiSecurityScheme { + if _, found := rawMap[key]; !found { + return errors.New("required key missing: " + key) + } + } + + if v, exists := rawMap["type"]; exists && string(v) != `"gssapi"` { + return fmt.Errorf(`bad const value for "type" ("gssapi" expected, %s received)`, v) + } + + delete(rawMap, "type") + + for _, key := range knownKeysSaslGssapiSecurityScheme { + delete(rawMap, key) + } + + for key, rawValue := range rawMap { + matched := false + + if regexXWD.MatchString(key) { + matched = true + + if ms.MapOfAnything == nil { + ms.MapOfAnything = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + ms.MapOfAnything[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + if len(rawMap) != 0 { + offendingKeys := make([]string, 0, len(rawMap)) + + for key := range rawMap { + offendingKeys = append(offendingKeys, key) + } + + return fmt.Errorf("additional properties not allowed in SaslGssapiSecurityScheme: %v", offendingKeys) + } + + *s = SaslGssapiSecurityScheme(ms) + + return nil +} + +var ( + // constSaslGssapiSecurityScheme is unconditionally added to JSON. + constSaslGssapiSecurityScheme = json.RawMessage(`{"type":"gssapi"}`) +) + +// MarshalJSON encodes JSON. +func (s SaslGssapiSecurityScheme) MarshalJSON() ([]byte, error) { + return marshalUnion(constSaslGssapiSecurityScheme, marshalSaslGssapiSecurityScheme(s), s.MapOfAnything) +} + +// SaslSecurityScheme structure is generated from "#/definitions/SaslSecurityScheme". +type SaslSecurityScheme struct { + SaslPlainSecurityScheme *SaslPlainSecurityScheme `json:"-"` + SaslScramSecurityScheme *SaslScramSecurityScheme `json:"-"` + SaslGssapiSecurityScheme *SaslGssapiSecurityScheme `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (s *SaslSecurityScheme) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 3) + oneOfValid := 0 + + err = json.Unmarshal(data, &s.SaslPlainSecurityScheme) + if err != nil { + oneOfErrors["SaslPlainSecurityScheme"] = err + s.SaslPlainSecurityScheme = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &s.SaslScramSecurityScheme) + if err != nil { + oneOfErrors["SaslScramSecurityScheme"] = err + s.SaslScramSecurityScheme = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &s.SaslGssapiSecurityScheme) + if err != nil { + oneOfErrors["SaslGssapiSecurityScheme"] = err + s.SaslGssapiSecurityScheme = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for SaslSecurityScheme with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (s SaslSecurityScheme) MarshalJSON() ([]byte, error) { + return marshalUnion(s.SaslPlainSecurityScheme, s.SaslScramSecurityScheme, s.SaslGssapiSecurityScheme) +} + +// SecurityScheme structure is generated from "#/definitions/SecurityScheme". +type SecurityScheme struct { + UserPassword *UserPassword `json:"-"` + APIKey *APIKey `json:"-"` + X509 *X509 `json:"-"` + SymmetricEncryption *SymmetricEncryption `json:"-"` + AsymmetricEncryption *AsymmetricEncryption `json:"-"` + HTTPSecurityScheme *HTTPSecurityScheme `json:"-"` + Oauth2Flows *Oauth2Flows `json:"-"` + OpenIDConnect *OpenIDConnect `json:"-"` + SaslSecurityScheme *SaslSecurityScheme `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (s *SecurityScheme) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 9) + oneOfValid := 0 + + err = json.Unmarshal(data, &s.UserPassword) + if err != nil { + oneOfErrors["UserPassword"] = err + s.UserPassword = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &s.APIKey) + if err != nil { + oneOfErrors["APIKey"] = err + s.APIKey = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &s.X509) + if err != nil { + oneOfErrors["X509"] = err + s.X509 = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &s.SymmetricEncryption) + if err != nil { + oneOfErrors["SymmetricEncryption"] = err + s.SymmetricEncryption = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &s.AsymmetricEncryption) + if err != nil { + oneOfErrors["AsymmetricEncryption"] = err + s.AsymmetricEncryption = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &s.HTTPSecurityScheme) + if err != nil { + oneOfErrors["HTTPSecurityScheme"] = err + s.HTTPSecurityScheme = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &s.Oauth2Flows) + if err != nil { + oneOfErrors["Oauth2Flows"] = err + s.Oauth2Flows = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &s.OpenIDConnect) + if err != nil { + oneOfErrors["OpenIDConnect"] = err + s.OpenIDConnect = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &s.SaslSecurityScheme) + if err != nil { + oneOfErrors["SaslSecurityScheme"] = err + s.SaslSecurityScheme = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for SecurityScheme with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (s SecurityScheme) MarshalJSON() ([]byte, error) { + return marshalUnion(s.UserPassword, s.APIKey, s.X509, s.SymmetricEncryption, s.AsymmetricEncryption, s.HTTPSecurityScheme, s.Oauth2Flows, s.OpenIDConnect, s.SaslSecurityScheme) +} + +// ComponentsSecuritySchemesWD structure is generated from "#/definitions/components->securitySchemes->^[\w\d\.\-_]+$". +type ComponentsSecuritySchemesWD struct { + Reference *Reference `json:"-"` + SecurityScheme *SecurityScheme `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (c *ComponentsSecuritySchemesWD) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 2) + oneOfValid := 0 + + err = json.Unmarshal(data, &c.Reference) + if err != nil { + oneOfErrors["Reference"] = err + c.Reference = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &c.SecurityScheme) + if err != nil { + oneOfErrors["SecurityScheme"] = err + c.SecurityScheme = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for ComponentsSecuritySchemesWD with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (c ComponentsSecuritySchemesWD) MarshalJSON() ([]byte, error) { + return marshalUnion(c.Reference, c.SecurityScheme) +} + +// ComponentsSecuritySchemes structure is generated from "#/definitions/components->securitySchemes". +type ComponentsSecuritySchemes struct { + MapOfComponentsSecuritySchemesWDValues map[string]ComponentsSecuritySchemesWD `json:"-"` // Key must match pattern: `^[\w\d\.\-_]+$`. + AdditionalProperties map[string]interface{} `json:"-"` // All unmatched properties. +} + +// UnmarshalJSON decodes JSON. +func (c *ComponentsSecuritySchemes) UnmarshalJSON(data []byte) error { + var err error + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for key, rawValue := range rawMap { + matched := false + + if regexWD.MatchString(key) { + matched = true + + if c.MapOfComponentsSecuritySchemesWDValues == nil { + c.MapOfComponentsSecuritySchemesWDValues = make(map[string]ComponentsSecuritySchemesWD, 1) + } + + var val ComponentsSecuritySchemesWD + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + c.MapOfComponentsSecuritySchemesWDValues[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + for key, rawValue := range rawMap { + if c.AdditionalProperties == nil { + c.AdditionalProperties = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + c.AdditionalProperties[key] = val + } + + return nil +} + +// MarshalJSON encodes JSON. +func (c ComponentsSecuritySchemes) MarshalJSON() ([]byte, error) { + return marshalUnion(c.MapOfComponentsSecuritySchemesWDValues, c.AdditionalProperties) +} + +// ComponentsCorrelationIdsWD structure is generated from "#/definitions/components->correlationIds->^[\w\d\.\-_]+$". +type ComponentsCorrelationIdsWD struct { + Reference *Reference `json:"-"` + CorrelationID *CorrelationID `json:"-"` +} + +// UnmarshalJSON decodes JSON. +func (c *ComponentsCorrelationIdsWD) UnmarshalJSON(data []byte) error { + var err error + + oneOfErrors := make(map[string]error, 2) + oneOfValid := 0 + + err = json.Unmarshal(data, &c.Reference) + if err != nil { + oneOfErrors["Reference"] = err + c.Reference = nil + } else { + oneOfValid++ + } + + err = json.Unmarshal(data, &c.CorrelationID) + if err != nil { + oneOfErrors["CorrelationID"] = err + c.CorrelationID = nil + } else { + oneOfValid++ + } + + if oneOfValid != 1 { + return fmt.Errorf("oneOf constraint failed for ComponentsCorrelationIdsWD with %d valid results: %v", oneOfValid, oneOfErrors) + } + + return nil +} + +// MarshalJSON encodes JSON. +func (c ComponentsCorrelationIdsWD) MarshalJSON() ([]byte, error) { + return marshalUnion(c.Reference, c.CorrelationID) +} + +// ComponentsCorrelationIds structure is generated from "#/definitions/components->correlationIds". +type ComponentsCorrelationIds struct { + MapOfComponentsCorrelationIdsWDValues map[string]ComponentsCorrelationIdsWD `json:"-"` // Key must match pattern: `^[\w\d\.\-_]+$`. + AdditionalProperties map[string]interface{} `json:"-"` // All unmatched properties. +} + +// UnmarshalJSON decodes JSON. +func (c *ComponentsCorrelationIds) UnmarshalJSON(data []byte) error { + var err error + + var rawMap map[string]json.RawMessage + + err = json.Unmarshal(data, &rawMap) + if err != nil { + rawMap = nil + } + + for key, rawValue := range rawMap { + matched := false + + if regexWD.MatchString(key) { + matched = true + + if c.MapOfComponentsCorrelationIdsWDValues == nil { + c.MapOfComponentsCorrelationIdsWDValues = make(map[string]ComponentsCorrelationIdsWD, 1) + } + + var val ComponentsCorrelationIdsWD + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + c.MapOfComponentsCorrelationIdsWDValues[key] = val + } + + if matched { + delete(rawMap, key) + } + } + + for key, rawValue := range rawMap { + if c.AdditionalProperties == nil { + c.AdditionalProperties = make(map[string]interface{}, 1) + } + + var val interface{} + + err = json.Unmarshal(rawValue, &val) + if err != nil { + return err + } + + c.AdditionalProperties[key] = val + } + + return nil +} + +// MarshalJSON encodes JSON. +func (c ComponentsCorrelationIds) MarshalJSON() ([]byte, error) { + return marshalUnion(c.MapOfComponentsCorrelationIdsWDValues, c.AdditionalProperties) +} + +// JSONSchemaTypeAnyOf0 is an enum type. +type JSONSchemaTypeAnyOf0 string + +// JSONSchemaTypeAnyOf0 values enumeration. +const ( + JSONSchemaTypeAnyOf0Array = JSONSchemaTypeAnyOf0("array") + JSONSchemaTypeAnyOf0Boolean = JSONSchemaTypeAnyOf0("boolean") + JSONSchemaTypeAnyOf0Integer = JSONSchemaTypeAnyOf0("integer") + JSONSchemaTypeAnyOf0Null = JSONSchemaTypeAnyOf0("null") + JSONSchemaTypeAnyOf0Number = JSONSchemaTypeAnyOf0("number") + JSONSchemaTypeAnyOf0Object = JSONSchemaTypeAnyOf0("object") + JSONSchemaTypeAnyOf0String = JSONSchemaTypeAnyOf0("string") +) + +// MarshalJSON encodes JSON. +func (i JSONSchemaTypeAnyOf0) MarshalJSON() ([]byte, error) { + switch i { + case JSONSchemaTypeAnyOf0Array: + case JSONSchemaTypeAnyOf0Boolean: + case JSONSchemaTypeAnyOf0Integer: + case JSONSchemaTypeAnyOf0Null: + case JSONSchemaTypeAnyOf0Number: + case JSONSchemaTypeAnyOf0Object: + case JSONSchemaTypeAnyOf0String: + + default: + return nil, fmt.Errorf("unexpected JSONSchemaTypeAnyOf0 value: %v", i) + } + + return json.Marshal(string(i)) +} + +// UnmarshalJSON decodes JSON. +func (i *JSONSchemaTypeAnyOf0) UnmarshalJSON(data []byte) error { + var ii string + + err := json.Unmarshal(data, &ii) + if err != nil { + return err + } + + v := JSONSchemaTypeAnyOf0(ii) + + switch v { + case JSONSchemaTypeAnyOf0Array: + case JSONSchemaTypeAnyOf0Boolean: + case JSONSchemaTypeAnyOf0Integer: + case JSONSchemaTypeAnyOf0Null: + case JSONSchemaTypeAnyOf0Number: + case JSONSchemaTypeAnyOf0Object: + case JSONSchemaTypeAnyOf0String: + + default: + return fmt.Errorf("unexpected JSONSchemaTypeAnyOf0 value: %v", v) + } + + *i = v + + return nil +} + +// JSONSchemaTypeAnyOf1Items is an enum type. +type JSONSchemaTypeAnyOf1Items string + +// JSONSchemaTypeAnyOf1Items values enumeration. +const ( + JSONSchemaTypeAnyOf1ItemsArray = JSONSchemaTypeAnyOf1Items("array") + JSONSchemaTypeAnyOf1ItemsBoolean = JSONSchemaTypeAnyOf1Items("boolean") + JSONSchemaTypeAnyOf1ItemsInteger = JSONSchemaTypeAnyOf1Items("integer") + JSONSchemaTypeAnyOf1ItemsNull = JSONSchemaTypeAnyOf1Items("null") + JSONSchemaTypeAnyOf1ItemsNumber = JSONSchemaTypeAnyOf1Items("number") + JSONSchemaTypeAnyOf1ItemsObject = JSONSchemaTypeAnyOf1Items("object") + JSONSchemaTypeAnyOf1ItemsString = JSONSchemaTypeAnyOf1Items("string") +) + +// MarshalJSON encodes JSON. +func (i JSONSchemaTypeAnyOf1Items) MarshalJSON() ([]byte, error) { + switch i { + case JSONSchemaTypeAnyOf1ItemsArray: + case JSONSchemaTypeAnyOf1ItemsBoolean: + case JSONSchemaTypeAnyOf1ItemsInteger: + case JSONSchemaTypeAnyOf1ItemsNull: + case JSONSchemaTypeAnyOf1ItemsNumber: + case JSONSchemaTypeAnyOf1ItemsObject: + case JSONSchemaTypeAnyOf1ItemsString: + + default: + return nil, fmt.Errorf("unexpected JSONSchemaTypeAnyOf1Items value: %v", i) + } + + return json.Marshal(string(i)) +} + +// UnmarshalJSON decodes JSON. +func (i *JSONSchemaTypeAnyOf1Items) UnmarshalJSON(data []byte) error { + var ii string + + err := json.Unmarshal(data, &ii) + if err != nil { + return err + } + + v := JSONSchemaTypeAnyOf1Items(ii) + + switch v { + case JSONSchemaTypeAnyOf1ItemsArray: + case JSONSchemaTypeAnyOf1ItemsBoolean: + case JSONSchemaTypeAnyOf1ItemsInteger: + case JSONSchemaTypeAnyOf1ItemsNull: + case JSONSchemaTypeAnyOf1ItemsNumber: + case JSONSchemaTypeAnyOf1ItemsObject: + case JSONSchemaTypeAnyOf1ItemsString: + + default: + return fmt.Errorf("unexpected JSONSchemaTypeAnyOf1Items value: %v", v) + } + + *i = v + + return nil +} + +// APIKeyIn is an enum type. +type APIKeyIn string + +// APIKeyIn values enumeration. +const ( + APIKeyInUser = APIKeyIn("user") + APIKeyInPassword = APIKeyIn("password") +) + +// MarshalJSON encodes JSON. +func (i APIKeyIn) MarshalJSON() ([]byte, error) { + switch i { + case APIKeyInUser: + case APIKeyInPassword: + + default: + return nil, fmt.Errorf("unexpected APIKeyIn value: %v", i) + } + + return json.Marshal(string(i)) +} + +// UnmarshalJSON decodes JSON. +func (i *APIKeyIn) UnmarshalJSON(data []byte) error { + var ii string + + err := json.Unmarshal(data, &ii) + if err != nil { + return err + } + + v := APIKeyIn(ii) + + switch v { + case APIKeyInUser: + case APIKeyInPassword: + + default: + return fmt.Errorf("unexpected APIKeyIn value: %v", v) + } + + *i = v + + return nil +} + +// APIKeyHTTPSecuritySchemeIn is an enum type. +type APIKeyHTTPSecuritySchemeIn string + +// APIKeyHTTPSecuritySchemeIn values enumeration. +const ( + APIKeyHTTPSecuritySchemeInHeader = APIKeyHTTPSecuritySchemeIn("header") + APIKeyHTTPSecuritySchemeInQuery = APIKeyHTTPSecuritySchemeIn("query") + APIKeyHTTPSecuritySchemeInCookie = APIKeyHTTPSecuritySchemeIn("cookie") +) + +// MarshalJSON encodes JSON. +func (i APIKeyHTTPSecuritySchemeIn) MarshalJSON() ([]byte, error) { + switch i { + case APIKeyHTTPSecuritySchemeInHeader: + case APIKeyHTTPSecuritySchemeInQuery: + case APIKeyHTTPSecuritySchemeInCookie: + + default: + return nil, fmt.Errorf("unexpected APIKeyHTTPSecuritySchemeIn value: %v", i) + } + + return json.Marshal(string(i)) +} + +// UnmarshalJSON decodes JSON. +func (i *APIKeyHTTPSecuritySchemeIn) UnmarshalJSON(data []byte) error { + var ii string + + err := json.Unmarshal(data, &ii) + if err != nil { + return err + } + + v := APIKeyHTTPSecuritySchemeIn(ii) + + switch v { + case APIKeyHTTPSecuritySchemeInHeader: + case APIKeyHTTPSecuritySchemeInQuery: + case APIKeyHTTPSecuritySchemeInCookie: + + default: + return fmt.Errorf("unexpected APIKeyHTTPSecuritySchemeIn value: %v", v) + } + + *i = v + + return nil +} + +// SaslScramSecuritySchemeType is an enum type. +type SaslScramSecuritySchemeType string + +// SaslScramSecuritySchemeType values enumeration. +const ( + SaslScramSecuritySchemeTypeScramSha256 = SaslScramSecuritySchemeType("scramSha256") + SaslScramSecuritySchemeTypeScramSha512 = SaslScramSecuritySchemeType("scramSha512") +) + +// MarshalJSON encodes JSON. +func (i SaslScramSecuritySchemeType) MarshalJSON() ([]byte, error) { + switch i { + case SaslScramSecuritySchemeTypeScramSha256: + case SaslScramSecuritySchemeTypeScramSha512: + + default: + return nil, fmt.Errorf("unexpected SaslScramSecuritySchemeType value: %v", i) + } + + return json.Marshal(string(i)) +} + +// UnmarshalJSON decodes JSON. +func (i *SaslScramSecuritySchemeType) UnmarshalJSON(data []byte) error { + var ii string + + err := json.Unmarshal(data, &ii) + if err != nil { + return err + } + + v := SaslScramSecuritySchemeType(ii) + + switch v { + case SaslScramSecuritySchemeTypeScramSha256: + case SaslScramSecuritySchemeTypeScramSha512: + + default: + return fmt.Errorf("unexpected SaslScramSecuritySchemeType value: %v", v) + } + + *i = v + + return nil +} + +func marshalUnion(maps ...interface{}) ([]byte, error) { + result := []byte("{") + isObject := true + + for _, m := range maps { + j, err := json.Marshal(m) + if err != nil { + return nil, err + } + + if string(j) == "{}" { + continue + } + + if string(j) == "null" { + continue + } + + if j[0] != '{' { + if len(result) == 1 && (isObject || bytes.Equal(result, j)) { + result = j + isObject = false + + continue + } + + return nil, errors.New("failed to union map: object expected, " + string(j) + " received") + } + + if !isObject { + return nil, errors.New("failed to union " + string(result) + " and " + string(j)) + } + + if len(result) > 1 { + result[len(result)-1] = ',' + } + + result = append(result, j[1:]...) + } + + // Close empty result. + if isObject && len(result) == 1 { + result = append(result, '}') + } + + return result, nil +} +// Regular expressions for pattern properties. +var ( + regexXWD = regexp.MustCompile(`^x-[\w\d\.\-\_]+$`) + regexWD = regexp.MustCompile(`^[\w\d\.\-_]+$`) +) diff --git a/tests/src/PHPUnit/JsonSchema/AsyncApi2Test.php b/tests/src/PHPUnit/JsonSchema/AsyncApi2Test.php index c0b3726..0eb1f1c 100644 --- a/tests/src/PHPUnit/JsonSchema/AsyncApi2Test.php +++ b/tests/src/PHPUnit/JsonSchema/AsyncApi2Test.php @@ -46,4 +46,40 @@ public function testGen() $out = implode("\n", $out); $this->assertSame('', $out, "Generated files changed"); } + + public function testGen21() + { + chdir(__DIR__ . '/../../../resources/'); + $schemaData = json_decode(file_get_contents(__DIR__ . '/../../../resources/asyncapi-2.1.0.json')); + $schema = Schema::import($schemaData); + + + $builder = new GoBuilder(); + $builder->options->hideConstProperties = true; + $builder->options->trimParentFromPropertyNames = true; + $builder->structCreatedHook = new StructHookCallback(function (StructDef $structDef, $path, $schema) use ($builder) { + if ('#' === $path) { + $structDef->setName('AsyncAPI'); + } elseif (0 === strpos($path, '#/definitions/')) { + $name = $builder->codeBuilder->exportableName(substr($path, strlen('#/definitions/'))); + $structDef->setName($name); + } + }); + $builder->getType($schema); + + $goFile = new GoFile('entities'); + $goFile->fileComment = ''; + foreach ($builder->getGeneratedStructs() as $generatedStruct) { + $goFile->getCode()->addSnippet($generatedStruct->structDef); + } + $goFile->getCode()->addSnippet($builder->getCode()); + + + $filePath = __DIR__ . '/../../../resources/go/asyncapi21/entities.go'; + file_put_contents($filePath,$goFile->render()); + + exec('git diff ' . $filePath, $out); + $out = implode("\n", $out); + $this->assertSame('', $out, "Generated files changed"); + } } \ No newline at end of file