From ec2904d9d57bc0ef2f29372d9a19f1ae72cdabfe Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Tue, 10 Sep 2019 17:17:58 +0200 Subject: [PATCH] Use references in *Of path when available --- src/JsonSchema/SchemaBuilder.php | 15 +- tests/resources/openapi3-schema.json | 1654 +++++++++++++++++ tests/src/PHPUnit/OpenAPI3/GenTest.php | 81 + .../src/Tmp/OpenAPI3/APIKeySecurityScheme.php | 155 ++ .../OpenAPI3/AuthorizationCodeOAuthFlow.php | 142 ++ .../Tmp/OpenAPI3/ClientCredentialsFlow.php | 124 ++ tests/src/Tmp/OpenAPI3/Components.php | 333 ++++ tests/src/Tmp/OpenAPI3/Contact.php | 120 ++ tests/src/Tmp/OpenAPI3/DefinitionsSchema.php | 831 +++++++++ tests/src/Tmp/OpenAPI3/Discriminator.php | 64 + tests/src/Tmp/OpenAPI3/Encoding.php | 125 ++ tests/src/Tmp/OpenAPI3/Example.php | 135 ++ .../Tmp/OpenAPI3/ExternalDocumentation.php | 106 ++ tests/src/Tmp/OpenAPI3/HTTPSecurityScheme.php | 147 ++ .../Tmp/OpenAPI3/HTTPSecuritySchemeOneOf0.php | 48 + .../Tmp/OpenAPI3/HTTPSecuritySchemeOneOf1.php | 53 + tests/src/Tmp/OpenAPI3/Header.php | 341 ++++ tests/src/Tmp/OpenAPI3/ImplicitOAuthFlow.php | 125 ++ tests/src/Tmp/OpenAPI3/Info.php | 171 ++ tests/src/Tmp/OpenAPI3/License.php | 106 ++ tests/src/Tmp/OpenAPI3/Link.php | 173 ++ tests/src/Tmp/OpenAPI3/MediaType.php | 167 ++ .../src/Tmp/OpenAPI3/OAuth2SecurityScheme.php | 127 ++ tests/src/Tmp/OpenAPI3/OAuthFlows.php | 134 ++ tests/src/Tmp/OpenAPI3/OpenAPI3Schema.php | 219 +++ .../OpenAPI3/OpenIdConnectSecurityScheme.php | 128 ++ tests/src/Tmp/OpenAPI3/Operation.php | 310 +++ tests/src/Tmp/OpenAPI3/Parameter.php | 379 ++++ .../Tmp/OpenAPI3/ParameterLocationOneOf0.php | 98 + .../Tmp/OpenAPI3/ParameterLocationOneOf1.php | 79 + .../Tmp/OpenAPI3/ParameterLocationOneOf2.php | 70 + .../Tmp/OpenAPI3/ParameterLocationOneOf3.php | 70 + tests/src/Tmp/OpenAPI3/PasswordOAuthFlow.php | 124 ++ tests/src/Tmp/OpenAPI3/PathItem.php | 169 ++ tests/src/Tmp/OpenAPI3/RequestBody.php | 123 ++ tests/src/Tmp/OpenAPI3/Response.php | 160 ++ tests/src/Tmp/OpenAPI3/Responses.php | 148 ++ tests/src/Tmp/OpenAPI3/Server.php | 122 ++ tests/src/Tmp/OpenAPI3/ServerVariable.php | 122 ++ tests/src/Tmp/OpenAPI3/Tag.php | 121 ++ tests/src/Tmp/OpenAPI3/XML.php | 153 ++ 41 files changed, 8069 insertions(+), 3 deletions(-) create mode 100644 tests/resources/openapi3-schema.json create mode 100644 tests/src/PHPUnit/OpenAPI3/GenTest.php create mode 100644 tests/src/Tmp/OpenAPI3/APIKeySecurityScheme.php create mode 100644 tests/src/Tmp/OpenAPI3/AuthorizationCodeOAuthFlow.php create mode 100644 tests/src/Tmp/OpenAPI3/ClientCredentialsFlow.php create mode 100644 tests/src/Tmp/OpenAPI3/Components.php create mode 100644 tests/src/Tmp/OpenAPI3/Contact.php create mode 100644 tests/src/Tmp/OpenAPI3/DefinitionsSchema.php create mode 100644 tests/src/Tmp/OpenAPI3/Discriminator.php create mode 100644 tests/src/Tmp/OpenAPI3/Encoding.php create mode 100644 tests/src/Tmp/OpenAPI3/Example.php create mode 100644 tests/src/Tmp/OpenAPI3/ExternalDocumentation.php create mode 100644 tests/src/Tmp/OpenAPI3/HTTPSecurityScheme.php create mode 100644 tests/src/Tmp/OpenAPI3/HTTPSecuritySchemeOneOf0.php create mode 100644 tests/src/Tmp/OpenAPI3/HTTPSecuritySchemeOneOf1.php create mode 100644 tests/src/Tmp/OpenAPI3/Header.php create mode 100644 tests/src/Tmp/OpenAPI3/ImplicitOAuthFlow.php create mode 100644 tests/src/Tmp/OpenAPI3/Info.php create mode 100644 tests/src/Tmp/OpenAPI3/License.php create mode 100644 tests/src/Tmp/OpenAPI3/Link.php create mode 100644 tests/src/Tmp/OpenAPI3/MediaType.php create mode 100644 tests/src/Tmp/OpenAPI3/OAuth2SecurityScheme.php create mode 100644 tests/src/Tmp/OpenAPI3/OAuthFlows.php create mode 100644 tests/src/Tmp/OpenAPI3/OpenAPI3Schema.php create mode 100644 tests/src/Tmp/OpenAPI3/OpenIdConnectSecurityScheme.php create mode 100644 tests/src/Tmp/OpenAPI3/Operation.php create mode 100644 tests/src/Tmp/OpenAPI3/Parameter.php create mode 100644 tests/src/Tmp/OpenAPI3/ParameterLocationOneOf0.php create mode 100644 tests/src/Tmp/OpenAPI3/ParameterLocationOneOf1.php create mode 100644 tests/src/Tmp/OpenAPI3/ParameterLocationOneOf2.php create mode 100644 tests/src/Tmp/OpenAPI3/ParameterLocationOneOf3.php create mode 100644 tests/src/Tmp/OpenAPI3/PasswordOAuthFlow.php create mode 100644 tests/src/Tmp/OpenAPI3/PathItem.php create mode 100644 tests/src/Tmp/OpenAPI3/RequestBody.php create mode 100644 tests/src/Tmp/OpenAPI3/Response.php create mode 100644 tests/src/Tmp/OpenAPI3/Responses.php create mode 100644 tests/src/Tmp/OpenAPI3/Server.php create mode 100644 tests/src/Tmp/OpenAPI3/ServerVariable.php create mode 100644 tests/src/Tmp/OpenAPI3/Tag.php create mode 100644 tests/src/Tmp/OpenAPI3/XML.php diff --git a/src/JsonSchema/SchemaBuilder.php b/src/JsonSchema/SchemaBuilder.php index 10b5e63..a778c2a 100644 --- a/src/JsonSchema/SchemaBuilder.php +++ b/src/JsonSchema/SchemaBuilder.php @@ -390,11 +390,16 @@ private function processLogic() /** @var string $keyword */ foreach (array($names->not, $names->if, $names->then, $names->else) as $keyword) { if ($this->schema->$keyword !== null) { + $schema = $this->schema->$keyword; + $path = $this->path . '->' . $keyword; + if ($schema instanceof Schema && !empty($schema->getFromRefs())) { + $path = $schema->getFromRefs()[0]; + } $this->result->addSnippet( $this->copyTo(new SchemaBuilder( - $this->schema->$keyword, + $schema, "{$this->varName}->{$keyword}", - $this->path . '->' . $keyword, + $path, $this->phpBuilder ))->build() ); @@ -405,11 +410,15 @@ private function processLogic() foreach (array($names->anyOf, $names->oneOf, $names->allOf) as $keyword) { if ($this->schema->$keyword !== null) { foreach ($this->schema->$keyword as $index => $schema) { + $path = $this->path . "->{$keyword}[{$index}]"; + if ($schema instanceof Schema && !empty($schema->getFromRefs())) { + $path = $schema->getFromRefs()[0]; + } $varName = '$' . PhpCode::makePhpName("{$this->varName}->{$keyword}[{$index}]"); $schemaInit = $this->copyTo(new SchemaBuilder( $schema, $varName, - $this->path . "->{$keyword}[{$index}]", + $path, $this->phpBuilder ))->build(); diff --git a/tests/resources/openapi3-schema.json b/tests/resources/openapi3-schema.json new file mode 100644 index 0000000..7180840 --- /dev/null +++ b/tests/resources/openapi3-schema.json @@ -0,0 +1,1654 @@ +{ + "id": "https://spec.openapis.org/oas/3.0/schema/2019-04-02", + "$schema": "http://json-schema.org/draft-04/schema#", + "description": "Validation schema for OpenAPI Specification 3.0.X.", + "type": "object", + "required": [ + "openapi", + "info", + "paths" + ], + "properties": { + "openapi": { + "type": "string", + "pattern": "^3\\.0\\.\\d(-.+)?$" + }, + "info": { + "$ref": "#/definitions/Info" + }, + "externalDocs": { + "$ref": "#/definitions/ExternalDocumentation" + }, + "servers": { + "type": "array", + "items": { + "$ref": "#/definitions/Server" + } + }, + "security": { + "type": "array", + "items": { + "$ref": "#/definitions/SecurityRequirement" + } + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/Tag" + }, + "uniqueItems": true + }, + "paths": { + "$ref": "#/definitions/Paths" + }, + "components": { + "$ref": "#/definitions/Components" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false, + "definitions": { + "Reference": { + "type": "object", + "required": [ + "$ref" + ], + "patternProperties": { + "^\\$ref$": { + "type": "string", + "format": "uri-reference" + } + } + }, + "Info": { + "type": "object", + "required": [ + "title", + "version" + ], + "properties": { + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "termsOfService": { + "type": "string", + "format": "uri-reference" + }, + "contact": { + "$ref": "#/definitions/Contact" + }, + "license": { + "$ref": "#/definitions/License" + }, + "version": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "Contact": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri-reference" + }, + "email": { + "type": "string", + "format": "email" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "License": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri-reference" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "Server": { + "type": "object", + "required": [ + "url" + ], + "properties": { + "url": { + "type": "string" + }, + "description": { + "type": "string" + }, + "variables": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/ServerVariable" + } + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "ServerVariable": { + "type": "object", + "required": [ + "default" + ], + "properties": { + "enum": { + "type": "array", + "items": { + "type": "string" + } + }, + "default": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "Components": { + "type": "object", + "properties": { + "schemas": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + } + }, + "responses": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Response" + } + ] + } + } + }, + "parameters": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Parameter" + } + ] + } + } + }, + "examples": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Example" + } + ] + } + } + }, + "requestBodies": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/RequestBody" + } + ] + } + } + }, + "headers": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Header" + } + ] + } + } + }, + "securitySchemes": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/SecurityScheme" + } + ] + } + } + }, + "links": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Link" + } + ] + } + } + }, + "callbacks": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Callback" + } + ] + } + } + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "Schema": { + "type": "object", + "properties": { + "title": { + "type": "string" + }, + "multipleOf": { + "type": "number", + "minimum": 0, + "exclusiveMinimum": true + }, + "maximum": { + "type": "number" + }, + "exclusiveMaximum": { + "type": "boolean", + "default": false + }, + "minimum": { + "type": "number" + }, + "exclusiveMinimum": { + "type": "boolean", + "default": false + }, + "maxLength": { + "type": "integer", + "minimum": 0 + }, + "minLength": { + "type": "integer", + "minimum": 0, + "default": 0 + }, + "pattern": { + "type": "string", + "format": "regex" + }, + "maxItems": { + "type": "integer", + "minimum": 0 + }, + "minItems": { + "type": "integer", + "minimum": 0, + "default": 0 + }, + "uniqueItems": { + "type": "boolean", + "default": false + }, + "maxProperties": { + "type": "integer", + "minimum": 0 + }, + "minProperties": { + "type": "integer", + "minimum": 0, + "default": 0 + }, + "required": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true + }, + "enum": { + "type": "array", + "items": { + }, + "minItems": 1, + "uniqueItems": false + }, + "type": { + "type": "string", + "enum": [ + "array", + "boolean", + "integer", + "number", + "object", + "string" + ] + }, + "not": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "allOf": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "oneOf": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "anyOf": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "properties": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + }, + { + "type": "boolean" + } + ], + "default": true + }, + "description": { + "type": "string" + }, + "format": { + "type": "string" + }, + "default": { + }, + "nullable": { + "type": "boolean", + "default": false + }, + "discriminator": { + "$ref": "#/definitions/Discriminator" + }, + "readOnly": { + "type": "boolean", + "default": false + }, + "writeOnly": { + "type": "boolean", + "default": false + }, + "example": { + }, + "externalDocs": { + "$ref": "#/definitions/ExternalDocumentation" + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "xml": { + "$ref": "#/definitions/XML" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "Discriminator": { + "type": "object", + "required": [ + "propertyName" + ], + "properties": { + "propertyName": { + "type": "string" + }, + "mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, + "XML": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "namespace": { + "type": "string", + "format": "uri" + }, + "prefix": { + "type": "string" + }, + "attribute": { + "type": "boolean", + "default": false + }, + "wrapped": { + "type": "boolean", + "default": false + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "Response": { + "type": "object", + "required": [ + "description" + ], + "properties": { + "description": { + "type": "string" + }, + "headers": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Header" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "content": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/MediaType" + } + }, + "links": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Link" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "MediaType": { + "type": "object", + "properties": { + "schema": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "example": { + }, + "examples": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Example" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "encoding": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Encoding" + } + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false, + "allOf": [ + { + "$ref": "#/definitions/ExampleXORExamples" + } + ] + }, + "Example": { + "type": "object", + "properties": { + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "value": { + }, + "externalValue": { + "type": "string", + "format": "uri-reference" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "Header": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "required": { + "type": "boolean", + "default": false + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "allowEmptyValue": { + "type": "boolean", + "default": false + }, + "style": { + "type": "string", + "enum": [ + "simple" + ], + "default": "simple" + }, + "explode": { + "type": "boolean" + }, + "allowReserved": { + "type": "boolean", + "default": false + }, + "schema": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "content": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/MediaType" + }, + "minProperties": 1, + "maxProperties": 1 + }, + "example": { + }, + "examples": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Example" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false, + "allOf": [ + { + "$ref": "#/definitions/ExampleXORExamples" + }, + { + "$ref": "#/definitions/SchemaXORContent" + } + ] + }, + "Paths": { + "type": "object", + "patternProperties": { + "^\\/": { + "$ref": "#/definitions/PathItem" + }, + "^x-": { + } + }, + "additionalProperties": false + }, + "PathItem": { + "type": "object", + "properties": { + "$ref": { + "type": "string" + }, + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "servers": { + "type": "array", + "items": { + "$ref": "#/definitions/Server" + } + }, + "parameters": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Parameter" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "uniqueItems": true + } + }, + "patternProperties": { + "^(get|put|post|delete|options|head|patch|trace)$": { + "$ref": "#/definitions/Operation" + }, + "^x-": { + } + }, + "additionalProperties": false + }, + "Operation": { + "type": "object", + "required": [ + "responses" + ], + "properties": { + "tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "externalDocs": { + "$ref": "#/definitions/ExternalDocumentation" + }, + "operationId": { + "type": "string" + }, + "parameters": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Parameter" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "uniqueItems": true + }, + "requestBody": { + "oneOf": [ + { + "$ref": "#/definitions/RequestBody" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "responses": { + "$ref": "#/definitions/Responses" + }, + "callbacks": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Callback" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "security": { + "type": "array", + "items": { + "$ref": "#/definitions/SecurityRequirement" + } + }, + "servers": { + "type": "array", + "items": { + "$ref": "#/definitions/Server" + } + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "Responses": { + "type": "object", + "properties": { + "default": { + "oneOf": [ + { + "$ref": "#/definitions/Response" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "patternProperties": { + "^[1-5](?:\\d{2}|XX)$": { + "oneOf": [ + { + "$ref": "#/definitions/Response" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "^x-": { + } + }, + "minProperties": 1, + "additionalProperties": false + }, + "SecurityRequirement": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "Tag": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "externalDocs": { + "$ref": "#/definitions/ExternalDocumentation" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "ExternalDocumentation": { + "type": "object", + "required": [ + "url" + ], + "properties": { + "description": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri-reference" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "ExampleXORExamples": { + "description": "Example and examples are mutually exclusive", + "not": { + "required": [ + "example", + "examples" + ] + } + }, + "SchemaXORContent": { + "description": "Schema and content are mutually exclusive, at least one is required", + "not": { + "required": [ + "schema", + "content" + ] + }, + "oneOf": [ + { + "required": [ + "schema" + ] + }, + { + "required": [ + "content" + ], + "description": "Some properties are not allowed if content is present", + "allOf": [ + { + "not": { + "required": [ + "style" + ] + } + }, + { + "not": { + "required": [ + "explode" + ] + } + }, + { + "not": { + "required": [ + "allowReserved" + ] + } + }, + { + "not": { + "required": [ + "example" + ] + } + }, + { + "not": { + "required": [ + "examples" + ] + } + } + ] + } + ] + }, + "Parameter": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "in": { + "type": "string" + }, + "description": { + "type": "string" + }, + "required": { + "type": "boolean", + "default": false + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "allowEmptyValue": { + "type": "boolean", + "default": false + }, + "style": { + "type": "string" + }, + "explode": { + "type": "boolean" + }, + "allowReserved": { + "type": "boolean", + "default": false + }, + "schema": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "content": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/MediaType" + }, + "minProperties": 1, + "maxProperties": 1 + }, + "example": { + }, + "examples": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Example" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false, + "required": [ + "name", + "in" + ], + "allOf": [ + { + "$ref": "#/definitions/ExampleXORExamples" + }, + { + "$ref": "#/definitions/SchemaXORContent" + }, + { + "$ref": "#/definitions/ParameterLocation" + } + ] + }, + "ParameterLocation": { + "description": "Parameter location", + "oneOf": [ + { + "description": "Parameter in path", + "required": [ + "required" + ], + "properties": { + "in": { + "enum": [ + "path" + ] + }, + "style": { + "enum": [ + "matrix", + "label", + "simple" + ], + "default": "simple" + }, + "required": { + "enum": [ + true + ] + } + } + }, + { + "description": "Parameter in query", + "properties": { + "in": { + "enum": [ + "query" + ] + }, + "style": { + "enum": [ + "form", + "spaceDelimited", + "pipeDelimited", + "deepObject" + ], + "default": "form" + } + } + }, + { + "description": "Parameter in header", + "properties": { + "in": { + "enum": [ + "header" + ] + }, + "style": { + "enum": [ + "simple" + ], + "default": "simple" + } + } + }, + { + "description": "Parameter in cookie", + "properties": { + "in": { + "enum": [ + "cookie" + ] + }, + "style": { + "enum": [ + "form" + ], + "default": "form" + } + } + } + ] + }, + "RequestBody": { + "type": "object", + "required": [ + "content" + ], + "properties": { + "description": { + "type": "string" + }, + "content": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/MediaType" + } + }, + "required": { + "type": "boolean", + "default": false + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "SecurityScheme": { + "oneOf": [ + { + "$ref": "#/definitions/APIKeySecurityScheme" + }, + { + "$ref": "#/definitions/HTTPSecurityScheme" + }, + { + "$ref": "#/definitions/OAuth2SecurityScheme" + }, + { + "$ref": "#/definitions/OpenIdConnectSecurityScheme" + } + ] + }, + "APIKeySecurityScheme": { + "type": "object", + "required": [ + "type", + "name", + "in" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "apiKey" + ] + }, + "name": { + "type": "string" + }, + "in": { + "type": "string", + "enum": [ + "header", + "query", + "cookie" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "HTTPSecurityScheme": { + "type": "object", + "required": [ + "scheme", + "type" + ], + "properties": { + "scheme": { + "type": "string" + }, + "bearerFormat": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "http" + ] + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false, + "oneOf": [ + { + "description": "Bearer", + "properties": { + "scheme": { + "enum": [ + "bearer" + ] + } + } + }, + { + "description": "Non Bearer", + "not": { + "required": [ + "bearerFormat" + ] + }, + "properties": { + "scheme": { + "not": { + "enum": [ + "bearer" + ] + } + } + } + } + ] + }, + "OAuth2SecurityScheme": { + "type": "object", + "required": [ + "type", + "flows" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "oauth2" + ] + }, + "flows": { + "$ref": "#/definitions/OAuthFlows" + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "OpenIdConnectSecurityScheme": { + "type": "object", + "required": [ + "type", + "openIdConnectUrl" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "openIdConnect" + ] + }, + "openIdConnectUrl": { + "type": "string", + "format": "uri-reference" + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "OAuthFlows": { + "type": "object", + "properties": { + "implicit": { + "$ref": "#/definitions/ImplicitOAuthFlow" + }, + "password": { + "$ref": "#/definitions/PasswordOAuthFlow" + }, + "clientCredentials": { + "$ref": "#/definitions/ClientCredentialsFlow" + }, + "authorizationCode": { + "$ref": "#/definitions/AuthorizationCodeOAuthFlow" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "ImplicitOAuthFlow": { + "type": "object", + "required": [ + "authorizationUrl", + "scopes" + ], + "properties": { + "authorizationUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "PasswordOAuthFlow": { + "type": "object", + "required": [ + "tokenUrl" + ], + "properties": { + "tokenUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "ClientCredentialsFlow": { + "type": "object", + "required": [ + "tokenUrl" + ], + "properties": { + "tokenUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "AuthorizationCodeOAuthFlow": { + "type": "object", + "required": [ + "authorizationUrl", + "tokenUrl" + ], + "properties": { + "authorizationUrl": { + "type": "string", + "format": "uri-reference" + }, + "tokenUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false + }, + "Link": { + "type": "object", + "properties": { + "operationId": { + "type": "string" + }, + "operationRef": { + "type": "string", + "format": "uri-reference" + }, + "parameters": { + "type": "object", + "additionalProperties": { + } + }, + "requestBody": { + }, + "description": { + "type": "string" + }, + "server": { + "$ref": "#/definitions/Server" + } + }, + "patternProperties": { + "^x-": { + } + }, + "additionalProperties": false, + "not": { + "description": "Operation Id and Operation Ref are mutually exclusive", + "required": [ + "operationId", + "operationRef" + ] + } + }, + "Callback": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/PathItem" + }, + "patternProperties": { + "^x-": { + } + } + }, + "Encoding": { + "type": "object", + "properties": { + "contentType": { + "type": "string" + }, + "headers": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Header" + } + }, + "style": { + "type": "string", + "enum": [ + "form", + "spaceDelimited", + "pipeDelimited", + "deepObject" + ] + }, + "explode": { + "type": "boolean" + }, + "allowReserved": { + "type": "boolean", + "default": false + } + }, + "additionalProperties": false + } + } +} \ No newline at end of file diff --git a/tests/src/PHPUnit/OpenAPI3/GenTest.php b/tests/src/PHPUnit/OpenAPI3/GenTest.php new file mode 100644 index 0000000..e029c28 --- /dev/null +++ b/tests/src/PHPUnit/OpenAPI3/GenTest.php @@ -0,0 +1,81 @@ +setSchemaData('http://swagger.io/v2/schema.json', $schemaData); + + $options = new Context(); + $options->setRemoteRefProvider($refProvider); + + $swaggerSchema = Schema::import($schemaData, $options); + + $appPath = realpath(__DIR__ . '/../../Tmp') . '/' . $this->nsItem; + $appNs = 'Swaggest\PhpCodeBuilder\Tests\Tmp\\' . $this->nsItem; + + $app = new PhpApp(); + $app->setNamespaceRoot($appNs, '.'); + + $builder = new PhpBuilder(); + $builder->buildSetters = true; + $builder->makeEnumConstants = true; + $builder->minimizeRefs = $this->minimizeRefs; + + $builder->classCreatedHook = new ClassHookCallback(function (PhpClass $class, $path, $schema) use ($app, $appNs) { + $desc = ''; + if ($schema->title) { + $desc = $schema->title; + } + if ($schema->description) { + $desc .= "\n" . $schema->description; + } + if ($fromRefs = $schema->getFromRefs()) { + $desc .= "\nBuilt from " . implode("\n" . ' <- ', $fromRefs); + } + + $class->setDescription(trim($desc)); + + $class->setNamespace($appNs); + if ('#' === $path) { + $class->setName('OpenAPI3Schema'); + } elseif ('#/definitions/' === substr($path, 0, strlen('#/definitions/'))) { + $className = PhpCode::makePhpClassName(substr($path, strlen('#/definitions/'))); + if ($className === 'Schema') { + $className = 'DefinitionsSchema'; + } + $class->setName($className); + } + $app->addClass($class); + }); + + $builder->classPreparedHook = new SchemaExporterInterface(); + + $builder->getType($swaggerSchema); + $app->clearOldFiles($appPath); + $app->store($appPath); + + exec('git diff ' . $appPath, $out); + $out = implode("\n", $out); + $this->assertSame('', $out, "Generated files changed"); + } + +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/APIKeySecurityScheme.php b/tests/src/Tmp/OpenAPI3/APIKeySecurityScheme.php new file mode 100644 index 0000000..5a5e6d1 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/APIKeySecurityScheme.php @@ -0,0 +1,155 @@ +type = Schema::string(); + $properties->type->enum = array( + self::API_KEY, + ); + $properties->name = Schema::string(); + $properties->in = Schema::string(); + $properties->in->enum = array( + self::HEADER, + self::QUERY, + self::COOKIE, + ); + $properties->description = Schema::string(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->type, + self::names()->name, + self::names()->in, + ); + $ownerSchema->setFromRef('#/definitions/APIKeySecurityScheme'); + } + + /** + * @param string $type + * @return $this + * @codeCoverageIgnoreStart + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @return $this + * @codeCoverageIgnoreStart + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $in + * @return $this + * @codeCoverageIgnoreStart + */ + public function setIn($in) + { + $this->in = $in; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/AuthorizationCodeOAuthFlow.php b/tests/src/Tmp/OpenAPI3/AuthorizationCodeOAuthFlow.php new file mode 100644 index 0000000..75fd100 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/AuthorizationCodeOAuthFlow.php @@ -0,0 +1,142 @@ +authorizationUrl = Schema::string(); + $properties->authorizationUrl->format = "uri-reference"; + $properties->tokenUrl = Schema::string(); + $properties->tokenUrl->format = "uri-reference"; + $properties->refreshUrl = Schema::string(); + $properties->refreshUrl->format = "uri-reference"; + $properties->scopes = Schema::object(); + $properties->scopes->additionalProperties = Schema::string(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->authorizationUrl, + self::names()->tokenUrl, + ); + $ownerSchema->setFromRef('#/definitions/AuthorizationCodeOAuthFlow'); + } + + /** + * @param string $authorizationUrl + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAuthorizationUrl($authorizationUrl) + { + $this->authorizationUrl = $authorizationUrl; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $tokenUrl + * @return $this + * @codeCoverageIgnoreStart + */ + public function setTokenUrl($tokenUrl) + { + $this->tokenUrl = $tokenUrl; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $refreshUrl + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRefreshUrl($refreshUrl) + { + $this->refreshUrl = $refreshUrl; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[] $scopes + * @return $this + * @codeCoverageIgnoreStart + */ + public function setScopes($scopes) + { + $this->scopes = $scopes; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/ClientCredentialsFlow.php b/tests/src/Tmp/OpenAPI3/ClientCredentialsFlow.php new file mode 100644 index 0000000..f6eab9c --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/ClientCredentialsFlow.php @@ -0,0 +1,124 @@ +tokenUrl = Schema::string(); + $properties->tokenUrl->format = "uri-reference"; + $properties->refreshUrl = Schema::string(); + $properties->refreshUrl->format = "uri-reference"; + $properties->scopes = Schema::object(); + $properties->scopes->additionalProperties = Schema::string(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->tokenUrl, + ); + $ownerSchema->setFromRef('#/definitions/ClientCredentialsFlow'); + } + + /** + * @param string $tokenUrl + * @return $this + * @codeCoverageIgnoreStart + */ + public function setTokenUrl($tokenUrl) + { + $this->tokenUrl = $tokenUrl; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $refreshUrl + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRefreshUrl($refreshUrl) + { + $this->refreshUrl = $refreshUrl; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[] $scopes + * @return $this + * @codeCoverageIgnoreStart + */ + public function setScopes($scopes) + { + $this->scopes = $scopes; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Components.php b/tests/src/Tmp/OpenAPI3/Components.php new file mode 100644 index 0000000..afc4471 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Components.php @@ -0,0 +1,333 @@ +schemas = Schema::object(); + $patternProperty = new Schema(); + $patternProperty->oneOf[0] = DefinitionsSchema::schema(); + $patternPropertyOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $patternPropertyOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $patternPropertyOneOf1->required = array( + '$ref', + ); + $patternPropertyOneOf1->setFromRef('#/definitions/Reference'); + $patternProperty->oneOf[1] = $patternPropertyOneOf1; + $properties->schemas->setPatternProperty('^[a-zA-Z0-9\\.\\-_]+$', $patternProperty); + $properties->responses = Schema::object(); + $patternProperty = new Schema(); + $patternPropertyOneOf0 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $patternPropertyOneOf0->setPatternProperty('^\\$ref$', $patternProperty); + $patternPropertyOneOf0->required = array( + '$ref', + ); + $patternPropertyOneOf0->setFromRef('#/definitions/Reference'); + $patternProperty->oneOf[0] = $patternPropertyOneOf0; + $patternProperty->oneOf[1] = Response::schema(); + $properties->responses->setPatternProperty('^[a-zA-Z0-9\\.\\-_]+$', $patternProperty); + $properties->parameters = Schema::object(); + $patternProperty = new Schema(); + $patternPropertyOneOf0 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $patternPropertyOneOf0->setPatternProperty('^\\$ref$', $patternProperty); + $patternPropertyOneOf0->required = array( + '$ref', + ); + $patternPropertyOneOf0->setFromRef('#/definitions/Reference'); + $patternProperty->oneOf[0] = $patternPropertyOneOf0; + $patternProperty->oneOf[1] = Parameter::schema(); + $properties->parameters->setPatternProperty('^[a-zA-Z0-9\\.\\-_]+$', $patternProperty); + $properties->examples = Schema::object(); + $patternProperty = new Schema(); + $patternPropertyOneOf0 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $patternPropertyOneOf0->setPatternProperty('^\\$ref$', $patternProperty); + $patternPropertyOneOf0->required = array( + '$ref', + ); + $patternPropertyOneOf0->setFromRef('#/definitions/Reference'); + $patternProperty->oneOf[0] = $patternPropertyOneOf0; + $patternProperty->oneOf[1] = Example::schema(); + $properties->examples->setPatternProperty('^[a-zA-Z0-9\\.\\-_]+$', $patternProperty); + $properties->requestBodies = Schema::object(); + $patternProperty = new Schema(); + $patternPropertyOneOf0 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $patternPropertyOneOf0->setPatternProperty('^\\$ref$', $patternProperty); + $patternPropertyOneOf0->required = array( + '$ref', + ); + $patternPropertyOneOf0->setFromRef('#/definitions/Reference'); + $patternProperty->oneOf[0] = $patternPropertyOneOf0; + $patternProperty->oneOf[1] = RequestBody::schema(); + $properties->requestBodies->setPatternProperty('^[a-zA-Z0-9\\.\\-_]+$', $patternProperty); + $properties->headers = Schema::object(); + $patternProperty = new Schema(); + $patternPropertyOneOf0 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $patternPropertyOneOf0->setPatternProperty('^\\$ref$', $patternProperty); + $patternPropertyOneOf0->required = array( + '$ref', + ); + $patternPropertyOneOf0->setFromRef('#/definitions/Reference'); + $patternProperty->oneOf[0] = $patternPropertyOneOf0; + $patternProperty->oneOf[1] = Header::schema(); + $properties->headers->setPatternProperty('^[a-zA-Z0-9\\.\\-_]+$', $patternProperty); + $properties->securitySchemes = Schema::object(); + $patternProperty = new Schema(); + $patternPropertyOneOf0 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $patternPropertyOneOf0->setPatternProperty('^\\$ref$', $patternProperty); + $patternPropertyOneOf0->required = array( + '$ref', + ); + $patternPropertyOneOf0->setFromRef('#/definitions/Reference'); + $patternProperty->oneOf[0] = $patternPropertyOneOf0; + $patternPropertyOneOf1 = new Schema(); + $patternPropertyOneOf1->oneOf[0] = APIKeySecurityScheme::schema(); + $patternPropertyOneOf1->oneOf[1] = HTTPSecurityScheme::schema(); + $patternPropertyOneOf1->oneOf[2] = OAuth2SecurityScheme::schema(); + $patternPropertyOneOf1->oneOf[3] = OpenIdConnectSecurityScheme::schema(); + $patternPropertyOneOf1->setFromRef('#/definitions/SecurityScheme'); + $patternProperty->oneOf[1] = $patternPropertyOneOf1; + $properties->securitySchemes->setPatternProperty('^[a-zA-Z0-9\\.\\-_]+$', $patternProperty); + $properties->links = Schema::object(); + $patternProperty = new Schema(); + $patternPropertyOneOf0 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $patternPropertyOneOf0->setPatternProperty('^\\$ref$', $patternProperty); + $patternPropertyOneOf0->required = array( + '$ref', + ); + $patternPropertyOneOf0->setFromRef('#/definitions/Reference'); + $patternProperty->oneOf[0] = $patternPropertyOneOf0; + $patternProperty->oneOf[1] = Link::schema(); + $properties->links->setPatternProperty('^[a-zA-Z0-9\\.\\-_]+$', $patternProperty); + $properties->callbacks = Schema::object(); + $patternProperty = new Schema(); + $patternPropertyOneOf0 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $patternPropertyOneOf0->setPatternProperty('^\\$ref$', $patternProperty); + $patternPropertyOneOf0->required = array( + '$ref', + ); + $patternPropertyOneOf0->setFromRef('#/definitions/Reference'); + $patternProperty->oneOf[0] = $patternPropertyOneOf0; + $patternPropertyOneOf1 = Schema::object(); + $patternPropertyOneOf1->additionalProperties = PathItem::schema(); + $patternProperty = new Schema(); + $patternPropertyOneOf1->setPatternProperty('^x-', $patternProperty); + $patternPropertyOneOf1->setFromRef('#/definitions/Callback'); + $patternProperty->oneOf[1] = $patternPropertyOneOf1; + $properties->callbacks->setPatternProperty('^[a-zA-Z0-9\\.\\-_]+$', $patternProperty); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->setFromRef('#/definitions/Components'); + } + + /** + * @param DefinitionsSchema[]|string[][] $schemas + * @return $this + * @codeCoverageIgnoreStart + */ + public function setSchemas($schemas) + { + $this->schemas = $schemas; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[][]|Response[] $responses + * @return $this + * @codeCoverageIgnoreStart + */ + public function setResponses($responses) + { + $this->responses = $responses; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[][]|Parameter[]|mixed[]|ParameterLocationOneOf0[]|ParameterLocationOneOf1[]|ParameterLocationOneOf2[]|ParameterLocationOneOf3[] $parameters + * @return $this + * @codeCoverageIgnoreStart + */ + public function setParameters($parameters) + { + $this->parameters = $parameters; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[][]|Example[] $examples + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExamples($examples) + { + $this->examples = $examples; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[][]|RequestBody[] $requestBodies + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRequestBodies($requestBodies) + { + $this->requestBodies = $requestBodies; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[][]|Header[]|mixed[] $headers + * @return $this + * @codeCoverageIgnoreStart + */ + public function setHeaders($headers) + { + $this->headers = $headers; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[][]|APIKeySecurityScheme[]|HTTPSecurityScheme[]|HTTPSecuritySchemeOneOf0[]|HTTPSecuritySchemeOneOf1[]|OAuth2SecurityScheme[]|OpenIdConnectSecurityScheme[] $securitySchemes + * @return $this + * @codeCoverageIgnoreStart + */ + public function setSecuritySchemes($securitySchemes) + { + $this->securitySchemes = $securitySchemes; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[][]|Link[] $links + * @return $this + * @codeCoverageIgnoreStart + */ + public function setLinks($links) + { + $this->links = $links; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[][]|PathItem[]|Operation[][][] $callbacks + * @return $this + * @codeCoverageIgnoreStart + */ + public function setCallbacks($callbacks) + { + $this->callbacks = $callbacks; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Contact.php b/tests/src/Tmp/OpenAPI3/Contact.php new file mode 100644 index 0000000..f20e690 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Contact.php @@ -0,0 +1,120 @@ +name = Schema::string(); + $properties->url = Schema::string(); + $properties->url->format = "uri-reference"; + $properties->email = Schema::string(); + $properties->email->format = "email"; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->setFromRef('#/definitions/Contact'); + } + + /** + * @param string $name + * @return $this + * @codeCoverageIgnoreStart + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $url + * @return $this + * @codeCoverageIgnoreStart + */ + public function setUrl($url) + { + $this->url = $url; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $email + * @return $this + * @codeCoverageIgnoreStart + */ + public function setEmail($email) + { + $this->email = $email; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/DefinitionsSchema.php b/tests/src/Tmp/OpenAPI3/DefinitionsSchema.php new file mode 100644 index 0000000..3c383a5 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/DefinitionsSchema.php @@ -0,0 +1,831 @@ +title = Schema::string(); + $properties->multipleOf = Schema::number(); + $properties->multipleOf->minimum = 0; + $properties->multipleOf->exclusiveMinimum = true; + $properties->maximum = Schema::number(); + $properties->exclusiveMaximum = Schema::boolean(); + $properties->exclusiveMaximum->default = false; + $properties->minimum = Schema::number(); + $properties->exclusiveMinimum = Schema::boolean(); + $properties->exclusiveMinimum->default = false; + $properties->maxLength = Schema::integer(); + $properties->maxLength->minimum = 0; + $properties->minLength = Schema::integer(); + $properties->minLength->default = 0; + $properties->minLength->minimum = 0; + $properties->pattern = Schema::string(); + $properties->pattern->format = "regex"; + $properties->maxItems = Schema::integer(); + $properties->maxItems->minimum = 0; + $properties->minItems = Schema::integer(); + $properties->minItems->default = 0; + $properties->minItems->minimum = 0; + $properties->uniqueItems = Schema::boolean(); + $properties->uniqueItems->default = false; + $properties->maxProperties = Schema::integer(); + $properties->maxProperties->minimum = 0; + $properties->minProperties = Schema::integer(); + $properties->minProperties->default = 0; + $properties->minProperties->minimum = 0; + $properties->required = Schema::arr(); + $properties->required->items = Schema::string(); + $properties->required->minItems = 1; + $properties->required->uniqueItems = true; + $properties->enum = Schema::arr(); + $properties->enum->items = new Schema(); + $properties->enum->minItems = 1; + $properties->enum->uniqueItems = false; + $properties->type = Schema::string(); + $properties->type->enum = array( + self::_ARRAY, + self::BOOLEAN, + self::INTEGER, + self::NUMBER, + self::OBJECT, + self::STRING, + ); + $properties->not = new Schema(); + $properties->not->oneOf[0] = DefinitionsSchema::schema(); + $propertiesNotOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesNotOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesNotOneOf1->required = array( + '$ref', + ); + $propertiesNotOneOf1->setFromRef('#/definitions/Reference'); + $properties->not->oneOf[1] = $propertiesNotOneOf1; + $properties->allOf = Schema::arr(); + $properties->allOf->items = new Schema(); + $properties->allOf->items->oneOf[0] = DefinitionsSchema::schema(); + $propertiesAllOfItemsOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesAllOfItemsOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesAllOfItemsOneOf1->required = array( + '$ref', + ); + $propertiesAllOfItemsOneOf1->setFromRef('#/definitions/Reference'); + $properties->allOf->items->oneOf[1] = $propertiesAllOfItemsOneOf1; + $properties->oneOf = Schema::arr(); + $properties->oneOf->items = new Schema(); + $properties->oneOf->items->oneOf[0] = DefinitionsSchema::schema(); + $propertiesOneOfItemsOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesOneOfItemsOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesOneOfItemsOneOf1->required = array( + '$ref', + ); + $propertiesOneOfItemsOneOf1->setFromRef('#/definitions/Reference'); + $properties->oneOf->items->oneOf[1] = $propertiesOneOfItemsOneOf1; + $properties->anyOf = Schema::arr(); + $properties->anyOf->items = new Schema(); + $properties->anyOf->items->oneOf[0] = DefinitionsSchema::schema(); + $propertiesAnyOfItemsOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesAnyOfItemsOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesAnyOfItemsOneOf1->required = array( + '$ref', + ); + $propertiesAnyOfItemsOneOf1->setFromRef('#/definitions/Reference'); + $properties->anyOf->items->oneOf[1] = $propertiesAnyOfItemsOneOf1; + $properties->items = new Schema(); + $properties->items->oneOf[0] = DefinitionsSchema::schema(); + $propertiesItemsOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesItemsOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesItemsOneOf1->required = array( + '$ref', + ); + $propertiesItemsOneOf1->setFromRef('#/definitions/Reference'); + $properties->items->oneOf[1] = $propertiesItemsOneOf1; + $properties->properties = Schema::object(); + $properties->properties->additionalProperties = new Schema(); + $properties->properties->additionalProperties->oneOf[0] = DefinitionsSchema::schema(); + $propertiesPropertiesAdditionalPropertiesOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesPropertiesAdditionalPropertiesOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesPropertiesAdditionalPropertiesOneOf1->required = array( + '$ref', + ); + $propertiesPropertiesAdditionalPropertiesOneOf1->setFromRef('#/definitions/Reference'); + $properties->properties->additionalProperties->oneOf[1] = $propertiesPropertiesAdditionalPropertiesOneOf1; + $properties->additionalProperties = new Schema(); + $properties->additionalProperties->oneOf[0] = DefinitionsSchema::schema(); + $propertiesAdditionalPropertiesOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesAdditionalPropertiesOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesAdditionalPropertiesOneOf1->required = array( + '$ref', + ); + $propertiesAdditionalPropertiesOneOf1->setFromRef('#/definitions/Reference'); + $properties->additionalProperties->oneOf[1] = $propertiesAdditionalPropertiesOneOf1; + $properties->additionalProperties->oneOf[2] = Schema::boolean(); + $properties->additionalProperties->default = true; + $properties->description = Schema::string(); + $properties->format = Schema::string(); + $properties->default = new Schema(); + $properties->nullable = Schema::boolean(); + $properties->nullable->default = false; + $properties->discriminator = Discriminator::schema(); + $properties->readOnly = Schema::boolean(); + $properties->readOnly->default = false; + $properties->writeOnly = Schema::boolean(); + $properties->writeOnly->default = false; + $properties->example = new Schema(); + $properties->externalDocs = ExternalDocumentation::schema(); + $properties->deprecated = Schema::boolean(); + $properties->deprecated->default = false; + $properties->xml = XML::schema(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->setFromRef('#/definitions/Schema'); + } + + /** + * @param string $title + * @return $this + * @codeCoverageIgnoreStart + */ + public function setTitle($title) + { + $this->title = $title; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param float $multipleOf + * @return $this + * @codeCoverageIgnoreStart + */ + public function setMultipleOf($multipleOf) + { + $this->multipleOf = $multipleOf; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param float $maximum + * @return $this + * @codeCoverageIgnoreStart + */ + public function setMaximum($maximum) + { + $this->maximum = $maximum; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $exclusiveMaximum + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExclusiveMaximum($exclusiveMaximum) + { + $this->exclusiveMaximum = $exclusiveMaximum; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param float $minimum + * @return $this + * @codeCoverageIgnoreStart + */ + public function setMinimum($minimum) + { + $this->minimum = $minimum; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $exclusiveMinimum + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExclusiveMinimum($exclusiveMinimum) + { + $this->exclusiveMinimum = $exclusiveMinimum; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param int $maxLength + * @return $this + * @codeCoverageIgnoreStart + */ + public function setMaxLength($maxLength) + { + $this->maxLength = $maxLength; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param int $minLength + * @return $this + * @codeCoverageIgnoreStart + */ + public function setMinLength($minLength) + { + $this->minLength = $minLength; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $pattern + * @return $this + * @codeCoverageIgnoreStart + */ + public function setPattern($pattern) + { + $this->pattern = $pattern; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param int $maxItems + * @return $this + * @codeCoverageIgnoreStart + */ + public function setMaxItems($maxItems) + { + $this->maxItems = $maxItems; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param int $minItems + * @return $this + * @codeCoverageIgnoreStart + */ + public function setMinItems($minItems) + { + $this->minItems = $minItems; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $uniqueItems + * @return $this + * @codeCoverageIgnoreStart + */ + public function setUniqueItems($uniqueItems) + { + $this->uniqueItems = $uniqueItems; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param int $maxProperties + * @return $this + * @codeCoverageIgnoreStart + */ + public function setMaxProperties($maxProperties) + { + $this->maxProperties = $maxProperties; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param int $minProperties + * @return $this + * @codeCoverageIgnoreStart + */ + public function setMinProperties($minProperties) + { + $this->minProperties = $minProperties; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[]|array $required + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRequired($required) + { + $this->required = $required; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param array $enum + * @return $this + * @codeCoverageIgnoreStart + */ + public function setEnum($enum) + { + $this->enum = $enum; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $type + * @return $this + * @codeCoverageIgnoreStart + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param DefinitionsSchema|string[] $not + * @return $this + * @codeCoverageIgnoreStart + */ + public function setNot($not) + { + $this->not = $not; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param DefinitionsSchema[]|string[][]|array $allOf + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAllOf($allOf) + { + $this->allOf = $allOf; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param DefinitionsSchema[]|string[][]|array $oneOf + * @return $this + * @codeCoverageIgnoreStart + */ + public function setOneOf($oneOf) + { + $this->oneOf = $oneOf; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param DefinitionsSchema[]|string[][]|array $anyOf + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAnyOf($anyOf) + { + $this->anyOf = $anyOf; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param DefinitionsSchema|string[] $items + * @return $this + * @codeCoverageIgnoreStart + */ + public function setItems($items) + { + $this->items = $items; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param DefinitionsSchema[]|string[][] $properties + * @return $this + * @codeCoverageIgnoreStart + */ + public function setProperties($properties) + { + $this->properties = $properties; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param DefinitionsSchema|string[]|bool $additionalProperties + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAdditionalProperties($additionalProperties) + { + $this->additionalProperties = $additionalProperties; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $format + * @return $this + * @codeCoverageIgnoreStart + */ + public function setFormat($format) + { + $this->format = $format; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $default + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDefault($default) + { + $this->default = $default; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $nullable + * @return $this + * @codeCoverageIgnoreStart + */ + public function setNullable($nullable) + { + $this->nullable = $nullable; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Discriminator $discriminator + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDiscriminator(Discriminator $discriminator) + { + $this->discriminator = $discriminator; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $readOnly + * @return $this + * @codeCoverageIgnoreStart + */ + public function setReadOnly($readOnly) + { + $this->readOnly = $readOnly; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $writeOnly + * @return $this + * @codeCoverageIgnoreStart + */ + public function setWriteOnly($writeOnly) + { + $this->writeOnly = $writeOnly; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $example + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExample($example) + { + $this->example = $example; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param ExternalDocumentation $externalDocs + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExternalDocs(ExternalDocumentation $externalDocs) + { + $this->externalDocs = $externalDocs; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $deprecated + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDeprecated($deprecated) + { + $this->deprecated = $deprecated; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param XML $xml + * @return $this + * @codeCoverageIgnoreStart + */ + public function setXml(XML $xml) + { + $this->xml = $xml; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @return Schema + */ + function exportSchema() + { + if (null === self::$schemaStorage) { + self::$schemaStorage = new SplObjectStorage(); + } + + if (self::$schemaStorage->contains($this)) { + return self::$schemaStorage->offsetGet($this); + } else { + $schema = new Schema(); + self::$schemaStorage->attach($this, $schema); + } + $schema->title = $this->title; + $schema->multipleOf = $this->multipleOf; + $schema->maximum = $this->maximum; + $schema->exclusiveMaximum = $this->exclusiveMaximum; + $schema->minimum = $this->minimum; + $schema->exclusiveMinimum = $this->exclusiveMinimum; + $schema->maxLength = $this->maxLength; + $schema->minLength = $this->minLength; + $schema->pattern = $this->pattern; + $schema->maxItems = $this->maxItems; + $schema->minItems = $this->minItems; + $schema->uniqueItems = $this->uniqueItems; + $schema->maxProperties = $this->maxProperties; + $schema->minProperties = $this->minProperties; + $schema->required = $this->required; + $schema->enum = $this->enum; + $schema->type = $this->type; + if (!empty($this->allOf)) { + foreach ($this->allOf as $i => $item) { + if ($item instanceof SchemaExporter) { + $schema->allOf[$i] = $item->exportSchema(); + } + } + } + if (!empty($this->oneOf)) { + foreach ($this->oneOf as $i => $item) { + if ($item instanceof SchemaExporter) { + $schema->oneOf[$i] = $item->exportSchema(); + } + } + } + if (!empty($this->anyOf)) { + foreach ($this->anyOf as $i => $item) { + if ($item instanceof SchemaExporter) { + $schema->anyOf[$i] = $item->exportSchema(); + } + } + } + if ($this->items !== null && $this->items instanceof SchemaExporter) { + $schema->items = $this->items->exportSchema(); + } + if (!empty($this->properties)) { + foreach ($this->properties as $propertyName => $propertySchema) { + if (is_string($propertyName) && $propertySchema instanceof SchemaExporter) { + $schema->setProperty($propertyName, $propertySchema->exportSchema()); + } + } + } + if ($this->additionalProperties !== null && $this->additionalProperties instanceof SchemaExporter) { + $schema->additionalProperties = $this->additionalProperties->exportSchema(); + } + $schema->description = $this->description; + $schema->format = $this->format; + $schema->default = $this->default; + $schema->__fromRef = $this->__fromRef; + $schema->setDocumentPath($this->getDocumentPath()); + $schema->addMeta($this, 'origin'); + return $schema; + } +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Discriminator.php b/tests/src/Tmp/OpenAPI3/Discriminator.php new file mode 100644 index 0000000..4e71eee --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Discriminator.php @@ -0,0 +1,64 @@ +propertyName = Schema::string(); + $properties->mapping = Schema::object(); + $properties->mapping->additionalProperties = Schema::string(); + $ownerSchema->type = 'object'; + $ownerSchema->required = array( + self::names()->propertyName, + ); + $ownerSchema->setFromRef('#/definitions/Discriminator'); + } + + /** + * @param string $propertyName + * @return $this + * @codeCoverageIgnoreStart + */ + public function setPropertyName($propertyName) + { + $this->propertyName = $propertyName; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[] $mapping + * @return $this + * @codeCoverageIgnoreStart + */ + public function setMapping($mapping) + { + $this->mapping = $mapping; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Encoding.php b/tests/src/Tmp/OpenAPI3/Encoding.php new file mode 100644 index 0000000..4645d70 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Encoding.php @@ -0,0 +1,125 @@ +contentType = Schema::string(); + $properties->headers = Schema::object(); + $properties->headers->additionalProperties = Header::schema(); + $properties->style = Schema::string(); + $properties->style->enum = array( + self::FORM, + self::SPACE_DELIMITED, + self::PIPE_DELIMITED, + self::DEEP_OBJECT, + ); + $properties->explode = Schema::boolean(); + $properties->allowReserved = Schema::boolean(); + $properties->allowReserved->default = false; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $ownerSchema->setFromRef('#/definitions/Encoding'); + } + + /** + * @param string $contentType + * @return $this + * @codeCoverageIgnoreStart + */ + public function setContentType($contentType) + { + $this->contentType = $contentType; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Header[]|mixed[] $headers + * @return $this + * @codeCoverageIgnoreStart + */ + public function setHeaders($headers) + { + $this->headers = $headers; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $style + * @return $this + * @codeCoverageIgnoreStart + */ + public function setStyle($style) + { + $this->style = $style; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $explode + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExplode($explode) + { + $this->explode = $explode; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $allowReserved + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAllowReserved($allowReserved) + { + $this->allowReserved = $allowReserved; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Example.php b/tests/src/Tmp/OpenAPI3/Example.php new file mode 100644 index 0000000..5e62f82 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Example.php @@ -0,0 +1,135 @@ +summary = Schema::string(); + $properties->description = Schema::string(); + $properties->value = new Schema(); + $properties->externalValue = Schema::string(); + $properties->externalValue->format = "uri-reference"; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->setFromRef('#/definitions/Example'); + } + + /** + * @param string $summary + * @return $this + * @codeCoverageIgnoreStart + */ + public function setSummary($summary) + { + $this->summary = $summary; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $value + * @return $this + * @codeCoverageIgnoreStart + */ + public function setValue($value) + { + $this->value = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $externalValue + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExternalValue($externalValue) + { + $this->externalValue = $externalValue; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/ExternalDocumentation.php b/tests/src/Tmp/OpenAPI3/ExternalDocumentation.php new file mode 100644 index 0000000..735e430 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/ExternalDocumentation.php @@ -0,0 +1,106 @@ +description = Schema::string(); + $properties->url = Schema::string(); + $properties->url->format = "uri-reference"; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->url, + ); + $ownerSchema->setFromRef('#/definitions/ExternalDocumentation'); + } + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $url + * @return $this + * @codeCoverageIgnoreStart + */ + public function setUrl($url) + { + $this->url = $url; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/HTTPSecurityScheme.php b/tests/src/Tmp/OpenAPI3/HTTPSecurityScheme.php new file mode 100644 index 0000000..25f0803 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/HTTPSecurityScheme.php @@ -0,0 +1,147 @@ +scheme = Schema::string(); + $properties->bearerFormat = Schema::string(); + $properties->description = Schema::string(); + $properties->type = Schema::string(); + $properties->type->enum = array( + self::HTTP, + ); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->oneOf[0] = HTTPSecuritySchemeOneOf0::schema(); + $ownerSchema->oneOf[1] = HTTPSecuritySchemeOneOf1::schema(); + $ownerSchema->required = array( + self::names()->scheme, + self::names()->type, + ); + $ownerSchema->setFromRef('#/definitions/HTTPSecurityScheme'); + } + + /** + * @param string $scheme + * @return $this + * @codeCoverageIgnoreStart + */ + public function setScheme($scheme) + { + $this->scheme = $scheme; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $bearerFormat + * @return $this + * @codeCoverageIgnoreStart + */ + public function setBearerFormat($bearerFormat) + { + $this->bearerFormat = $bearerFormat; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $type + * @return $this + * @codeCoverageIgnoreStart + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/HTTPSecuritySchemeOneOf0.php b/tests/src/Tmp/OpenAPI3/HTTPSecuritySchemeOneOf0.php new file mode 100644 index 0000000..37ce19d --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/HTTPSecuritySchemeOneOf0.php @@ -0,0 +1,48 @@ +scheme = new Schema(); + $properties->scheme->enum = array( + self::BEARER, + ); + $ownerSchema->description = "Bearer"; + } + + /** + * @param mixed $scheme + * @return $this + * @codeCoverageIgnoreStart + */ + public function setScheme($scheme) + { + $this->scheme = $scheme; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/HTTPSecuritySchemeOneOf1.php b/tests/src/Tmp/OpenAPI3/HTTPSecuritySchemeOneOf1.php new file mode 100644 index 0000000..6f46e64 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/HTTPSecuritySchemeOneOf1.php @@ -0,0 +1,53 @@ +scheme = new Schema(); + $properties->scheme->not = new Schema(); + $properties->scheme->not->enum = array( + self::BEARER, + ); + $ownerSchema->not = new Schema(); + $ownerSchema->not->required = array( + self::names()->bearerFormat, + ); + $ownerSchema->description = "Non Bearer"; + } + + /** + * @param mixed $scheme + * @return $this + * @codeCoverageIgnoreStart + */ + public function setScheme($scheme) + { + $this->scheme = $scheme; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Header.php b/tests/src/Tmp/OpenAPI3/Header.php new file mode 100644 index 0000000..b1ce0f0 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Header.php @@ -0,0 +1,341 @@ +description = Schema::string(); + $properties->required = Schema::boolean(); + $properties->required->default = false; + $properties->deprecated = Schema::boolean(); + $properties->deprecated->default = false; + $properties->allowEmptyValue = Schema::boolean(); + $properties->allowEmptyValue->default = false; + $properties->style = Schema::string(); + $properties->style->enum = array( + self::SIMPLE, + ); + $properties->style->default = "simple"; + $properties->explode = Schema::boolean(); + $properties->allowReserved = Schema::boolean(); + $properties->allowReserved->default = false; + $properties->schema = new Schema(); + $properties->schema->oneOf[0] = DefinitionsSchema::schema(); + $propertiesSchemaOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesSchemaOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesSchemaOneOf1->required = array( + '$ref', + ); + $propertiesSchemaOneOf1->setFromRef('#/definitions/Reference'); + $properties->schema->oneOf[1] = $propertiesSchemaOneOf1; + $properties->content = Schema::object(); + $properties->content->additionalProperties = MediaType::schema(); + $properties->content->maxProperties = 1; + $properties->content->minProperties = 1; + $properties->example = new Schema(); + $properties->examples = Schema::object(); + $properties->examples->additionalProperties = new Schema(); + $properties->examples->additionalProperties->oneOf[0] = Example::schema(); + $propertiesExamplesAdditionalPropertiesOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesExamplesAdditionalPropertiesOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesExamplesAdditionalPropertiesOneOf1->required = array( + '$ref', + ); + $propertiesExamplesAdditionalPropertiesOneOf1->setFromRef('#/definitions/Reference'); + $properties->examples->additionalProperties->oneOf[1] = $propertiesExamplesAdditionalPropertiesOneOf1; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchemaAllOf0 = new Schema(); + $ownerSchemaAllOf0->not = new Schema(); + $ownerSchemaAllOf0->not->required = array( + self::names()->example, + self::names()->examples, + ); + $ownerSchemaAllOf0->description = "Example and examples are mutually exclusive"; + $ownerSchemaAllOf0->setFromRef('#/definitions/ExampleXORExamples'); + $ownerSchema->allOf[0] = $ownerSchemaAllOf0; + $ownerSchemaAllOf1 = new Schema(); + $ownerSchemaAllOf1->not = new Schema(); + $ownerSchemaAllOf1->not->required = array( + self::names()->schema, + self::names()->content, + ); + $ownerSchemaAllOf1OneOf0 = new Schema(); + $ownerSchemaAllOf1OneOf0->required = array( + self::names()->schema, + ); + $ownerSchemaAllOf1->oneOf[0] = $ownerSchemaAllOf1OneOf0; + $ownerSchemaAllOf1OneOf1 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf0 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf0->not = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf0->not->required = array( + self::names()->style, + ); + $ownerSchemaAllOf1OneOf1->allOf[0] = $ownerSchemaAllOf1OneOf1AllOf0; + $ownerSchemaAllOf1OneOf1AllOf1 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf1->not = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf1->not->required = array( + self::names()->explode, + ); + $ownerSchemaAllOf1OneOf1->allOf[1] = $ownerSchemaAllOf1OneOf1AllOf1; + $ownerSchemaAllOf1OneOf1AllOf2 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf2->not = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf2->not->required = array( + self::names()->allowReserved, + ); + $ownerSchemaAllOf1OneOf1->allOf[2] = $ownerSchemaAllOf1OneOf1AllOf2; + $ownerSchemaAllOf1OneOf1AllOf3 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf3->not = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf3->not->required = array( + self::names()->example, + ); + $ownerSchemaAllOf1OneOf1->allOf[3] = $ownerSchemaAllOf1OneOf1AllOf3; + $ownerSchemaAllOf1OneOf1AllOf4 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf4->not = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf4->not->required = array( + self::names()->examples, + ); + $ownerSchemaAllOf1OneOf1->allOf[4] = $ownerSchemaAllOf1OneOf1AllOf4; + $ownerSchemaAllOf1OneOf1->description = "Some properties are not allowed if content is present"; + $ownerSchemaAllOf1OneOf1->required = array( + self::names()->content, + ); + $ownerSchemaAllOf1->oneOf[1] = $ownerSchemaAllOf1OneOf1; + $ownerSchemaAllOf1->description = "Schema and content are mutually exclusive, at least one is required"; + $ownerSchemaAllOf1->setFromRef('#/definitions/SchemaXORContent'); + $ownerSchema->allOf[1] = $ownerSchemaAllOf1; + $ownerSchema->setFromRef('#/definitions/Header'); + } + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $required + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRequired($required) + { + $this->required = $required; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $deprecated + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDeprecated($deprecated) + { + $this->deprecated = $deprecated; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $allowEmptyValue + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAllowEmptyValue($allowEmptyValue) + { + $this->allowEmptyValue = $allowEmptyValue; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $style + * @return $this + * @codeCoverageIgnoreStart + */ + public function setStyle($style) + { + $this->style = $style; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $explode + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExplode($explode) + { + $this->explode = $explode; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $allowReserved + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAllowReserved($allowReserved) + { + $this->allowReserved = $allowReserved; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param DefinitionsSchema|string[] $schema + * @return $this + * @codeCoverageIgnoreStart + */ + public function setSchema($schema) + { + $this->schema = $schema; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param MediaType[]|mixed[] $content + * @return $this + * @codeCoverageIgnoreStart + */ + public function setContent($content) + { + $this->content = $content; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $example + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExample($example) + { + $this->example = $example; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Example[]|string[][] $examples + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExamples($examples) + { + $this->examples = $examples; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/ImplicitOAuthFlow.php b/tests/src/Tmp/OpenAPI3/ImplicitOAuthFlow.php new file mode 100644 index 0000000..4acea90 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/ImplicitOAuthFlow.php @@ -0,0 +1,125 @@ +authorizationUrl = Schema::string(); + $properties->authorizationUrl->format = "uri-reference"; + $properties->refreshUrl = Schema::string(); + $properties->refreshUrl->format = "uri-reference"; + $properties->scopes = Schema::object(); + $properties->scopes->additionalProperties = Schema::string(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->authorizationUrl, + self::names()->scopes, + ); + $ownerSchema->setFromRef('#/definitions/ImplicitOAuthFlow'); + } + + /** + * @param string $authorizationUrl + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAuthorizationUrl($authorizationUrl) + { + $this->authorizationUrl = $authorizationUrl; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $refreshUrl + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRefreshUrl($refreshUrl) + { + $this->refreshUrl = $refreshUrl; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[] $scopes + * @return $this + * @codeCoverageIgnoreStart + */ + public function setScopes($scopes) + { + $this->scopes = $scopes; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Info.php b/tests/src/Tmp/OpenAPI3/Info.php new file mode 100644 index 0000000..c0428d0 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Info.php @@ -0,0 +1,171 @@ +title = Schema::string(); + $properties->description = Schema::string(); + $properties->termsOfService = Schema::string(); + $properties->termsOfService->format = "uri-reference"; + $properties->contact = Contact::schema(); + $properties->license = License::schema(); + $properties->version = Schema::string(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->title, + self::names()->version, + ); + $ownerSchema->setFromRef('#/definitions/Info'); + } + + /** + * @param string $title + * @return $this + * @codeCoverageIgnoreStart + */ + public function setTitle($title) + { + $this->title = $title; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $termsOfService + * @return $this + * @codeCoverageIgnoreStart + */ + public function setTermsOfService($termsOfService) + { + $this->termsOfService = $termsOfService; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Contact $contact + * @return $this + * @codeCoverageIgnoreStart + */ + public function setContact(Contact $contact) + { + $this->contact = $contact; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param License $license + * @return $this + * @codeCoverageIgnoreStart + */ + public function setLicense(License $license) + { + $this->license = $license; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $version + * @return $this + * @codeCoverageIgnoreStart + */ + public function setVersion($version) + { + $this->version = $version; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/License.php b/tests/src/Tmp/OpenAPI3/License.php new file mode 100644 index 0000000..23a7fcb --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/License.php @@ -0,0 +1,106 @@ +name = Schema::string(); + $properties->url = Schema::string(); + $properties->url->format = "uri-reference"; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->name, + ); + $ownerSchema->setFromRef('#/definitions/License'); + } + + /** + * @param string $name + * @return $this + * @codeCoverageIgnoreStart + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $url + * @return $this + * @codeCoverageIgnoreStart + */ + public function setUrl($url) + { + $this->url = $url; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Link.php b/tests/src/Tmp/OpenAPI3/Link.php new file mode 100644 index 0000000..cd816df --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Link.php @@ -0,0 +1,173 @@ +operationId = Schema::string(); + $properties->operationRef = Schema::string(); + $properties->operationRef->format = "uri-reference"; + $properties->parameters = Schema::object(); + $properties->parameters->additionalProperties = new Schema(); + $properties->requestBody = new Schema(); + $properties->description = Schema::string(); + $properties->server = Server::schema(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->not = new Schema(); + $ownerSchema->not->description = "Operation Id and Operation Ref are mutually exclusive"; + $ownerSchema->not->required = array( + self::names()->operationId, + self::names()->operationRef, + ); + $ownerSchema->setFromRef('#/definitions/Link'); + } + + /** + * @param string $operationId + * @return $this + * @codeCoverageIgnoreStart + */ + public function setOperationId($operationId) + { + $this->operationId = $operationId; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $operationRef + * @return $this + * @codeCoverageIgnoreStart + */ + public function setOperationRef($operationRef) + { + $this->operationRef = $operationRef; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param $parameters + * @return $this + * @codeCoverageIgnoreStart + */ + public function setParameters($parameters) + { + $this->parameters = $parameters; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $requestBody + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRequestBody($requestBody) + { + $this->requestBody = $requestBody; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Server $server + * @return $this + * @codeCoverageIgnoreStart + */ + public function setServer(Server $server) + { + $this->server = $server; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/MediaType.php b/tests/src/Tmp/OpenAPI3/MediaType.php new file mode 100644 index 0000000..13b6be8 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/MediaType.php @@ -0,0 +1,167 @@ +schema = new Schema(); + $properties->schema->oneOf[0] = DefinitionsSchema::schema(); + $propertiesSchemaOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesSchemaOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesSchemaOneOf1->required = array( + '$ref', + ); + $propertiesSchemaOneOf1->setFromRef('#/definitions/Reference'); + $properties->schema->oneOf[1] = $propertiesSchemaOneOf1; + $properties->example = new Schema(); + $properties->examples = Schema::object(); + $properties->examples->additionalProperties = new Schema(); + $properties->examples->additionalProperties->oneOf[0] = Example::schema(); + $propertiesExamplesAdditionalPropertiesOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesExamplesAdditionalPropertiesOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesExamplesAdditionalPropertiesOneOf1->required = array( + '$ref', + ); + $propertiesExamplesAdditionalPropertiesOneOf1->setFromRef('#/definitions/Reference'); + $properties->examples->additionalProperties->oneOf[1] = $propertiesExamplesAdditionalPropertiesOneOf1; + $properties->encoding = Schema::object(); + $properties->encoding->additionalProperties = Encoding::schema(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchemaAllOf0 = new Schema(); + $ownerSchemaAllOf0->not = new Schema(); + $ownerSchemaAllOf0->not->required = array( + self::names()->example, + self::names()->examples, + ); + $ownerSchemaAllOf0->description = "Example and examples are mutually exclusive"; + $ownerSchemaAllOf0->setFromRef('#/definitions/ExampleXORExamples'); + $ownerSchema->allOf[0] = $ownerSchemaAllOf0; + $ownerSchema->setFromRef('#/definitions/MediaType'); + } + + /** + * @param DefinitionsSchema|string[] $schema + * @return $this + * @codeCoverageIgnoreStart + */ + public function setSchema($schema) + { + $this->schema = $schema; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $example + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExample($example) + { + $this->example = $example; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Example[]|string[][] $examples + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExamples($examples) + { + $this->examples = $examples; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Encoding[] $encoding + * @return $this + * @codeCoverageIgnoreStart + */ + public function setEncoding($encoding) + { + $this->encoding = $encoding; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/OAuth2SecurityScheme.php b/tests/src/Tmp/OpenAPI3/OAuth2SecurityScheme.php new file mode 100644 index 0000000..2ce580f --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/OAuth2SecurityScheme.php @@ -0,0 +1,127 @@ +type = Schema::string(); + $properties->type->enum = array( + self::OAUTH2, + ); + $properties->flows = OAuthFlows::schema(); + $properties->description = Schema::string(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->type, + self::names()->flows, + ); + $ownerSchema->setFromRef('#/definitions/OAuth2SecurityScheme'); + } + + /** + * @param string $type + * @return $this + * @codeCoverageIgnoreStart + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param OAuthFlows $flows + * @return $this + * @codeCoverageIgnoreStart + */ + public function setFlows(OAuthFlows $flows) + { + $this->flows = $flows; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/OAuthFlows.php b/tests/src/Tmp/OpenAPI3/OAuthFlows.php new file mode 100644 index 0000000..07bbc27 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/OAuthFlows.php @@ -0,0 +1,134 @@ +implicit = ImplicitOAuthFlow::schema(); + $properties->password = PasswordOAuthFlow::schema(); + $properties->clientCredentials = ClientCredentialsFlow::schema(); + $properties->authorizationCode = AuthorizationCodeOAuthFlow::schema(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->setFromRef('#/definitions/OAuthFlows'); + } + + /** + * @param ImplicitOAuthFlow $implicit + * @return $this + * @codeCoverageIgnoreStart + */ + public function setImplicit(ImplicitOAuthFlow $implicit) + { + $this->implicit = $implicit; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param PasswordOAuthFlow $password + * @return $this + * @codeCoverageIgnoreStart + */ + public function setPassword(PasswordOAuthFlow $password) + { + $this->password = $password; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param ClientCredentialsFlow $clientCredentials + * @return $this + * @codeCoverageIgnoreStart + */ + public function setClientCredentials(ClientCredentialsFlow $clientCredentials) + { + $this->clientCredentials = $clientCredentials; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param AuthorizationCodeOAuthFlow $authorizationCode + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAuthorizationCode(AuthorizationCodeOAuthFlow $authorizationCode) + { + $this->authorizationCode = $authorizationCode; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/OpenAPI3Schema.php b/tests/src/Tmp/OpenAPI3/OpenAPI3Schema.php new file mode 100644 index 0000000..610275c --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/OpenAPI3Schema.php @@ -0,0 +1,219 @@ +openapi = Schema::string(); + $properties->openapi->pattern = "^3\\.0\\.\\d(-.+)?$"; + $properties->info = Info::schema(); + $properties->externalDocs = ExternalDocumentation::schema(); + $properties->servers = Schema::arr(); + $properties->servers->items = Server::schema(); + $properties->security = Schema::arr(); + $properties->security->items = Schema::object(); + $properties->security->items->additionalProperties = Schema::arr(); + $properties->security->items->additionalProperties->items = Schema::string(); + $properties->security->items->setFromRef('#/definitions/SecurityRequirement'); + $properties->tags = Schema::arr(); + $properties->tags->items = Tag::schema(); + $properties->tags->uniqueItems = true; + $properties->paths = Schema::object(); + $properties->paths->additionalProperties = false; + $patternProperty = PathItem::schema(); + $properties->paths->setPatternProperty('^\\/', $patternProperty); + $patternProperty = new Schema(); + $properties->paths->setPatternProperty('^x-', $patternProperty); + $properties->paths->setFromRef('#/definitions/Paths'); + $properties->components = Components::schema(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->id = "https://spec.openapis.org/oas/3.0/schema/2019-04-02"; + $ownerSchema->schema = "http://json-schema.org/draft-04/schema#"; + $ownerSchema->description = "Validation schema for OpenAPI Specification 3.0.X."; + $ownerSchema->required = array( + self::names()->openapi, + self::names()->info, + self::names()->paths, + ); + } + + /** + * @param string $openapi + * @return $this + * @codeCoverageIgnoreStart + */ + public function setOpenapi($openapi) + { + $this->openapi = $openapi; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Info $info + * @return $this + * @codeCoverageIgnoreStart + */ + public function setInfo(Info $info) + { + $this->info = $info; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param ExternalDocumentation $externalDocs + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExternalDocs(ExternalDocumentation $externalDocs) + { + $this->externalDocs = $externalDocs; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Server[]|array $servers + * @return $this + * @codeCoverageIgnoreStart + */ + public function setServers($servers) + { + $this->servers = $servers; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[][]|array[][]|array $security + * @return $this + * @codeCoverageIgnoreStart + */ + public function setSecurity($security) + { + $this->security = $security; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Tag[]|array $tags + * @return $this + * @codeCoverageIgnoreStart + */ + public function setTags($tags) + { + $this->tags = $tags; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param PathItem[]|Operation[][] $paths + * @return $this + * @codeCoverageIgnoreStart + */ + public function setPaths($paths) + { + $this->paths = $paths; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Components $components + * @return $this + * @codeCoverageIgnoreStart + */ + public function setComponents(Components $components) + { + $this->components = $components; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/OpenIdConnectSecurityScheme.php b/tests/src/Tmp/OpenAPI3/OpenIdConnectSecurityScheme.php new file mode 100644 index 0000000..6decf3b --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/OpenIdConnectSecurityScheme.php @@ -0,0 +1,128 @@ +type = Schema::string(); + $properties->type->enum = array( + self::OPEN_ID_CONNECT, + ); + $properties->openIdConnectUrl = Schema::string(); + $properties->openIdConnectUrl->format = "uri-reference"; + $properties->description = Schema::string(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->type, + self::names()->openIdConnectUrl, + ); + $ownerSchema->setFromRef('#/definitions/OpenIdConnectSecurityScheme'); + } + + /** + * @param string $type + * @return $this + * @codeCoverageIgnoreStart + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $openIdConnectUrl + * @return $this + * @codeCoverageIgnoreStart + */ + public function setOpenIdConnectUrl($openIdConnectUrl) + { + $this->openIdConnectUrl = $openIdConnectUrl; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Operation.php b/tests/src/Tmp/OpenAPI3/Operation.php new file mode 100644 index 0000000..2266871 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Operation.php @@ -0,0 +1,310 @@ +tags = Schema::arr(); + $properties->tags->items = Schema::string(); + $properties->summary = Schema::string(); + $properties->description = Schema::string(); + $properties->externalDocs = ExternalDocumentation::schema(); + $properties->operationId = Schema::string(); + $properties->parameters = Schema::arr(); + $properties->parameters->items = new Schema(); + $properties->parameters->items->oneOf[0] = Parameter::schema(); + $propertiesParametersItemsOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesParametersItemsOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesParametersItemsOneOf1->required = array( + '$ref', + ); + $propertiesParametersItemsOneOf1->setFromRef('#/definitions/Reference'); + $properties->parameters->items->oneOf[1] = $propertiesParametersItemsOneOf1; + $properties->parameters->uniqueItems = true; + $properties->requestBody = new Schema(); + $properties->requestBody->oneOf[0] = RequestBody::schema(); + $propertiesRequestBodyOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesRequestBodyOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesRequestBodyOneOf1->required = array( + '$ref', + ); + $propertiesRequestBodyOneOf1->setFromRef('#/definitions/Reference'); + $properties->requestBody->oneOf[1] = $propertiesRequestBodyOneOf1; + $properties->responses = Responses::schema(); + $properties->callbacks = Schema::object(); + $properties->callbacks->additionalProperties = new Schema(); + $propertiesCallbacksAdditionalPropertiesOneOf0 = Schema::object(); + $propertiesCallbacksAdditionalPropertiesOneOf0->additionalProperties = PathItem::schema(); + $patternProperty = new Schema(); + $propertiesCallbacksAdditionalPropertiesOneOf0->setPatternProperty('^x-', $patternProperty); + $propertiesCallbacksAdditionalPropertiesOneOf0->setFromRef('#/definitions/Callback'); + $properties->callbacks->additionalProperties->oneOf[0] = $propertiesCallbacksAdditionalPropertiesOneOf0; + $propertiesCallbacksAdditionalPropertiesOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesCallbacksAdditionalPropertiesOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesCallbacksAdditionalPropertiesOneOf1->required = array( + '$ref', + ); + $propertiesCallbacksAdditionalPropertiesOneOf1->setFromRef('#/definitions/Reference'); + $properties->callbacks->additionalProperties->oneOf[1] = $propertiesCallbacksAdditionalPropertiesOneOf1; + $properties->deprecated = Schema::boolean(); + $properties->deprecated->default = false; + $properties->security = Schema::arr(); + $properties->security->items = Schema::object(); + $properties->security->items->additionalProperties = Schema::arr(); + $properties->security->items->additionalProperties->items = Schema::string(); + $properties->security->items->setFromRef('#/definitions/SecurityRequirement'); + $properties->servers = Schema::arr(); + $properties->servers->items = Server::schema(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->responses, + ); + $ownerSchema->setFromRef('#/definitions/Operation'); + } + + /** + * @param string[]|array $tags + * @return $this + * @codeCoverageIgnoreStart + */ + public function setTags($tags) + { + $this->tags = $tags; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $summary + * @return $this + * @codeCoverageIgnoreStart + */ + public function setSummary($summary) + { + $this->summary = $summary; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param ExternalDocumentation $externalDocs + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExternalDocs(ExternalDocumentation $externalDocs) + { + $this->externalDocs = $externalDocs; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $operationId + * @return $this + * @codeCoverageIgnoreStart + */ + public function setOperationId($operationId) + { + $this->operationId = $operationId; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Parameter[]|mixed[]|ParameterLocationOneOf0[]|ParameterLocationOneOf1[]|ParameterLocationOneOf2[]|ParameterLocationOneOf3[]|string[][]|array $parameters + * @return $this + * @codeCoverageIgnoreStart + */ + public function setParameters($parameters) + { + $this->parameters = $parameters; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param RequestBody|string[] $requestBody + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRequestBody($requestBody) + { + $this->requestBody = $requestBody; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Responses|Response[]|string[][] $responses + * @return $this + * @codeCoverageIgnoreStart + */ + public function setResponses($responses) + { + $this->responses = $responses; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param PathItem[]|Operation[][][]|string[][] $callbacks + * @return $this + * @codeCoverageIgnoreStart + */ + public function setCallbacks($callbacks) + { + $this->callbacks = $callbacks; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $deprecated + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDeprecated($deprecated) + { + $this->deprecated = $deprecated; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[][]|array[][]|array $security + * @return $this + * @codeCoverageIgnoreStart + */ + public function setSecurity($security) + { + $this->security = $security; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Server[]|array $servers + * @return $this + * @codeCoverageIgnoreStart + */ + public function setServers($servers) + { + $this->servers = $servers; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Parameter.php b/tests/src/Tmp/OpenAPI3/Parameter.php new file mode 100644 index 0000000..c74c39f --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Parameter.php @@ -0,0 +1,379 @@ +name = Schema::string(); + $properties->in = Schema::string(); + $properties->description = Schema::string(); + $properties->required = Schema::boolean(); + $properties->required->default = false; + $properties->deprecated = Schema::boolean(); + $properties->deprecated->default = false; + $properties->allowEmptyValue = Schema::boolean(); + $properties->allowEmptyValue->default = false; + $properties->style = Schema::string(); + $properties->explode = Schema::boolean(); + $properties->allowReserved = Schema::boolean(); + $properties->allowReserved->default = false; + $properties->schema = new Schema(); + $properties->schema->oneOf[0] = DefinitionsSchema::schema(); + $propertiesSchemaOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesSchemaOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesSchemaOneOf1->required = array( + '$ref', + ); + $propertiesSchemaOneOf1->setFromRef('#/definitions/Reference'); + $properties->schema->oneOf[1] = $propertiesSchemaOneOf1; + $properties->content = Schema::object(); + $properties->content->additionalProperties = MediaType::schema(); + $properties->content->maxProperties = 1; + $properties->content->minProperties = 1; + $properties->example = new Schema(); + $properties->examples = Schema::object(); + $properties->examples->additionalProperties = new Schema(); + $properties->examples->additionalProperties->oneOf[0] = Example::schema(); + $propertiesExamplesAdditionalPropertiesOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesExamplesAdditionalPropertiesOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesExamplesAdditionalPropertiesOneOf1->required = array( + '$ref', + ); + $propertiesExamplesAdditionalPropertiesOneOf1->setFromRef('#/definitions/Reference'); + $properties->examples->additionalProperties->oneOf[1] = $propertiesExamplesAdditionalPropertiesOneOf1; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchemaAllOf0 = new Schema(); + $ownerSchemaAllOf0->not = new Schema(); + $ownerSchemaAllOf0->not->required = array( + self::names()->example, + self::names()->examples, + ); + $ownerSchemaAllOf0->description = "Example and examples are mutually exclusive"; + $ownerSchemaAllOf0->setFromRef('#/definitions/ExampleXORExamples'); + $ownerSchema->allOf[0] = $ownerSchemaAllOf0; + $ownerSchemaAllOf1 = new Schema(); + $ownerSchemaAllOf1->not = new Schema(); + $ownerSchemaAllOf1->not->required = array( + self::names()->schema, + self::names()->content, + ); + $ownerSchemaAllOf1OneOf0 = new Schema(); + $ownerSchemaAllOf1OneOf0->required = array( + self::names()->schema, + ); + $ownerSchemaAllOf1->oneOf[0] = $ownerSchemaAllOf1OneOf0; + $ownerSchemaAllOf1OneOf1 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf0 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf0->not = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf0->not->required = array( + self::names()->style, + ); + $ownerSchemaAllOf1OneOf1->allOf[0] = $ownerSchemaAllOf1OneOf1AllOf0; + $ownerSchemaAllOf1OneOf1AllOf1 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf1->not = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf1->not->required = array( + self::names()->explode, + ); + $ownerSchemaAllOf1OneOf1->allOf[1] = $ownerSchemaAllOf1OneOf1AllOf1; + $ownerSchemaAllOf1OneOf1AllOf2 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf2->not = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf2->not->required = array( + self::names()->allowReserved, + ); + $ownerSchemaAllOf1OneOf1->allOf[2] = $ownerSchemaAllOf1OneOf1AllOf2; + $ownerSchemaAllOf1OneOf1AllOf3 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf3->not = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf3->not->required = array( + self::names()->example, + ); + $ownerSchemaAllOf1OneOf1->allOf[3] = $ownerSchemaAllOf1OneOf1AllOf3; + $ownerSchemaAllOf1OneOf1AllOf4 = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf4->not = new Schema(); + $ownerSchemaAllOf1OneOf1AllOf4->not->required = array( + self::names()->examples, + ); + $ownerSchemaAllOf1OneOf1->allOf[4] = $ownerSchemaAllOf1OneOf1AllOf4; + $ownerSchemaAllOf1OneOf1->description = "Some properties are not allowed if content is present"; + $ownerSchemaAllOf1OneOf1->required = array( + self::names()->content, + ); + $ownerSchemaAllOf1->oneOf[1] = $ownerSchemaAllOf1OneOf1; + $ownerSchemaAllOf1->description = "Schema and content are mutually exclusive, at least one is required"; + $ownerSchemaAllOf1->setFromRef('#/definitions/SchemaXORContent'); + $ownerSchema->allOf[1] = $ownerSchemaAllOf1; + $ownerSchemaAllOf2 = new Schema(); + $ownerSchemaAllOf2->oneOf[0] = ParameterLocationOneOf0::schema(); + $ownerSchemaAllOf2->oneOf[1] = ParameterLocationOneOf1::schema(); + $ownerSchemaAllOf2->oneOf[2] = ParameterLocationOneOf2::schema(); + $ownerSchemaAllOf2->oneOf[3] = ParameterLocationOneOf3::schema(); + $ownerSchemaAllOf2->description = "Parameter location"; + $ownerSchemaAllOf2->setFromRef('#/definitions/ParameterLocation'); + $ownerSchema->allOf[2] = $ownerSchemaAllOf2; + $ownerSchema->required = array( + self::names()->name, + self::names()->in, + ); + $ownerSchema->setFromRef('#/definitions/Parameter'); + } + + /** + * @param string $name + * @return $this + * @codeCoverageIgnoreStart + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $in + * @return $this + * @codeCoverageIgnoreStart + */ + public function setIn($in) + { + $this->in = $in; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $required + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRequired($required) + { + $this->required = $required; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $deprecated + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDeprecated($deprecated) + { + $this->deprecated = $deprecated; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $allowEmptyValue + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAllowEmptyValue($allowEmptyValue) + { + $this->allowEmptyValue = $allowEmptyValue; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $style + * @return $this + * @codeCoverageIgnoreStart + */ + public function setStyle($style) + { + $this->style = $style; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $explode + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExplode($explode) + { + $this->explode = $explode; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $allowReserved + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAllowReserved($allowReserved) + { + $this->allowReserved = $allowReserved; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param DefinitionsSchema|string[] $schema + * @return $this + * @codeCoverageIgnoreStart + */ + public function setSchema($schema) + { + $this->schema = $schema; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param MediaType[]|mixed[] $content + * @return $this + * @codeCoverageIgnoreStart + */ + public function setContent($content) + { + $this->content = $content; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $example + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExample($example) + { + $this->example = $example; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Example[]|string[][] $examples + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExamples($examples) + { + $this->examples = $examples; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf0.php b/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf0.php new file mode 100644 index 0000000..c73f2a4 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf0.php @@ -0,0 +1,98 @@ +in = new Schema(); + $properties->in->enum = array( + self::PATH, + ); + $properties->style = new Schema(); + $properties->style->enum = array( + self::MATRIX, + self::LABEL, + self::SIMPLE, + ); + $properties->style->default = "simple"; + $properties->required = new Schema(); + $properties->required->enum = array( + true, + ); + $ownerSchema->description = "Parameter in path"; + $ownerSchema->required = array( + self::names()->required, + ); + } + + /** + * @param mixed $in + * @return $this + * @codeCoverageIgnoreStart + */ + public function setIn($in) + { + $this->in = $in; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $style + * @return $this + * @codeCoverageIgnoreStart + */ + public function setStyle($style) + { + $this->style = $style; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $required + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRequired($required) + { + $this->required = $required; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf1.php b/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf1.php new file mode 100644 index 0000000..9547fd9 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf1.php @@ -0,0 +1,79 @@ +in = new Schema(); + $properties->in->enum = array( + self::QUERY, + ); + $properties->style = new Schema(); + $properties->style->enum = array( + self::FORM, + self::SPACE_DELIMITED, + self::PIPE_DELIMITED, + self::DEEP_OBJECT, + ); + $properties->style->default = "form"; + $ownerSchema->description = "Parameter in query"; + } + + /** + * @param mixed $in + * @return $this + * @codeCoverageIgnoreStart + */ + public function setIn($in) + { + $this->in = $in; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $style + * @return $this + * @codeCoverageIgnoreStart + */ + public function setStyle($style) + { + $this->style = $style; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf2.php b/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf2.php new file mode 100644 index 0000000..ed54fa8 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf2.php @@ -0,0 +1,70 @@ +in = new Schema(); + $properties->in->enum = array( + self::HEADER, + ); + $properties->style = new Schema(); + $properties->style->enum = array( + self::SIMPLE, + ); + $properties->style->default = "simple"; + $ownerSchema->description = "Parameter in header"; + } + + /** + * @param mixed $in + * @return $this + * @codeCoverageIgnoreStart + */ + public function setIn($in) + { + $this->in = $in; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $style + * @return $this + * @codeCoverageIgnoreStart + */ + public function setStyle($style) + { + $this->style = $style; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf3.php b/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf3.php new file mode 100644 index 0000000..74402e6 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/ParameterLocationOneOf3.php @@ -0,0 +1,70 @@ +in = new Schema(); + $properties->in->enum = array( + self::COOKIE, + ); + $properties->style = new Schema(); + $properties->style->enum = array( + self::FORM, + ); + $properties->style->default = "form"; + $ownerSchema->description = "Parameter in cookie"; + } + + /** + * @param mixed $in + * @return $this + * @codeCoverageIgnoreStart + */ + public function setIn($in) + { + $this->in = $in; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param mixed $style + * @return $this + * @codeCoverageIgnoreStart + */ + public function setStyle($style) + { + $this->style = $style; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/PasswordOAuthFlow.php b/tests/src/Tmp/OpenAPI3/PasswordOAuthFlow.php new file mode 100644 index 0000000..817bf27 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/PasswordOAuthFlow.php @@ -0,0 +1,124 @@ +tokenUrl = Schema::string(); + $properties->tokenUrl->format = "uri-reference"; + $properties->refreshUrl = Schema::string(); + $properties->refreshUrl->format = "uri-reference"; + $properties->scopes = Schema::object(); + $properties->scopes->additionalProperties = Schema::string(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->tokenUrl, + ); + $ownerSchema->setFromRef('#/definitions/PasswordOAuthFlow'); + } + + /** + * @param string $tokenUrl + * @return $this + * @codeCoverageIgnoreStart + */ + public function setTokenUrl($tokenUrl) + { + $this->tokenUrl = $tokenUrl; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $refreshUrl + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRefreshUrl($refreshUrl) + { + $this->refreshUrl = $refreshUrl; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string[] $scopes + * @return $this + * @codeCoverageIgnoreStart + */ + public function setScopes($scopes) + { + $this->scopes = $scopes; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/PathItem.php b/tests/src/Tmp/OpenAPI3/PathItem.php new file mode 100644 index 0000000..4f1fb02 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/PathItem.php @@ -0,0 +1,169 @@ +ref = Schema::string(); + $ownerSchema->addPropertyMapping('$ref', self::names()->ref); + $properties->summary = Schema::string(); + $properties->description = Schema::string(); + $properties->servers = Schema::arr(); + $properties->servers->items = Server::schema(); + $properties->parameters = Schema::arr(); + $properties->parameters->items = new Schema(); + $properties->parameters->items->oneOf[0] = Parameter::schema(); + $propertiesParametersItemsOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesParametersItemsOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesParametersItemsOneOf1->required = array( + '$ref', + ); + $propertiesParametersItemsOneOf1->setFromRef('#/definitions/Reference'); + $properties->parameters->items->oneOf[1] = $propertiesParametersItemsOneOf1; + $properties->parameters->uniqueItems = true; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = Operation::schema(); + $ownerSchema->setPatternProperty('^(get|put|post|delete|options|head|patch|trace)$', $patternProperty); + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->setFromRef('#/definitions/PathItem'); + } + + /** + * @param string $ref + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRef($ref) + { + $this->ref = $ref; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $summary + * @return $this + * @codeCoverageIgnoreStart + */ + public function setSummary($summary) + { + $this->summary = $summary; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Server[]|array $servers + * @return $this + * @codeCoverageIgnoreStart + */ + public function setServers($servers) + { + $this->servers = $servers; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Parameter[]|mixed[]|ParameterLocationOneOf0[]|ParameterLocationOneOf1[]|ParameterLocationOneOf2[]|ParameterLocationOneOf3[]|string[][]|array $parameters + * @return $this + * @codeCoverageIgnoreStart + */ + public function setParameters($parameters) + { + $this->parameters = $parameters; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @return Operation[] + * @codeCoverageIgnoreStart + */ + public function getGetPutPostDeleteOptionsHeadPatchTraceValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::GET_PUT_POST_DELETE_OPTIONS_HEAD_PATCH_TRACE_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param Operation $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setGetPutPostDeleteOptionsHeadPatchTraceValue($name, Operation $value) + { + if (preg_match(Helper::toPregPattern(self::GET_PUT_POST_DELETE_OPTIONS_HEAD_PATCH_TRACE_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::GET_PUT_POST_DELETE_OPTIONS_HEAD_PATCH_TRACE_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/RequestBody.php b/tests/src/Tmp/OpenAPI3/RequestBody.php new file mode 100644 index 0000000..a37674d --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/RequestBody.php @@ -0,0 +1,123 @@ +description = Schema::string(); + $properties->content = Schema::object(); + $properties->content->additionalProperties = MediaType::schema(); + $properties->required = Schema::boolean(); + $properties->required->default = false; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->content, + ); + $ownerSchema->setFromRef('#/definitions/RequestBody'); + } + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param MediaType[]|mixed[] $content + * @return $this + * @codeCoverageIgnoreStart + */ + public function setContent($content) + { + $this->content = $content; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $required + * @return $this + * @codeCoverageIgnoreStart + */ + public function setRequired($required) + { + $this->required = $required; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Response.php b/tests/src/Tmp/OpenAPI3/Response.php new file mode 100644 index 0000000..3efbe3b --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Response.php @@ -0,0 +1,160 @@ +description = Schema::string(); + $properties->headers = Schema::object(); + $properties->headers->additionalProperties = new Schema(); + $properties->headers->additionalProperties->oneOf[0] = Header::schema(); + $propertiesHeadersAdditionalPropertiesOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesHeadersAdditionalPropertiesOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesHeadersAdditionalPropertiesOneOf1->required = array( + '$ref', + ); + $propertiesHeadersAdditionalPropertiesOneOf1->setFromRef('#/definitions/Reference'); + $properties->headers->additionalProperties->oneOf[1] = $propertiesHeadersAdditionalPropertiesOneOf1; + $properties->content = Schema::object(); + $properties->content->additionalProperties = MediaType::schema(); + $properties->links = Schema::object(); + $properties->links->additionalProperties = new Schema(); + $properties->links->additionalProperties->oneOf[0] = Link::schema(); + $propertiesLinksAdditionalPropertiesOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesLinksAdditionalPropertiesOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesLinksAdditionalPropertiesOneOf1->required = array( + '$ref', + ); + $propertiesLinksAdditionalPropertiesOneOf1->setFromRef('#/definitions/Reference'); + $properties->links->additionalProperties->oneOf[1] = $propertiesLinksAdditionalPropertiesOneOf1; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->description, + ); + $ownerSchema->setFromRef('#/definitions/Response'); + } + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Header[]|mixed[]|string[][] $headers + * @return $this + * @codeCoverageIgnoreStart + */ + public function setHeaders($headers) + { + $this->headers = $headers; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param MediaType[]|mixed[] $content + * @return $this + * @codeCoverageIgnoreStart + */ + public function setContent($content) + { + $this->content = $content; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param Link[]|string[][] $links + * @return $this + * @codeCoverageIgnoreStart + */ + public function setLinks($links) + { + $this->links = $links; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Responses.php b/tests/src/Tmp/OpenAPI3/Responses.php new file mode 100644 index 0000000..6db5ac1 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Responses.php @@ -0,0 +1,148 @@ +default = new Schema(); + $properties->default->oneOf[0] = Response::schema(); + $propertiesDefaultOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $propertiesDefaultOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $propertiesDefaultOneOf1->required = array( + '$ref', + ); + $propertiesDefaultOneOf1->setFromRef('#/definitions/Reference'); + $properties->default->oneOf[1] = $propertiesDefaultOneOf1; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $patternProperty->oneOf[0] = Response::schema(); + $patternPropertyOneOf1 = Schema::object(); + $patternProperty = Schema::string(); + $patternProperty->format = "uri-reference"; + $patternPropertyOneOf1->setPatternProperty('^\\$ref$', $patternProperty); + $patternPropertyOneOf1->required = array( + '$ref', + ); + $patternPropertyOneOf1->setFromRef('#/definitions/Reference'); + $patternProperty->oneOf[1] = $patternPropertyOneOf1; + $ownerSchema->setPatternProperty('^[1-5](?:\\d{2}|XX)$', $patternProperty); + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->minProperties = 1; + $ownerSchema->setFromRef('#/definitions/Responses'); + } + + /** + * @param Response|string[] $default + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDefault($default) + { + $this->default = $default; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @return Response[]|string[][] + * @codeCoverageIgnoreStart + */ + public function getproperty15D2XXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::CONST_1_5_D_2_XX_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param Response|string[] $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setproperty15D2XXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::CONST_1_5_D_2_XX_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::CONST_1_5_D_2_XX_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Server.php b/tests/src/Tmp/OpenAPI3/Server.php new file mode 100644 index 0000000..39783ec --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Server.php @@ -0,0 +1,122 @@ +url = Schema::string(); + $properties->description = Schema::string(); + $properties->variables = Schema::object(); + $properties->variables->additionalProperties = ServerVariable::schema(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->url, + ); + $ownerSchema->setFromRef('#/definitions/Server'); + } + + /** + * @param string $url + * @return $this + * @codeCoverageIgnoreStart + */ + public function setUrl($url) + { + $this->url = $url; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param ServerVariable[] $variables + * @return $this + * @codeCoverageIgnoreStart + */ + public function setVariables($variables) + { + $this->variables = $variables; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/ServerVariable.php b/tests/src/Tmp/OpenAPI3/ServerVariable.php new file mode 100644 index 0000000..bfa5983 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/ServerVariable.php @@ -0,0 +1,122 @@ +enum = Schema::arr(); + $properties->enum->items = Schema::string(); + $properties->default = Schema::string(); + $properties->description = Schema::string(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->default, + ); + $ownerSchema->setFromRef('#/definitions/ServerVariable'); + } + + /** + * @param string[]|array $enum + * @return $this + * @codeCoverageIgnoreStart + */ + public function setEnum($enum) + { + $this->enum = $enum; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $default + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDefault($default) + { + $this->default = $default; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/Tag.php b/tests/src/Tmp/OpenAPI3/Tag.php new file mode 100644 index 0000000..5d5fd25 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/Tag.php @@ -0,0 +1,121 @@ +name = Schema::string(); + $properties->description = Schema::string(); + $properties->externalDocs = ExternalDocumentation::schema(); + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->required = array( + self::names()->name, + ); + $ownerSchema->setFromRef('#/definitions/Tag'); + } + + /** + * @param string $name + * @return $this + * @codeCoverageIgnoreStart + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $description + * @return $this + * @codeCoverageIgnoreStart + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param ExternalDocumentation $externalDocs + * @return $this + * @codeCoverageIgnoreStart + */ + public function setExternalDocs(ExternalDocumentation $externalDocs) + { + $this->externalDocs = $externalDocs; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file diff --git a/tests/src/Tmp/OpenAPI3/XML.php b/tests/src/Tmp/OpenAPI3/XML.php new file mode 100644 index 0000000..b4bea95 --- /dev/null +++ b/tests/src/Tmp/OpenAPI3/XML.php @@ -0,0 +1,153 @@ +name = Schema::string(); + $properties->namespace = Schema::string(); + $properties->namespace->format = "uri"; + $properties->prefix = Schema::string(); + $properties->attribute = Schema::boolean(); + $properties->attribute->default = false; + $properties->wrapped = Schema::boolean(); + $properties->wrapped->default = false; + $ownerSchema->type = 'object'; + $ownerSchema->additionalProperties = false; + $patternProperty = new Schema(); + $ownerSchema->setPatternProperty('^x-', $patternProperty); + $ownerSchema->setFromRef('#/definitions/XML'); + } + + /** + * @param string $name + * @return $this + * @codeCoverageIgnoreStart + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $namespace + * @return $this + * @codeCoverageIgnoreStart + */ + public function setNamespace($namespace) + { + $this->namespace = $namespace; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $prefix + * @return $this + * @codeCoverageIgnoreStart + */ + public function setPrefix($prefix) + { + $this->prefix = $prefix; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $attribute + * @return $this + * @codeCoverageIgnoreStart + */ + public function setAttribute($attribute) + { + $this->attribute = $attribute; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param bool $wrapped + * @return $this + * @codeCoverageIgnoreStart + */ + public function setWrapped($wrapped) + { + $this->wrapped = $wrapped; + return $this; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @codeCoverageIgnoreStart + */ + public function getXValues() + { + $result = array(); + if (!$names = $this->getPatternPropertyNames(self::X_PROPERTY_PATTERN)) { + return $result; + } + foreach ($names as $name) { + $result[$name] = $this->$name; + } + return $result; + } + /** @codeCoverageIgnoreEnd */ + + /** + * @param string $name + * @param mixed $value + * @return self + * @throws InvalidValue + * @codeCoverageIgnoreStart + */ + public function setXValue($name, $value) + { + if (preg_match(Helper::toPregPattern(self::X_PROPERTY_PATTERN), $name)) { + throw new StringException('Pattern mismatch', StringException::PATTERN_MISMATCH); + } + $this->addPatternPropertyName(self::X_PROPERTY_PATTERN, $name); + $this->{$name} = $value; + return $this; + } + /** @codeCoverageIgnoreEnd */ +} \ No newline at end of file