├── .jane ├── Generator ├── ClientGenerator.php ├── RequestBodyContentGeneratorInterface.php ├── RequestBodyContent │ ├── DefaultBodyContentGenerator.php │ ├── JsonBodyContentGenerator.php │ └── FormBodyContentGenerator.php ├── Endpoint │ ├── GetGetBodyTrait.php │ ├── GetGetQueryAllowReservedTrait.php │ ├── GetGetExtraHeadersTrait.php │ ├── GetResponseContentTrait.php │ ├── GetGetOptionsResolverTrait.php │ └── GetGetUriTrait.php ├── Client │ └── ServerPluginGenerator.php ├── GeneratorFactory.php └── RequestBodyGenerator.php ├── JsonSchema ├── Runtime │ └── Normalizer │ │ ├── CheckArray.php │ │ ├── ValidatorTrait.php │ │ ├── ValidationException.php │ │ └── ReferenceNormalizer.php ├── Model │ ├── HTTPSecuritySchemeSub.php │ ├── Reference.php │ ├── Responses.php │ ├── License.php │ ├── ExternalDocumentation.php │ ├── Discriminator.php │ ├── Contact.php │ ├── ServerVariable.php │ ├── OAuth2SecurityScheme.php │ ├── Server.php │ ├── PasswordOAuthFlow.php │ ├── ClientCredentialsFlow.php │ ├── RequestBody.php │ ├── Tag.php │ ├── OpenIdConnectSecurityScheme.php │ ├── ImplicitOAuthFlow.php │ ├── APIKeySecurityScheme.php │ ├── Example.php │ ├── HTTPSecurityScheme.php │ ├── MediaType.php │ ├── AuthorizationCodeOAuthFlow.php │ ├── Response.php │ ├── OAuthFlows.php │ ├── XML.php │ ├── Encoding.php │ ├── Info.php │ ├── Link.php │ └── OpenApi.php └── Normalizer │ ├── ReferenceNormalizer.php │ ├── HTTPSecuritySchemeSubNormalizer.php │ ├── LicenseNormalizer.php │ ├── DiscriminatorNormalizer.php │ ├── ExternalDocumentationNormalizer.php │ ├── ContactNormalizer.php │ ├── OpenIdConnectSecuritySchemeNormalizer.php │ ├── OAuth2SecuritySchemeNormalizer.php │ ├── TagNormalizer.php │ ├── APIKeySecuritySchemeNormalizer.php │ ├── ServerVariableNormalizer.php │ ├── ImplicitOAuthFlowNormalizer.php │ ├── PasswordOAuthFlowNormalizer.php │ ├── ClientCredentialsFlowNormalizer.php │ ├── HTTPSecuritySchemeNormalizer.php │ ├── ServerNormalizer.php │ ├── RequestBodyNormalizer.php │ ├── ExampleNormalizer.php │ ├── AuthorizationCodeOAuthFlowNormalizer.php │ ├── XMLNormalizer.php │ ├── EncodingNormalizer.php │ └── ResponsesNormalizer.php ├── .github └── workflows │ └── read-only.yml ├── Guesser ├── GuessClass.php └── OpenApiSchema │ ├── SecurityGuesser.php │ ├── GuesserFactory.php │ ├── SchemaGuesser.php │ └── AnyOfReferencefGuesser.php ├── SchemaParser └── SchemaParser.php ├── README.md ├── LICENSE ├── composer.json └── JaneOpenApi.php /.jane: -------------------------------------------------------------------------------- 1 | __DIR__ . '/version3.json', 5 | 'root-class' => 'OpenApi', 6 | 'namespace' => 'Jane\Component\OpenApi3\JsonSchema', 7 | 'directory' => __DIR__ . DIRECTORY_SEPARATOR . 'JsonSchema', 8 | 'reference' => true, 9 | 'use-fixer' => true, 10 | 'strict' => false, 11 | ]; 12 | -------------------------------------------------------------------------------- /Generator/ClientGenerator.php: -------------------------------------------------------------------------------- 1 | validate($data, $constraint); 12 | if ($violations->count() > 0) { 13 | throw new ValidationException($violations); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Generator/RequestBodyContentGeneratorInterface.php: -------------------------------------------------------------------------------- 1 | resolve(function ($value) use ($result) { 16 | return $this->denormalizer->denormalize($value, Parameter::class, 'json', [ 17 | 'document-origin' => (string) $result->getMergedUri()->withFragment(''), 18 | ]); 19 | }); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /JsonSchema/Runtime/Normalizer/ValidationException.php: -------------------------------------------------------------------------------- 1 | violationList = $violationList; 13 | parent::__construct(sprintf('Model validation failed with %d errors.', $violationList->count()), 400); 14 | } 15 | public function getViolationList() : ConstraintViolationListInterface 16 | { 17 | return $this->violationList; 18 | } 19 | } -------------------------------------------------------------------------------- /SchemaParser/SchemaParser.php: -------------------------------------------------------------------------------- 1 | ='); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /JsonSchema/Runtime/Normalizer/ReferenceNormalizer.php: -------------------------------------------------------------------------------- 1 | getReferenceUri(); 16 | return $ref; 17 | } 18 | /** 19 | * {@inheritdoc} 20 | */ 21 | public function supportsNormalization($data, $format = null) : bool 22 | { 23 | return $data instanceof Reference; 24 | } 25 | } -------------------------------------------------------------------------------- /JsonSchema/Model/HTTPSecuritySchemeSub.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var mixed|null 17 | */ 18 | protected $scheme; 19 | /** 20 | * @return mixed 21 | */ 22 | public function getScheme() 23 | { 24 | return $this->scheme; 25 | } 26 | /** 27 | * @param mixed $scheme 28 | * 29 | * @return self 30 | */ 31 | public function setScheme($scheme) : self 32 | { 33 | $this->initialized['scheme'] = true; 34 | $this->scheme = $scheme; 35 | return $this; 36 | } 37 | } -------------------------------------------------------------------------------- /JsonSchema/Model/Reference.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $dollarRef; 19 | /** 20 | * @return string|null 21 | */ 22 | public function getDollarRef() : ?string 23 | { 24 | return $this->dollarRef; 25 | } 26 | /** 27 | * @param string|null $dollarRef 28 | * 29 | * @return self 30 | */ 31 | public function setDollarRef(?string $dollarRef) : self 32 | { 33 | $this->initialized['dollarRef'] = true; 34 | $this->dollarRef = $dollarRef; 35 | return $this; 36 | } 37 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jane OpenAPI 2 | 3 | Generate a PHP Client API (PSR7 compatible) given a [OpenAPI (Swagger) specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md). 4 | 5 | ## License 6 | 7 | View the [LICENSE](LICENSE) file attach to this project. 8 | 9 | ## Resources 10 | 11 | * [Documentation](http://jane.readthedocs.io/en/latest/) 12 | * [Contributing](https://github.com/janephp/janephp/blob/master/CONTRIBUTING.md) 13 | * [Report Issues](https://github.com/janephp/janephp/issues) and [send Pull Requests](https://github.com/janephp/janephp/pulls) 14 | in the [main Jane Repository](https://github.com/janephp/janephp) 15 | 16 | ## Sponsor 17 | 18 | [![JoliCode](https://jolicode.com/images/logo.svg)](https://jolicode.com) 19 | 20 | Open Source time sponsored by JoliCode 21 | 22 | ## Credits 23 | 24 | * [All contributors](https://github.com/jolicode/jane/graphs/contributors) 25 | -------------------------------------------------------------------------------- /JsonSchema/Model/Responses.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var Response|Reference|null 17 | */ 18 | protected $default; 19 | /** 20 | * @return Response|Reference|null 21 | */ 22 | public function getDefault() 23 | { 24 | return $this->default; 25 | } 26 | /** 27 | * @param Response|Reference|null $default 28 | * 29 | * @return self 30 | */ 31 | public function setDefault($default) : self 32 | { 33 | $this->initialized['default'] = true; 34 | $this->default = $default; 35 | return $this; 36 | } 37 | } -------------------------------------------------------------------------------- /Generator/RequestBodyContent/DefaultBodyContentGenerator.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $name; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $url; 23 | /** 24 | * @return string|null 25 | */ 26 | public function getName() : ?string 27 | { 28 | return $this->name; 29 | } 30 | /** 31 | * @param string|null $name 32 | * 33 | * @return self 34 | */ 35 | public function setName(?string $name) : self 36 | { 37 | $this->initialized['name'] = true; 38 | $this->name = $name; 39 | return $this; 40 | } 41 | /** 42 | * @return string|null 43 | */ 44 | public function getUrl() : ?string 45 | { 46 | return $this->url; 47 | } 48 | /** 49 | * @param string|null $url 50 | * 51 | * @return self 52 | */ 53 | public function setUrl(?string $url) : self 54 | { 55 | $this->initialized['url'] = true; 56 | $this->url = $url; 57 | return $this; 58 | } 59 | } -------------------------------------------------------------------------------- /JsonSchema/Model/ExternalDocumentation.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $description; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $url; 23 | /** 24 | * @return string|null 25 | */ 26 | public function getDescription() : ?string 27 | { 28 | return $this->description; 29 | } 30 | /** 31 | * @param string|null $description 32 | * 33 | * @return self 34 | */ 35 | public function setDescription(?string $description) : self 36 | { 37 | $this->initialized['description'] = true; 38 | $this->description = $description; 39 | return $this; 40 | } 41 | /** 42 | * @return string|null 43 | */ 44 | public function getUrl() : ?string 45 | { 46 | return $this->url; 47 | } 48 | /** 49 | * @param string|null $url 50 | * 51 | * @return self 52 | */ 53 | public function setUrl(?string $url) : self 54 | { 55 | $this->initialized['url'] = true; 56 | $this->url = $url; 57 | return $this; 58 | } 59 | } -------------------------------------------------------------------------------- /JsonSchema/Model/Discriminator.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $propertyName; 19 | /** 20 | * @var array|null 21 | */ 22 | protected $mapping; 23 | /** 24 | * @return string|null 25 | */ 26 | public function getPropertyName() : ?string 27 | { 28 | return $this->propertyName; 29 | } 30 | /** 31 | * @param string|null $propertyName 32 | * 33 | * @return self 34 | */ 35 | public function setPropertyName(?string $propertyName) : self 36 | { 37 | $this->initialized['propertyName'] = true; 38 | $this->propertyName = $propertyName; 39 | return $this; 40 | } 41 | /** 42 | * @return array|null 43 | */ 44 | public function getMapping() : ?iterable 45 | { 46 | return $this->mapping; 47 | } 48 | /** 49 | * @param array|null $mapping 50 | * 51 | * @return self 52 | */ 53 | public function setMapping(?iterable $mapping) : self 54 | { 55 | $this->initialized['mapping'] = true; 56 | $this->mapping = $mapping; 57 | return $this; 58 | } 59 | } -------------------------------------------------------------------------------- /Generator/RequestBodyContent/JsonBodyContentGenerator.php: -------------------------------------------------------------------------------- 1 | getReference() . '/requestBody'; 23 | $requestBody = $operation->getOperation()->getRequestBody(); 24 | 25 | if ($requestBody instanceof Reference) { 26 | [, $requestBody] = $guessClass->resolve($requestBody, RequestBody::class); 27 | } 28 | 29 | return new Stmt\ClassMethod('getBody', [ 30 | 'flags' => Modifiers::PUBLIC, 31 | 'params' => [ 32 | new Param(new Expr\Variable('serializer'), null, new Name\FullyQualified(SerializerInterface::class)), 33 | new Param(new Expr\Variable('streamFactory'), new Expr\ConstFetch(new Name('null'))), 34 | ], 35 | 'returnType' => new Name('array'), 36 | 'stmts' => $requestBodyGenerator->getSerializeStatements($requestBody, $opRef, $context), 37 | ]); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Generator/Client/ServerPluginGenerator.php: -------------------------------------------------------------------------------- 1 | getServers(); 20 | $server = $servers !== null && !empty($servers[0]) ? $servers[0] : null; 21 | 22 | if (null !== $server) { 23 | $url = parse_url($server->getUrl()); 24 | $baseUri = ''; 25 | $plugins = []; 26 | 27 | if (\array_key_exists('host', $url)) { 28 | $scheme = $url['scheme'] ?? 'https'; 29 | $baseUri = $scheme . '://' . trim($url['host'], '/'); 30 | $plugins[] = AddHostPlugin::class; 31 | } 32 | 33 | $variables = $server->getVariables(); 34 | 35 | if ($variables instanceof \ArrayObject 36 | && $variables->offsetExists('port') 37 | && null !== $variables->offsetGet('port')->getDefault() 38 | ) { 39 | $baseUri .= ':' . $variables['port']->getDefault(); 40 | } 41 | 42 | if (\array_key_exists('path', $url) && null !== $url['path']) { 43 | $baseUri .= '/' . trim($url['path'], '/'); 44 | $plugins[] = AddPathPlugin::class; 45 | } 46 | 47 | return [$baseUri, $plugins]; 48 | } 49 | 50 | return [null, []]; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Generator/Endpoint/GetGetQueryAllowReservedTrait.php: -------------------------------------------------------------------------------- 1 | getParameters() as $parameter) { 22 | if ($parameter instanceof Reference) { 23 | $parameter = $guessClass->resolveParameter($parameter); 24 | } 25 | 26 | if ($parameter instanceof Parameter && EndpointGenerator::IN_QUERY === $parameter->getIn() && true === $parameter->getAllowReserved()) { 27 | $queryAllowReservedParameters[] = $parameter->getName(); 28 | } 29 | } 30 | 31 | if (\count($queryAllowReservedParameters) === 0) { 32 | return null; 33 | } 34 | 35 | $items = []; 36 | foreach ($queryAllowReservedParameters as $parameter) { 37 | $items[] = new Expr\ArrayItem(new Scalar\String_($parameter)); 38 | } 39 | 40 | return new Stmt\ClassMethod($methodName, [ 41 | 'flags' => Modifiers::PROTECTED, 42 | 'stmts' => [ 43 | new Stmt\Return_(new Expr\Array_($items)), 44 | ], 45 | 'returnType' => new Name('array'), 46 | ]); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /JsonSchema/Model/Contact.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $name; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $url; 23 | /** 24 | * @var string|null 25 | */ 26 | protected $email; 27 | /** 28 | * @return string|null 29 | */ 30 | public function getName() : ?string 31 | { 32 | return $this->name; 33 | } 34 | /** 35 | * @param string|null $name 36 | * 37 | * @return self 38 | */ 39 | public function setName(?string $name) : self 40 | { 41 | $this->initialized['name'] = true; 42 | $this->name = $name; 43 | return $this; 44 | } 45 | /** 46 | * @return string|null 47 | */ 48 | public function getUrl() : ?string 49 | { 50 | return $this->url; 51 | } 52 | /** 53 | * @param string|null $url 54 | * 55 | * @return self 56 | */ 57 | public function setUrl(?string $url) : self 58 | { 59 | $this->initialized['url'] = true; 60 | $this->url = $url; 61 | return $this; 62 | } 63 | /** 64 | * @return string|null 65 | */ 66 | public function getEmail() : ?string 67 | { 68 | return $this->email; 69 | } 70 | /** 71 | * @param string|null $email 72 | * 73 | * @return self 74 | */ 75 | public function setEmail(?string $email) : self 76 | { 77 | $this->initialized['email'] = true; 78 | $this->email = $email; 79 | return $this; 80 | } 81 | } -------------------------------------------------------------------------------- /JsonSchema/Model/ServerVariable.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string[]|null 17 | */ 18 | protected $enum; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $default; 23 | /** 24 | * @var string|null 25 | */ 26 | protected $description; 27 | /** 28 | * @return string[]|null 29 | */ 30 | public function getEnum() : ?array 31 | { 32 | return $this->enum; 33 | } 34 | /** 35 | * @param string[]|null $enum 36 | * 37 | * @return self 38 | */ 39 | public function setEnum(?array $enum) : self 40 | { 41 | $this->initialized['enum'] = true; 42 | $this->enum = $enum; 43 | return $this; 44 | } 45 | /** 46 | * @return string|null 47 | */ 48 | public function getDefault() : ?string 49 | { 50 | return $this->default; 51 | } 52 | /** 53 | * @param string|null $default 54 | * 55 | * @return self 56 | */ 57 | public function setDefault(?string $default) : self 58 | { 59 | $this->initialized['default'] = true; 60 | $this->default = $default; 61 | return $this; 62 | } 63 | /** 64 | * @return string|null 65 | */ 66 | public function getDescription() : ?string 67 | { 68 | return $this->description; 69 | } 70 | /** 71 | * @param string|null $description 72 | * 73 | * @return self 74 | */ 75 | public function setDescription(?string $description) : self 76 | { 77 | $this->initialized['description'] = true; 78 | $this->description = $description; 79 | return $this; 80 | } 81 | } -------------------------------------------------------------------------------- /JsonSchema/Model/OAuth2SecurityScheme.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $type; 19 | /** 20 | * @var OAuthFlows|null 21 | */ 22 | protected $flows; 23 | /** 24 | * @var string|null 25 | */ 26 | protected $description; 27 | /** 28 | * @return string|null 29 | */ 30 | public function getType() : ?string 31 | { 32 | return $this->type; 33 | } 34 | /** 35 | * @param string|null $type 36 | * 37 | * @return self 38 | */ 39 | public function setType(?string $type) : self 40 | { 41 | $this->initialized['type'] = true; 42 | $this->type = $type; 43 | return $this; 44 | } 45 | /** 46 | * @return OAuthFlows|null 47 | */ 48 | public function getFlows() : ?OAuthFlows 49 | { 50 | return $this->flows; 51 | } 52 | /** 53 | * @param OAuthFlows|null $flows 54 | * 55 | * @return self 56 | */ 57 | public function setFlows(?OAuthFlows $flows) : self 58 | { 59 | $this->initialized['flows'] = true; 60 | $this->flows = $flows; 61 | return $this; 62 | } 63 | /** 64 | * @return string|null 65 | */ 66 | public function getDescription() : ?string 67 | { 68 | return $this->description; 69 | } 70 | /** 71 | * @param string|null $description 72 | * 73 | * @return self 74 | */ 75 | public function setDescription(?string $description) : self 76 | { 77 | $this->initialized['description'] = true; 78 | $this->description = $description; 79 | return $this; 80 | } 81 | } -------------------------------------------------------------------------------- /JsonSchema/Model/Server.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $url; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $description; 23 | /** 24 | * @var array|null 25 | */ 26 | protected $variables; 27 | /** 28 | * @return string|null 29 | */ 30 | public function getUrl() : ?string 31 | { 32 | return $this->url; 33 | } 34 | /** 35 | * @param string|null $url 36 | * 37 | * @return self 38 | */ 39 | public function setUrl(?string $url) : self 40 | { 41 | $this->initialized['url'] = true; 42 | $this->url = $url; 43 | return $this; 44 | } 45 | /** 46 | * @return string|null 47 | */ 48 | public function getDescription() : ?string 49 | { 50 | return $this->description; 51 | } 52 | /** 53 | * @param string|null $description 54 | * 55 | * @return self 56 | */ 57 | public function setDescription(?string $description) : self 58 | { 59 | $this->initialized['description'] = true; 60 | $this->description = $description; 61 | return $this; 62 | } 63 | /** 64 | * @return array|null 65 | */ 66 | public function getVariables() : ?iterable 67 | { 68 | return $this->variables; 69 | } 70 | /** 71 | * @param array|null $variables 72 | * 73 | * @return self 74 | */ 75 | public function setVariables(?iterable $variables) : self 76 | { 77 | $this->initialized['variables'] = true; 78 | $this->variables = $variables; 79 | return $this; 80 | } 81 | } -------------------------------------------------------------------------------- /JsonSchema/Model/PasswordOAuthFlow.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $tokenUrl; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $refreshUrl; 23 | /** 24 | * @var array|null 25 | */ 26 | protected $scopes; 27 | /** 28 | * @return string|null 29 | */ 30 | public function getTokenUrl() : ?string 31 | { 32 | return $this->tokenUrl; 33 | } 34 | /** 35 | * @param string|null $tokenUrl 36 | * 37 | * @return self 38 | */ 39 | public function setTokenUrl(?string $tokenUrl) : self 40 | { 41 | $this->initialized['tokenUrl'] = true; 42 | $this->tokenUrl = $tokenUrl; 43 | return $this; 44 | } 45 | /** 46 | * @return string|null 47 | */ 48 | public function getRefreshUrl() : ?string 49 | { 50 | return $this->refreshUrl; 51 | } 52 | /** 53 | * @param string|null $refreshUrl 54 | * 55 | * @return self 56 | */ 57 | public function setRefreshUrl(?string $refreshUrl) : self 58 | { 59 | $this->initialized['refreshUrl'] = true; 60 | $this->refreshUrl = $refreshUrl; 61 | return $this; 62 | } 63 | /** 64 | * @return array|null 65 | */ 66 | public function getScopes() : ?iterable 67 | { 68 | return $this->scopes; 69 | } 70 | /** 71 | * @param array|null $scopes 72 | * 73 | * @return self 74 | */ 75 | public function setScopes(?iterable $scopes) : self 76 | { 77 | $this->initialized['scopes'] = true; 78 | $this->scopes = $scopes; 79 | return $this; 80 | } 81 | } -------------------------------------------------------------------------------- /JsonSchema/Model/ClientCredentialsFlow.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $tokenUrl; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $refreshUrl; 23 | /** 24 | * @var array|null 25 | */ 26 | protected $scopes; 27 | /** 28 | * @return string|null 29 | */ 30 | public function getTokenUrl() : ?string 31 | { 32 | return $this->tokenUrl; 33 | } 34 | /** 35 | * @param string|null $tokenUrl 36 | * 37 | * @return self 38 | */ 39 | public function setTokenUrl(?string $tokenUrl) : self 40 | { 41 | $this->initialized['tokenUrl'] = true; 42 | $this->tokenUrl = $tokenUrl; 43 | return $this; 44 | } 45 | /** 46 | * @return string|null 47 | */ 48 | public function getRefreshUrl() : ?string 49 | { 50 | return $this->refreshUrl; 51 | } 52 | /** 53 | * @param string|null $refreshUrl 54 | * 55 | * @return self 56 | */ 57 | public function setRefreshUrl(?string $refreshUrl) : self 58 | { 59 | $this->initialized['refreshUrl'] = true; 60 | $this->refreshUrl = $refreshUrl; 61 | return $this; 62 | } 63 | /** 64 | * @return array|null 65 | */ 66 | public function getScopes() : ?iterable 67 | { 68 | return $this->scopes; 69 | } 70 | /** 71 | * @param array|null $scopes 72 | * 73 | * @return self 74 | */ 75 | public function setScopes(?iterable $scopes) : self 76 | { 77 | $this->initialized['scopes'] = true; 78 | $this->scopes = $scopes; 79 | return $this; 80 | } 81 | } -------------------------------------------------------------------------------- /JsonSchema/Model/RequestBody.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $description; 19 | /** 20 | * @var array|null 21 | */ 22 | protected $content; 23 | /** 24 | * @var bool|null 25 | */ 26 | protected $required = false; 27 | /** 28 | * @return string|null 29 | */ 30 | public function getDescription() : ?string 31 | { 32 | return $this->description; 33 | } 34 | /** 35 | * @param string|null $description 36 | * 37 | * @return self 38 | */ 39 | public function setDescription(?string $description) : self 40 | { 41 | $this->initialized['description'] = true; 42 | $this->description = $description; 43 | return $this; 44 | } 45 | /** 46 | * @return array|null 47 | */ 48 | public function getContent() : ?iterable 49 | { 50 | return $this->content; 51 | } 52 | /** 53 | * @param array|null $content 54 | * 55 | * @return self 56 | */ 57 | public function setContent(?iterable $content) : self 58 | { 59 | $this->initialized['content'] = true; 60 | $this->content = $content; 61 | return $this; 62 | } 63 | /** 64 | * @return bool|null 65 | */ 66 | public function getRequired() : ?bool 67 | { 68 | return $this->required; 69 | } 70 | /** 71 | * @param bool|null $required 72 | * 73 | * @return self 74 | */ 75 | public function setRequired(?bool $required) : self 76 | { 77 | $this->initialized['required'] = true; 78 | $this->required = $required; 79 | return $this; 80 | } 81 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jane-php/open-api-3", 3 | "type": "library", 4 | "description": "Generate a PHP Client API (PSR7/PSR18 compatible) given a OpenApi 3.x specification", 5 | "keywords": [ 6 | "jane", 7 | "swagger", 8 | "openapi" 9 | ], 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Joel Wurtz", 14 | "email": "jwurtz@jolicode.com" 15 | }, 16 | { 17 | "name": "Baptiste Leduc", 18 | "email": "baptiste.leduc@gmail.com" 19 | } 20 | ], 21 | "autoload": { 22 | "psr-4": { 23 | "Jane\\Component\\OpenApi3\\": "" 24 | }, 25 | "exclude-from-classmap": [ 26 | "/Tests/" 27 | ] 28 | }, 29 | "autoload-dev": { 30 | "psr-4": { 31 | "Jane\\Component\\OpenApi3\\Tests\\Client\\": "/Tests/client/generated/" 32 | } 33 | }, 34 | "require": { 35 | "php": "^8.1", 36 | "ext-json": "*", 37 | "jane-php/json-schema": "^7.5", 38 | "jane-php/open-api-common": "^7.5", 39 | "nikic/php-parser": "^4.19 || ^5.1", 40 | "symfony/serializer": "^5.4 || ^6.4 || ^7.0 || ^8.0", 41 | "symfony/yaml": "^5.4 || ^6.4 || ^7.0 || ^8.0" 42 | }, 43 | "require-dev": { 44 | "phpunit/phpunit": "^8.5", 45 | "symfony/finder": "^5.4 || ^6.4 || ^7.0 || ^8.0", 46 | "kriswallsmith/buzz": "^1.2", 47 | "nyholm/psr7": "^1.8" 48 | }, 49 | "suggest": { 50 | "friendsofphp/php-cs-fixer": "To have a nice formatting of the generated files" 51 | }, 52 | "conflict": { 53 | "symfony/framework-bundle": "5.1.0" 54 | }, 55 | "extra": { 56 | "branch-alias": { 57 | "dev-next": "7-dev" 58 | } 59 | }, 60 | "config": { 61 | "process-timeout": 1800, 62 | "sort-packages": true, 63 | "allow-plugins": { 64 | "php-http/discovery": true 65 | } 66 | }, 67 | "minimum-stability": "dev", 68 | "prefer-stable": true 69 | } 70 | -------------------------------------------------------------------------------- /JsonSchema/Model/Tag.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $name; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $description; 23 | /** 24 | * @var ExternalDocumentation|null 25 | */ 26 | protected $externalDocs; 27 | /** 28 | * @return string|null 29 | */ 30 | public function getName() : ?string 31 | { 32 | return $this->name; 33 | } 34 | /** 35 | * @param string|null $name 36 | * 37 | * @return self 38 | */ 39 | public function setName(?string $name) : self 40 | { 41 | $this->initialized['name'] = true; 42 | $this->name = $name; 43 | return $this; 44 | } 45 | /** 46 | * @return string|null 47 | */ 48 | public function getDescription() : ?string 49 | { 50 | return $this->description; 51 | } 52 | /** 53 | * @param string|null $description 54 | * 55 | * @return self 56 | */ 57 | public function setDescription(?string $description) : self 58 | { 59 | $this->initialized['description'] = true; 60 | $this->description = $description; 61 | return $this; 62 | } 63 | /** 64 | * @return ExternalDocumentation|null 65 | */ 66 | public function getExternalDocs() : ?ExternalDocumentation 67 | { 68 | return $this->externalDocs; 69 | } 70 | /** 71 | * @param ExternalDocumentation|null $externalDocs 72 | * 73 | * @return self 74 | */ 75 | public function setExternalDocs(?ExternalDocumentation $externalDocs) : self 76 | { 77 | $this->initialized['externalDocs'] = true; 78 | $this->externalDocs = $externalDocs; 79 | return $this; 80 | } 81 | } -------------------------------------------------------------------------------- /JsonSchema/Model/OpenIdConnectSecurityScheme.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $type; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $openIdConnectUrl; 23 | /** 24 | * @var string|null 25 | */ 26 | protected $description; 27 | /** 28 | * @return string|null 29 | */ 30 | public function getType() : ?string 31 | { 32 | return $this->type; 33 | } 34 | /** 35 | * @param string|null $type 36 | * 37 | * @return self 38 | */ 39 | public function setType(?string $type) : self 40 | { 41 | $this->initialized['type'] = true; 42 | $this->type = $type; 43 | return $this; 44 | } 45 | /** 46 | * @return string|null 47 | */ 48 | public function getOpenIdConnectUrl() : ?string 49 | { 50 | return $this->openIdConnectUrl; 51 | } 52 | /** 53 | * @param string|null $openIdConnectUrl 54 | * 55 | * @return self 56 | */ 57 | public function setOpenIdConnectUrl(?string $openIdConnectUrl) : self 58 | { 59 | $this->initialized['openIdConnectUrl'] = true; 60 | $this->openIdConnectUrl = $openIdConnectUrl; 61 | return $this; 62 | } 63 | /** 64 | * @return string|null 65 | */ 66 | public function getDescription() : ?string 67 | { 68 | return $this->description; 69 | } 70 | /** 71 | * @param string|null $description 72 | * 73 | * @return self 74 | */ 75 | public function setDescription(?string $description) : self 76 | { 77 | $this->initialized['description'] = true; 78 | $this->description = $description; 79 | return $this; 80 | } 81 | } -------------------------------------------------------------------------------- /JsonSchema/Model/ImplicitOAuthFlow.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $authorizationUrl; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $refreshUrl; 23 | /** 24 | * @var array|null 25 | */ 26 | protected $scopes; 27 | /** 28 | * @return string|null 29 | */ 30 | public function getAuthorizationUrl() : ?string 31 | { 32 | return $this->authorizationUrl; 33 | } 34 | /** 35 | * @param string|null $authorizationUrl 36 | * 37 | * @return self 38 | */ 39 | public function setAuthorizationUrl(?string $authorizationUrl) : self 40 | { 41 | $this->initialized['authorizationUrl'] = true; 42 | $this->authorizationUrl = $authorizationUrl; 43 | return $this; 44 | } 45 | /** 46 | * @return string|null 47 | */ 48 | public function getRefreshUrl() : ?string 49 | { 50 | return $this->refreshUrl; 51 | } 52 | /** 53 | * @param string|null $refreshUrl 54 | * 55 | * @return self 56 | */ 57 | public function setRefreshUrl(?string $refreshUrl) : self 58 | { 59 | $this->initialized['refreshUrl'] = true; 60 | $this->refreshUrl = $refreshUrl; 61 | return $this; 62 | } 63 | /** 64 | * @return array|null 65 | */ 66 | public function getScopes() : ?iterable 67 | { 68 | return $this->scopes; 69 | } 70 | /** 71 | * @param array|null $scopes 72 | * 73 | * @return self 74 | */ 75 | public function setScopes(?iterable $scopes) : self 76 | { 77 | $this->initialized['scopes'] = true; 78 | $this->scopes = $scopes; 79 | return $this; 80 | } 81 | } -------------------------------------------------------------------------------- /Generator/Endpoint/GetGetExtraHeadersTrait.php: -------------------------------------------------------------------------------- 1 | getContentTypes($operation, $guessClass); 20 | 21 | if (\count($produces) === 0) { 22 | return null; 23 | } 24 | 25 | // Add all content types except text/html as default Accept content types. 26 | $items = []; 27 | foreach ($produces as $contentType) { 28 | if ($contentType === 'text/html') { 29 | continue; 30 | } 31 | $items[] = new Expr\ArrayItem(new Scalar\String_($contentType)); 32 | } 33 | $headers[] = new Expr\ArrayItem( 34 | new Expr\Array_($items), 35 | new Scalar\String_('Accept') 36 | ); 37 | 38 | if (\count($items) === 1) { 39 | return new Stmt\ClassMethod('getExtraHeaders', [ 40 | 'flags' => Modifiers::PUBLIC, 41 | 'stmts' => [new Stmt\Return_(new Expr\Array_($headers))], 42 | 'returnType' => new Name('array'), 43 | ]); 44 | } 45 | 46 | $returnDefault = new Stmt\If_( 47 | new Expr\FuncCall(new Name('empty'), [ 48 | new Arg(new Expr\PropertyFetch(new Expr\Variable('this'), 'accept')), 49 | ]), 50 | [ 51 | 'stmts' => [ 52 | new Stmt\Return_(new Expr\Array_($headers)), 53 | ], 54 | ] 55 | ); 56 | 57 | $returnAccept = new Stmt\Return_(new Expr\PropertyFetch(new Expr\Variable('this'), 'accept')); 58 | 59 | return new Stmt\ClassMethod('getExtraHeaders', [ 60 | 'flags' => Modifiers::PUBLIC, 61 | 'stmts' => [$returnDefault, $returnAccept], 62 | 'returnType' => new Name('array'), 63 | ]); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /JaneOpenApi.php: -------------------------------------------------------------------------------- 1 | createForHostVersion(); 39 | 40 | yield new ModelGenerator($naming, $parser); 41 | yield new NormalizerGenerator($naming, $parser, $options['reference'] ?? false, $options['use-cacheable-supports-method'] ?? false, $options['skip-null-values'] ?? true, $options['skip-required-fields'] ?? false, $options['validation'] ?? false, $options['include-null-value'] ?? true); 42 | yield new AuthenticationGenerator(); 43 | yield GeneratorFactory::build($denormalizer, $options['endpoint-generator'] ?: EndpointGenerator::class); 44 | yield new RuntimeGenerator($naming, $parser); 45 | if ($options['validation'] ?? false) { 46 | yield new ValidatorGenerator($naming); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Guesser/OpenApiSchema/SecurityGuesser.php: -------------------------------------------------------------------------------- 1 | getType(), SecuritySchemeGuess::getAvailableTypes()); 20 | } 21 | 22 | /** 23 | * @param APIKeySecurityScheme|HTTPSecurityScheme|OAuth2SecurityScheme|OpenIdConnectSecurityScheme $object 24 | */ 25 | public function guessClass($object, string $name, string $reference, Registry $registry): void 26 | { 27 | if (!\in_array($object->getType(), [SecuritySchemeGuess::TYPE_HTTP, SecuritySchemeGuess::TYPE_API_KEY])) { 28 | return; 29 | } 30 | 31 | $securitySchemeGuess = new SecuritySchemeGuess($name, $object, $object instanceof HTTPSecurityScheme ? $name : $object->getName(), $object->getType()); 32 | switch ($securitySchemeGuess->getType()) { 33 | case SecuritySchemeGuess::TYPE_HTTP: 34 | $scheme = $object->getScheme() ?? SecuritySchemeGuess::SCHEME_BEARER; 35 | $scheme = ucfirst(mb_strtolower($scheme)); 36 | $securitySchemeGuess->setScheme($scheme); 37 | break; 38 | case SecuritySchemeGuess::TYPE_API_KEY: 39 | $securitySchemeGuess->setIn($object->getIn()); 40 | break; 41 | } 42 | 43 | /** @var Schema $schema */ 44 | $schema = $registry->getSchema($reference); 45 | $schema->addSecurityScheme($reference, $securitySchemeGuess); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Generator/GeneratorFactory.php: -------------------------------------------------------------------------------- 1 | createForHostVersion(); 23 | 24 | $nonBodyParameter = new NonBodyParameterGenerator($serializer, $parser); 25 | $exceptionGenerator = new ExceptionGenerator(); 26 | $operationNaming = new ChainOperationNaming([ 27 | new OperationIdNaming(), 28 | new OperationUrlNaming(), 29 | ]); 30 | 31 | $defaultContentGenerator = new DefaultBodyContentGenerator($serializer); 32 | $requestBodyGenerator = new RequestBodyGenerator($defaultContentGenerator); 33 | $requestBodyGenerator->addRequestBodyGenerator(JsonBodyContentGenerator::JSON_TYPES, new JsonBodyContentGenerator($serializer)); 34 | $requestBodyGenerator->addRequestBodyGenerator(['application/x-www-form-urlencoded', 'multipart/form-data'], new FormBodyContentGenerator($serializer)); 35 | 36 | if (!class_exists($endpointGeneratorClass)) { 37 | throw new \InvalidArgumentException(\sprintf('Unknown generator class %s', $endpointGeneratorClass)); 38 | } 39 | 40 | $endpointGenerator = new $endpointGeneratorClass($operationNaming, $nonBodyParameter, $serializer, $exceptionGenerator, $requestBodyGenerator); 41 | $operationGenerator = new OperationGenerator($endpointGenerator); 42 | 43 | return new ClientGenerator($operationGenerator, $operationNaming); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /JsonSchema/Model/APIKeySecurityScheme.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $type; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $name; 23 | /** 24 | * @var string|null 25 | */ 26 | protected $in; 27 | /** 28 | * @var string|null 29 | */ 30 | protected $description; 31 | /** 32 | * @return string|null 33 | */ 34 | public function getType() : ?string 35 | { 36 | return $this->type; 37 | } 38 | /** 39 | * @param string|null $type 40 | * 41 | * @return self 42 | */ 43 | public function setType(?string $type) : self 44 | { 45 | $this->initialized['type'] = true; 46 | $this->type = $type; 47 | return $this; 48 | } 49 | /** 50 | * @return string|null 51 | */ 52 | public function getName() : ?string 53 | { 54 | return $this->name; 55 | } 56 | /** 57 | * @param string|null $name 58 | * 59 | * @return self 60 | */ 61 | public function setName(?string $name) : self 62 | { 63 | $this->initialized['name'] = true; 64 | $this->name = $name; 65 | return $this; 66 | } 67 | /** 68 | * @return string|null 69 | */ 70 | public function getIn() : ?string 71 | { 72 | return $this->in; 73 | } 74 | /** 75 | * @param string|null $in 76 | * 77 | * @return self 78 | */ 79 | public function setIn(?string $in) : self 80 | { 81 | $this->initialized['in'] = true; 82 | $this->in = $in; 83 | return $this; 84 | } 85 | /** 86 | * @return string|null 87 | */ 88 | public function getDescription() : ?string 89 | { 90 | return $this->description; 91 | } 92 | /** 93 | * @param string|null $description 94 | * 95 | * @return self 96 | */ 97 | public function setDescription(?string $description) : self 98 | { 99 | $this->initialized['description'] = true; 100 | $this->description = $description; 101 | return $this; 102 | } 103 | } -------------------------------------------------------------------------------- /JsonSchema/Model/Example.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $summary; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $description; 23 | /** 24 | * @var mixed|null 25 | */ 26 | protected $value; 27 | /** 28 | * @var string|null 29 | */ 30 | protected $externalValue; 31 | /** 32 | * @return string|null 33 | */ 34 | public function getSummary() : ?string 35 | { 36 | return $this->summary; 37 | } 38 | /** 39 | * @param string|null $summary 40 | * 41 | * @return self 42 | */ 43 | public function setSummary(?string $summary) : self 44 | { 45 | $this->initialized['summary'] = true; 46 | $this->summary = $summary; 47 | return $this; 48 | } 49 | /** 50 | * @return string|null 51 | */ 52 | public function getDescription() : ?string 53 | { 54 | return $this->description; 55 | } 56 | /** 57 | * @param string|null $description 58 | * 59 | * @return self 60 | */ 61 | public function setDescription(?string $description) : self 62 | { 63 | $this->initialized['description'] = true; 64 | $this->description = $description; 65 | return $this; 66 | } 67 | /** 68 | * @return mixed 69 | */ 70 | public function getValue() 71 | { 72 | return $this->value; 73 | } 74 | /** 75 | * @param mixed $value 76 | * 77 | * @return self 78 | */ 79 | public function setValue($value) : self 80 | { 81 | $this->initialized['value'] = true; 82 | $this->value = $value; 83 | return $this; 84 | } 85 | /** 86 | * @return string|null 87 | */ 88 | public function getExternalValue() : ?string 89 | { 90 | return $this->externalValue; 91 | } 92 | /** 93 | * @param string|null $externalValue 94 | * 95 | * @return self 96 | */ 97 | public function setExternalValue(?string $externalValue) : self 98 | { 99 | $this->initialized['externalValue'] = true; 100 | $this->externalValue = $externalValue; 101 | return $this; 102 | } 103 | } -------------------------------------------------------------------------------- /JsonSchema/Model/HTTPSecurityScheme.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $scheme; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $bearerFormat; 23 | /** 24 | * @var string|null 25 | */ 26 | protected $description; 27 | /** 28 | * @var string|null 29 | */ 30 | protected $type; 31 | /** 32 | * @return string|null 33 | */ 34 | public function getScheme() : ?string 35 | { 36 | return $this->scheme; 37 | } 38 | /** 39 | * @param string|null $scheme 40 | * 41 | * @return self 42 | */ 43 | public function setScheme(?string $scheme) : self 44 | { 45 | $this->initialized['scheme'] = true; 46 | $this->scheme = $scheme; 47 | return $this; 48 | } 49 | /** 50 | * @return string|null 51 | */ 52 | public function getBearerFormat() : ?string 53 | { 54 | return $this->bearerFormat; 55 | } 56 | /** 57 | * @param string|null $bearerFormat 58 | * 59 | * @return self 60 | */ 61 | public function setBearerFormat(?string $bearerFormat) : self 62 | { 63 | $this->initialized['bearerFormat'] = true; 64 | $this->bearerFormat = $bearerFormat; 65 | return $this; 66 | } 67 | /** 68 | * @return string|null 69 | */ 70 | public function getDescription() : ?string 71 | { 72 | return $this->description; 73 | } 74 | /** 75 | * @param string|null $description 76 | * 77 | * @return self 78 | */ 79 | public function setDescription(?string $description) : self 80 | { 81 | $this->initialized['description'] = true; 82 | $this->description = $description; 83 | return $this; 84 | } 85 | /** 86 | * @return string|null 87 | */ 88 | public function getType() : ?string 89 | { 90 | return $this->type; 91 | } 92 | /** 93 | * @param string|null $type 94 | * 95 | * @return self 96 | */ 97 | public function setType(?string $type) : self 98 | { 99 | $this->initialized['type'] = true; 100 | $this->type = $type; 101 | return $this; 102 | } 103 | } -------------------------------------------------------------------------------- /Generator/Endpoint/GetResponseContentTrait.php: -------------------------------------------------------------------------------- 1 | getOperation()->getResponses()) { 21 | foreach ($operation->getOperation()->getResponses() as $response) { 22 | if ($response instanceof Reference) { 23 | [, $response] = $guessClass->resolve($response, Response::class); 24 | } 25 | if (\is_array($response)) { 26 | $normalizer = new ResponseNormalizer(); 27 | $normalizer->setDenormalizer($this->denormalizer); 28 | $response = $normalizer->denormalize($response, Response::class); 29 | } 30 | 31 | /** @var Response $response */ 32 | if ($response->getContent()) { 33 | foreach ($response->getContent() as $contentType => $content) { 34 | $trimmedContentType = trim($contentType); 35 | if ($trimmedContentType !== '' && !\in_array($trimmedContentType, $produces)) { 36 | $produces[] = $trimmedContentType; 37 | } 38 | } 39 | } 40 | } 41 | 42 | if ($operation->getOperation()->getResponses()->getDefault()) { 43 | $response = $operation->getOperation()->getResponses()->getDefault(); 44 | 45 | if ($response instanceof Reference) { 46 | [, $response] = $guessClass->resolve($response, Response::class); 47 | } 48 | 49 | /** @var Response $response */ 50 | if ($response->getContent()) { 51 | foreach ($response->getContent() as $contentType => $content) { 52 | $trimmedContentType = trim($contentType); 53 | if ($trimmedContentType !== '' && !\in_array($trimmedContentType, $produces)) { 54 | $produces[] = $trimmedContentType; 55 | } 56 | } 57 | } 58 | } 59 | } 60 | 61 | return $produces; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /JsonSchema/Model/MediaType.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var Schema|Reference|null 17 | */ 18 | protected $schema; 19 | /** 20 | * @var mixed|null 21 | */ 22 | protected $example; 23 | /** 24 | * @var array|null 25 | */ 26 | protected $examples; 27 | /** 28 | * @var array|null 29 | */ 30 | protected $encoding; 31 | /** 32 | * @return Schema|Reference|null 33 | */ 34 | public function getSchema() 35 | { 36 | return $this->schema; 37 | } 38 | /** 39 | * @param Schema|Reference|null $schema 40 | * 41 | * @return self 42 | */ 43 | public function setSchema($schema) : self 44 | { 45 | $this->initialized['schema'] = true; 46 | $this->schema = $schema; 47 | return $this; 48 | } 49 | /** 50 | * @return mixed 51 | */ 52 | public function getExample() 53 | { 54 | return $this->example; 55 | } 56 | /** 57 | * @param mixed $example 58 | * 59 | * @return self 60 | */ 61 | public function setExample($example) : self 62 | { 63 | $this->initialized['example'] = true; 64 | $this->example = $example; 65 | return $this; 66 | } 67 | /** 68 | * @return array|null 69 | */ 70 | public function getExamples() : ?iterable 71 | { 72 | return $this->examples; 73 | } 74 | /** 75 | * @param array|null $examples 76 | * 77 | * @return self 78 | */ 79 | public function setExamples(?iterable $examples) : self 80 | { 81 | $this->initialized['examples'] = true; 82 | $this->examples = $examples; 83 | return $this; 84 | } 85 | /** 86 | * @return array|null 87 | */ 88 | public function getEncoding() : ?iterable 89 | { 90 | return $this->encoding; 91 | } 92 | /** 93 | * @param array|null $encoding 94 | * 95 | * @return self 96 | */ 97 | public function setEncoding(?iterable $encoding) : self 98 | { 99 | $this->initialized['encoding'] = true; 100 | $this->encoding = $encoding; 101 | return $this; 102 | } 103 | } -------------------------------------------------------------------------------- /JsonSchema/Model/AuthorizationCodeOAuthFlow.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $authorizationUrl; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $tokenUrl; 23 | /** 24 | * @var string|null 25 | */ 26 | protected $refreshUrl; 27 | /** 28 | * @var array|null 29 | */ 30 | protected $scopes; 31 | /** 32 | * @return string|null 33 | */ 34 | public function getAuthorizationUrl() : ?string 35 | { 36 | return $this->authorizationUrl; 37 | } 38 | /** 39 | * @param string|null $authorizationUrl 40 | * 41 | * @return self 42 | */ 43 | public function setAuthorizationUrl(?string $authorizationUrl) : self 44 | { 45 | $this->initialized['authorizationUrl'] = true; 46 | $this->authorizationUrl = $authorizationUrl; 47 | return $this; 48 | } 49 | /** 50 | * @return string|null 51 | */ 52 | public function getTokenUrl() : ?string 53 | { 54 | return $this->tokenUrl; 55 | } 56 | /** 57 | * @param string|null $tokenUrl 58 | * 59 | * @return self 60 | */ 61 | public function setTokenUrl(?string $tokenUrl) : self 62 | { 63 | $this->initialized['tokenUrl'] = true; 64 | $this->tokenUrl = $tokenUrl; 65 | return $this; 66 | } 67 | /** 68 | * @return string|null 69 | */ 70 | public function getRefreshUrl() : ?string 71 | { 72 | return $this->refreshUrl; 73 | } 74 | /** 75 | * @param string|null $refreshUrl 76 | * 77 | * @return self 78 | */ 79 | public function setRefreshUrl(?string $refreshUrl) : self 80 | { 81 | $this->initialized['refreshUrl'] = true; 82 | $this->refreshUrl = $refreshUrl; 83 | return $this; 84 | } 85 | /** 86 | * @return array|null 87 | */ 88 | public function getScopes() : ?iterable 89 | { 90 | return $this->scopes; 91 | } 92 | /** 93 | * @param array|null $scopes 94 | * 95 | * @return self 96 | */ 97 | public function setScopes(?iterable $scopes) : self 98 | { 99 | $this->initialized['scopes'] = true; 100 | $this->scopes = $scopes; 101 | return $this; 102 | } 103 | } -------------------------------------------------------------------------------- /JsonSchema/Model/Response.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $description; 19 | /** 20 | * @var array|null 21 | */ 22 | protected $headers; 23 | /** 24 | * @var array|null 25 | */ 26 | protected $content; 27 | /** 28 | * @var array|null 29 | */ 30 | protected $links; 31 | /** 32 | * @return string|null 33 | */ 34 | public function getDescription() : ?string 35 | { 36 | return $this->description; 37 | } 38 | /** 39 | * @param string|null $description 40 | * 41 | * @return self 42 | */ 43 | public function setDescription(?string $description) : self 44 | { 45 | $this->initialized['description'] = true; 46 | $this->description = $description; 47 | return $this; 48 | } 49 | /** 50 | * @return array|null 51 | */ 52 | public function getHeaders() : ?iterable 53 | { 54 | return $this->headers; 55 | } 56 | /** 57 | * @param array|null $headers 58 | * 59 | * @return self 60 | */ 61 | public function setHeaders(?iterable $headers) : self 62 | { 63 | $this->initialized['headers'] = true; 64 | $this->headers = $headers; 65 | return $this; 66 | } 67 | /** 68 | * @return array|null 69 | */ 70 | public function getContent() : ?iterable 71 | { 72 | return $this->content; 73 | } 74 | /** 75 | * @param array|null $content 76 | * 77 | * @return self 78 | */ 79 | public function setContent(?iterable $content) : self 80 | { 81 | $this->initialized['content'] = true; 82 | $this->content = $content; 83 | return $this; 84 | } 85 | /** 86 | * @return array|null 87 | */ 88 | public function getLinks() : ?iterable 89 | { 90 | return $this->links; 91 | } 92 | /** 93 | * @param array|null $links 94 | * 95 | * @return self 96 | */ 97 | public function setLinks(?iterable $links) : self 98 | { 99 | $this->initialized['links'] = true; 100 | $this->links = $links; 101 | return $this; 102 | } 103 | } -------------------------------------------------------------------------------- /Generator/Endpoint/GetGetOptionsResolverTrait.php: -------------------------------------------------------------------------------- 1 | getParameters() as $parameter) { 24 | if ($parameter instanceof Reference) { 25 | $parameter = $guessClass->resolveParameter($parameter); 26 | } 27 | 28 | if ($parameter instanceof Parameter && $parameterIn === $parameter->getIn()) { 29 | if ($parameter->offsetExists('x-jane-skip-validation') && $parameter->offsetGet('x-jane-skip-validation')) { 30 | continue; 31 | } 32 | 33 | $parameters[] = $parameter; 34 | if (\in_array($parameter->getName(), $customResolverKeys)) { 35 | $queryResolverNormalizerStms[] = $this->generateOptionResolverNormalizationStatement($parameter->getName(), $customResolver[$parameter->getName()]); 36 | } 37 | } 38 | } 39 | 40 | if (\count($parameters) === 0) { 41 | return null; 42 | } 43 | 44 | $optionsResolverVariable = new Expr\Variable('optionsResolver'); 45 | 46 | return new Stmt\ClassMethod($methodName, [ 47 | 'flags' => Modifiers::PROTECTED, 48 | 'stmts' => array_merge( 49 | [ 50 | new Stmt\Expression(new Expr\Assign($optionsResolverVariable, new Expr\StaticCall(new Name('parent'), $methodName))), 51 | ], 52 | $nonBodyParameterGenerator->generateOptionsResolverStatements($optionsResolverVariable, $parameters, $genericResolver), 53 | $queryResolverNormalizerStms, 54 | [ 55 | new Stmt\Return_($optionsResolverVariable), 56 | ] 57 | ), 58 | 'returnType' => new Name\FullyQualified(OptionsResolver::class), 59 | ]); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /JsonSchema/Normalizer/ReferenceNormalizer.php: -------------------------------------------------------------------------------- 1 | setDollarRef($data['$ref']); 46 | } 47 | elseif (\array_key_exists('$ref', $data) && $data['$ref'] === null) { 48 | $object->setDollarRef(null); 49 | } 50 | return $object; 51 | } 52 | /** 53 | * @return array|string|int|float|bool|\ArrayObject|null 54 | */ 55 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 56 | { 57 | $data = []; 58 | $data['$ref'] = $object->getDollarRef(); 59 | return $data; 60 | } 61 | public function getSupportedTypes(?string $format = null) : array 62 | { 63 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Reference' => false]; 64 | } 65 | } -------------------------------------------------------------------------------- /Guesser/OpenApiSchema/GuesserFactory.php: -------------------------------------------------------------------------------- 1 | addGuesser(new SecurityGuesser()); 33 | $chainGuesser->addGuesser(new CustomStringFormatGuesser(Schema::class, $customStringFormatMapping)); 34 | $chainGuesser->addGuesser(new DateGuesser(Schema::class, $dateFormat, $datePreferInterface)); 35 | $chainGuesser->addGuesser(new DateTimeGuesser(Schema::class, $outputDateTimeFormat, $inputDateTimeFormat, $datePreferInterface)); 36 | $chainGuesser->addGuesser(new ReferenceGuesser($denormalizer, Schema::class)); 37 | $chainGuesser->addGuesser(new OpenApiGuesser($denormalizer)); 38 | $chainGuesser->addGuesser(new SchemaGuesser($denormalizer, $naming)); 39 | $chainGuesser->addGuesser(new AdditionalPropertiesGuesser(Schema::class)); 40 | $chainGuesser->addGuesser(new AllOfGuesser($denormalizer, $naming, Schema::class)); 41 | $chainGuesser->addGuesser(new AnyOfReferencefGuesser($denormalizer, $naming, Schema::class)); 42 | $chainGuesser->addGuesser(new ArrayGuesser(Schema::class)); 43 | $chainGuesser->addGuesser(new ItemsGuesser(Schema::class)); 44 | $chainGuesser->addGuesser(new SimpleTypeGuesser(Schema::class)); 45 | $chainGuesser->addGuesser(new MultipleGuesser(Schema::class)); 46 | 47 | return $chainGuesser; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /JsonSchema/Model/OAuthFlows.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var ImplicitOAuthFlow|null 17 | */ 18 | protected $implicit; 19 | /** 20 | * @var PasswordOAuthFlow|null 21 | */ 22 | protected $password; 23 | /** 24 | * @var ClientCredentialsFlow|null 25 | */ 26 | protected $clientCredentials; 27 | /** 28 | * @var AuthorizationCodeOAuthFlow|null 29 | */ 30 | protected $authorizationCode; 31 | /** 32 | * @return ImplicitOAuthFlow|null 33 | */ 34 | public function getImplicit() : ?ImplicitOAuthFlow 35 | { 36 | return $this->implicit; 37 | } 38 | /** 39 | * @param ImplicitOAuthFlow|null $implicit 40 | * 41 | * @return self 42 | */ 43 | public function setImplicit(?ImplicitOAuthFlow $implicit) : self 44 | { 45 | $this->initialized['implicit'] = true; 46 | $this->implicit = $implicit; 47 | return $this; 48 | } 49 | /** 50 | * @return PasswordOAuthFlow|null 51 | */ 52 | public function getPassword() : ?PasswordOAuthFlow 53 | { 54 | return $this->password; 55 | } 56 | /** 57 | * @param PasswordOAuthFlow|null $password 58 | * 59 | * @return self 60 | */ 61 | public function setPassword(?PasswordOAuthFlow $password) : self 62 | { 63 | $this->initialized['password'] = true; 64 | $this->password = $password; 65 | return $this; 66 | } 67 | /** 68 | * @return ClientCredentialsFlow|null 69 | */ 70 | public function getClientCredentials() : ?ClientCredentialsFlow 71 | { 72 | return $this->clientCredentials; 73 | } 74 | /** 75 | * @param ClientCredentialsFlow|null $clientCredentials 76 | * 77 | * @return self 78 | */ 79 | public function setClientCredentials(?ClientCredentialsFlow $clientCredentials) : self 80 | { 81 | $this->initialized['clientCredentials'] = true; 82 | $this->clientCredentials = $clientCredentials; 83 | return $this; 84 | } 85 | /** 86 | * @return AuthorizationCodeOAuthFlow|null 87 | */ 88 | public function getAuthorizationCode() : ?AuthorizationCodeOAuthFlow 89 | { 90 | return $this->authorizationCode; 91 | } 92 | /** 93 | * @param AuthorizationCodeOAuthFlow|null $authorizationCode 94 | * 95 | * @return self 96 | */ 97 | public function setAuthorizationCode(?AuthorizationCodeOAuthFlow $authorizationCode) : self 98 | { 99 | $this->initialized['authorizationCode'] = true; 100 | $this->authorizationCode = $authorizationCode; 101 | return $this; 102 | } 103 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/HTTPSecuritySchemeSubNormalizer.php: -------------------------------------------------------------------------------- 1 | setScheme($data['scheme']); 46 | } 47 | elseif (\array_key_exists('scheme', $data) && $data['scheme'] === null) { 48 | $object->setScheme(null); 49 | } 50 | return $object; 51 | } 52 | /** 53 | * @return array|string|int|float|bool|\ArrayObject|null 54 | */ 55 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 56 | { 57 | $data = []; 58 | $data['scheme'] = $object->getScheme(); 59 | return $data; 60 | } 61 | public function getSupportedTypes(?string $format = null) : array 62 | { 63 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\HTTPSecuritySchemeSub' => false]; 64 | } 65 | } -------------------------------------------------------------------------------- /JsonSchema/Model/XML.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $name; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $namespace; 23 | /** 24 | * @var string|null 25 | */ 26 | protected $prefix; 27 | /** 28 | * @var bool|null 29 | */ 30 | protected $attribute = false; 31 | /** 32 | * @var bool|null 33 | */ 34 | protected $wrapped = false; 35 | /** 36 | * @return string|null 37 | */ 38 | public function getName() : ?string 39 | { 40 | return $this->name; 41 | } 42 | /** 43 | * @param string|null $name 44 | * 45 | * @return self 46 | */ 47 | public function setName(?string $name) : self 48 | { 49 | $this->initialized['name'] = true; 50 | $this->name = $name; 51 | return $this; 52 | } 53 | /** 54 | * @return string|null 55 | */ 56 | public function getNamespace() : ?string 57 | { 58 | return $this->namespace; 59 | } 60 | /** 61 | * @param string|null $namespace 62 | * 63 | * @return self 64 | */ 65 | public function setNamespace(?string $namespace) : self 66 | { 67 | $this->initialized['namespace'] = true; 68 | $this->namespace = $namespace; 69 | return $this; 70 | } 71 | /** 72 | * @return string|null 73 | */ 74 | public function getPrefix() : ?string 75 | { 76 | return $this->prefix; 77 | } 78 | /** 79 | * @param string|null $prefix 80 | * 81 | * @return self 82 | */ 83 | public function setPrefix(?string $prefix) : self 84 | { 85 | $this->initialized['prefix'] = true; 86 | $this->prefix = $prefix; 87 | return $this; 88 | } 89 | /** 90 | * @return bool|null 91 | */ 92 | public function getAttribute() : ?bool 93 | { 94 | return $this->attribute; 95 | } 96 | /** 97 | * @param bool|null $attribute 98 | * 99 | * @return self 100 | */ 101 | public function setAttribute(?bool $attribute) : self 102 | { 103 | $this->initialized['attribute'] = true; 104 | $this->attribute = $attribute; 105 | return $this; 106 | } 107 | /** 108 | * @return bool|null 109 | */ 110 | public function getWrapped() : ?bool 111 | { 112 | return $this->wrapped; 113 | } 114 | /** 115 | * @param bool|null $wrapped 116 | * 117 | * @return self 118 | */ 119 | public function setWrapped(?bool $wrapped) : self 120 | { 121 | $this->initialized['wrapped'] = true; 122 | $this->wrapped = $wrapped; 123 | return $this; 124 | } 125 | } -------------------------------------------------------------------------------- /Guesser/OpenApiSchema/SchemaGuesser.php: -------------------------------------------------------------------------------- 1 | getType() || null === $object->getType()) && null !== $object->getProperties(); 17 | } 18 | 19 | protected function isPropertyNullable($property): bool 20 | { 21 | return parent::isPropertyNullable($property) || ($property->getNullable() ?? false); 22 | } 23 | 24 | /** 25 | * @param Schema $object 26 | */ 27 | protected function createClassGuess($object, $reference, $name, $extensions): BaseClassGuess 28 | { 29 | $classGuess = new ClassGuess($object, $reference, $this->naming->getClassName($name), $extensions, $object->getDeprecated() ?? false); 30 | 31 | $discriminator = $object->getDiscriminator(); 32 | if ($discriminator instanceof Discriminator 33 | && is_countable($discriminator->getMapping()) && \count($discriminator->getMapping()) > 0) { 34 | $classGuess = new ParentClass($classGuess, $discriminator->getPropertyName()); 35 | 36 | foreach ($discriminator->getMapping() as $discriminatorValue => $entryReference) { 37 | $subClassName = str_replace('#/components/schemas/', '', $entryReference); 38 | $classGuess->addChildEntry( 39 | $subClassName, 40 | preg_replace( 41 | '#components/schemas\/.+$#', 42 | \sprintf('components/schemas/%s', $subClassName), 43 | $reference 44 | ), 45 | $discriminatorValue 46 | ); 47 | } 48 | 49 | return $classGuess; 50 | } 51 | 52 | if ($object->getDiscriminator() instanceof Discriminator 53 | && \is_array($object->getEnum()) && \count($object->getEnum()) > 0) { 54 | $classGuess = new ParentClass($classGuess, $object->getDiscriminator()->getPropertyName()); 55 | 56 | foreach ($object->getEnum() as $subClassName) { 57 | $classGuess->addChildEntry( 58 | $subClassName, 59 | preg_replace( 60 | '#components/schemas\/.+$#', 61 | \sprintf('components/schemas/%s', $subClassName), 62 | $reference 63 | ) 64 | ); 65 | } 66 | 67 | return $classGuess; 68 | } 69 | 70 | return $classGuess; 71 | } 72 | 73 | protected function getSchemaClass(): string 74 | { 75 | return Schema::class; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /JsonSchema/Model/Encoding.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $contentType; 19 | /** 20 | * @var array|null 21 | */ 22 | protected $headers; 23 | /** 24 | * @var string|null 25 | */ 26 | protected $style; 27 | /** 28 | * @var bool|null 29 | */ 30 | protected $explode; 31 | /** 32 | * @var bool|null 33 | */ 34 | protected $allowReserved = false; 35 | /** 36 | * @return string|null 37 | */ 38 | public function getContentType() : ?string 39 | { 40 | return $this->contentType; 41 | } 42 | /** 43 | * @param string|null $contentType 44 | * 45 | * @return self 46 | */ 47 | public function setContentType(?string $contentType) : self 48 | { 49 | $this->initialized['contentType'] = true; 50 | $this->contentType = $contentType; 51 | return $this; 52 | } 53 | /** 54 | * @return array|null 55 | */ 56 | public function getHeaders() : ?iterable 57 | { 58 | return $this->headers; 59 | } 60 | /** 61 | * @param array|null $headers 62 | * 63 | * @return self 64 | */ 65 | public function setHeaders(?iterable $headers) : self 66 | { 67 | $this->initialized['headers'] = true; 68 | $this->headers = $headers; 69 | return $this; 70 | } 71 | /** 72 | * @return string|null 73 | */ 74 | public function getStyle() : ?string 75 | { 76 | return $this->style; 77 | } 78 | /** 79 | * @param string|null $style 80 | * 81 | * @return self 82 | */ 83 | public function setStyle(?string $style) : self 84 | { 85 | $this->initialized['style'] = true; 86 | $this->style = $style; 87 | return $this; 88 | } 89 | /** 90 | * @return bool|null 91 | */ 92 | public function getExplode() : ?bool 93 | { 94 | return $this->explode; 95 | } 96 | /** 97 | * @param bool|null $explode 98 | * 99 | * @return self 100 | */ 101 | public function setExplode(?bool $explode) : self 102 | { 103 | $this->initialized['explode'] = true; 104 | $this->explode = $explode; 105 | return $this; 106 | } 107 | /** 108 | * @return bool|null 109 | */ 110 | public function getAllowReserved() : ?bool 111 | { 112 | return $this->allowReserved; 113 | } 114 | /** 115 | * @param bool|null $allowReserved 116 | * 117 | * @return self 118 | */ 119 | public function setAllowReserved(?bool $allowReserved) : self 120 | { 121 | $this->initialized['allowReserved'] = true; 122 | $this->allowReserved = $allowReserved; 123 | return $this; 124 | } 125 | } -------------------------------------------------------------------------------- /Generator/Endpoint/GetGetUriTrait.php: -------------------------------------------------------------------------------- 1 | getParameters() as $parameter) { 26 | if ($parameter instanceof Reference) { 27 | $parameter = $guessClass->resolveParameter($parameter); 28 | } 29 | 30 | if (!$parameter instanceof Parameter || EndpointGenerator::IN_PATH !== $parameter->getIn()) { 31 | continue; 32 | } 33 | 34 | $schema = $parameter->getSchema(); 35 | if ($schema instanceof Reference) { 36 | [, $schema] = $guessClass->resolve($parameter->getSchema(), Schema::class); 37 | } 38 | 39 | $names[] = $parameter->getName(); 40 | $types[] = $schema instanceof Schema ? $schema->getType() : null; 41 | } 42 | 43 | if (\count($names) === 0) { 44 | return new Stmt\ClassMethod('getUri', [ 45 | 'flags' => Modifiers::PUBLIC, 46 | 'stmts' => [ 47 | new Stmt\Return_(new Scalar\String_($operation->getPath())), 48 | ], 49 | 'returnType' => new Name('string'), 50 | ]); 51 | } 52 | 53 | return new Stmt\ClassMethod('getUri', [ 54 | 'flags' => Modifiers::PUBLIC, 55 | 'stmts' => [ 56 | new Stmt\Return_(new Expr\FuncCall(new Name('str_replace'), [ 57 | new Arg(new Expr\Array_(array_map(function ($name) { 58 | return new ArrayItem(new Scalar\String_('{' . $name . '}')); 59 | }, $names))), 60 | new Arg(new Expr\Array_(array_map(function ($type, $name) { 61 | return 'array' === $type 62 | // return str_replace(['{param}'], [implode(',', $this->param)], '/path/{param}') 63 | ? new ArrayItem(new Expr\FuncCall(new Name('implode'), [new Arg(new Scalar\String_(',')), new Arg(new Expr\PropertyFetch(new Expr\Variable('this'), $name))])) 64 | // return str_replace(['{param}'], [$this->param], '/path/{param}') 65 | : new ArrayItem(new Expr\PropertyFetch(new Expr\Variable('this'), $name)); 66 | }, $types, $names))), 67 | new Arg(new Scalar\String_($operation->getPath())), 68 | ])), 69 | ], 70 | 'returnType' => new Name('string'), 71 | ]); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Guesser/OpenApiSchema/AnyOfReferencefGuesser.php: -------------------------------------------------------------------------------- 1 | denormalizer = $denormalizer; 31 | } 32 | 33 | public function supportObject($object): bool 34 | { 35 | return $object instanceof Schema && \is_array($object->getAnyOf()) && $object->getAnyOf()[0] instanceof Reference; 36 | } 37 | 38 | public function guessType($object, string $name, string $reference, Registry $registry): Type 39 | { 40 | $type = new MultipleType($object); 41 | if ($object instanceof Schema) { 42 | $mapping = null; 43 | $supportsDiscriminator = false; 44 | if ($object->getDiscriminator() && $object->getDiscriminator()->getPropertyName()) { 45 | $supportsDiscriminator = true; 46 | $type->setDiscriminatorProperty($object->getDiscriminator()->getPropertyName()); 47 | if ($object->getDiscriminator()->getMapping()) { 48 | $mapping = array_flip((array) $object->getDiscriminator()->getMapping()); 49 | } 50 | } 51 | foreach ($object->getAnyOf() as $index => $anyOf) { 52 | if ($anyOf === null) { 53 | continue; 54 | } 55 | $anyOfSchema = $anyOf; 56 | $anyOfReference = $reference . '/anyOf/' . $index; 57 | 58 | if ($anyOf instanceof Reference) { 59 | $anyOfReference = (string) $anyOf->getMergedUri(); 60 | 61 | if ((string) $anyOf->getMergedUri() === (string) $anyOf->getMergedUri()->withFragment('')) { 62 | $anyOfReference .= '#'; 63 | } 64 | 65 | $anyOfSchema = $this->resolve($anyOfSchema, $this->schemaClass); 66 | } 67 | if (null !== $anyOfSchema->getType()) { 68 | $anyOfType = $this->chainGuesser->guessType($anyOfSchema, $name, $anyOfReference, $registry); 69 | if ($supportsDiscriminator && $anyOf instanceof Reference) { 70 | $objectRef = '#' . $anyOf->getMergedUri()->getFragment(); 71 | $type->addType($anyOfType, $mapping ? $mapping[$objectRef] : $objectRef); 72 | } else { 73 | $type->addType($anyOfType); 74 | } 75 | } 76 | } 77 | } 78 | 79 | return $type; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /JsonSchema/Model/Info.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $title; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $description; 23 | /** 24 | * @var string|null 25 | */ 26 | protected $termsOfService; 27 | /** 28 | * @var Contact|null 29 | */ 30 | protected $contact; 31 | /** 32 | * @var License|null 33 | */ 34 | protected $license; 35 | /** 36 | * @var string|null 37 | */ 38 | protected $version; 39 | /** 40 | * @return string|null 41 | */ 42 | public function getTitle() : ?string 43 | { 44 | return $this->title; 45 | } 46 | /** 47 | * @param string|null $title 48 | * 49 | * @return self 50 | */ 51 | public function setTitle(?string $title) : self 52 | { 53 | $this->initialized['title'] = true; 54 | $this->title = $title; 55 | return $this; 56 | } 57 | /** 58 | * @return string|null 59 | */ 60 | public function getDescription() : ?string 61 | { 62 | return $this->description; 63 | } 64 | /** 65 | * @param string|null $description 66 | * 67 | * @return self 68 | */ 69 | public function setDescription(?string $description) : self 70 | { 71 | $this->initialized['description'] = true; 72 | $this->description = $description; 73 | return $this; 74 | } 75 | /** 76 | * @return string|null 77 | */ 78 | public function getTermsOfService() : ?string 79 | { 80 | return $this->termsOfService; 81 | } 82 | /** 83 | * @param string|null $termsOfService 84 | * 85 | * @return self 86 | */ 87 | public function setTermsOfService(?string $termsOfService) : self 88 | { 89 | $this->initialized['termsOfService'] = true; 90 | $this->termsOfService = $termsOfService; 91 | return $this; 92 | } 93 | /** 94 | * @return Contact|null 95 | */ 96 | public function getContact() : ?Contact 97 | { 98 | return $this->contact; 99 | } 100 | /** 101 | * @param Contact|null $contact 102 | * 103 | * @return self 104 | */ 105 | public function setContact(?Contact $contact) : self 106 | { 107 | $this->initialized['contact'] = true; 108 | $this->contact = $contact; 109 | return $this; 110 | } 111 | /** 112 | * @return License|null 113 | */ 114 | public function getLicense() : ?License 115 | { 116 | return $this->license; 117 | } 118 | /** 119 | * @param License|null $license 120 | * 121 | * @return self 122 | */ 123 | public function setLicense(?License $license) : self 124 | { 125 | $this->initialized['license'] = true; 126 | $this->license = $license; 127 | return $this; 128 | } 129 | /** 130 | * @return string|null 131 | */ 132 | public function getVersion() : ?string 133 | { 134 | return $this->version; 135 | } 136 | /** 137 | * @param string|null $version 138 | * 139 | * @return self 140 | */ 141 | public function setVersion(?string $version) : self 142 | { 143 | $this->initialized['version'] = true; 144 | $this->version = $version; 145 | return $this; 146 | } 147 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/LicenseNormalizer.php: -------------------------------------------------------------------------------- 1 | setName($data['name']); 46 | unset($data['name']); 47 | } 48 | elseif (\array_key_exists('name', $data) && $data['name'] === null) { 49 | $object->setName(null); 50 | } 51 | if (\array_key_exists('url', $data) && $data['url'] !== null) { 52 | $object->setUrl($data['url']); 53 | unset($data['url']); 54 | } 55 | elseif (\array_key_exists('url', $data) && $data['url'] === null) { 56 | $object->setUrl(null); 57 | } 58 | foreach ($data as $key => $value) { 59 | if (preg_match('/^x-/', (string) $key)) { 60 | $object[$key] = $value; 61 | } 62 | } 63 | return $object; 64 | } 65 | /** 66 | * @return array|string|int|float|bool|\ArrayObject|null 67 | */ 68 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 69 | { 70 | $data = []; 71 | $data['name'] = $object->getName(); 72 | if ($object->isInitialized('url') && null !== $object->getUrl()) { 73 | $data['url'] = $object->getUrl(); 74 | } 75 | foreach ($object as $key => $value) { 76 | if (preg_match('/^x-/', (string) $key)) { 77 | $data[$key] = $value; 78 | } 79 | } 80 | return $data; 81 | } 82 | public function getSupportedTypes(?string $format = null) : array 83 | { 84 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\License' => false]; 85 | } 86 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/DiscriminatorNormalizer.php: -------------------------------------------------------------------------------- 1 | setPropertyName($data['propertyName']); 46 | } 47 | elseif (\array_key_exists('propertyName', $data) && $data['propertyName'] === null) { 48 | $object->setPropertyName(null); 49 | } 50 | if (\array_key_exists('mapping', $data) && $data['mapping'] !== null) { 51 | $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); 52 | foreach ($data['mapping'] as $key => $value) { 53 | $values[$key] = $value; 54 | } 55 | $object->setMapping($values); 56 | } 57 | elseif (\array_key_exists('mapping', $data) && $data['mapping'] === null) { 58 | $object->setMapping(null); 59 | } 60 | return $object; 61 | } 62 | /** 63 | * @return array|string|int|float|bool|\ArrayObject|null 64 | */ 65 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 66 | { 67 | $data = []; 68 | $data['propertyName'] = $object->getPropertyName(); 69 | if ($object->isInitialized('mapping') && null !== $object->getMapping()) { 70 | $values = []; 71 | foreach ($object->getMapping() as $key => $value) { 72 | $values[$key] = $value; 73 | } 74 | $data['mapping'] = $values; 75 | } 76 | return $data; 77 | } 78 | public function getSupportedTypes(?string $format = null) : array 79 | { 80 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Discriminator' => false]; 81 | } 82 | } -------------------------------------------------------------------------------- /JsonSchema/Model/Link.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $operationId; 19 | /** 20 | * @var string|null 21 | */ 22 | protected $operationRef; 23 | /** 24 | * @var array|null 25 | */ 26 | protected $parameters; 27 | /** 28 | * @var mixed|null 29 | */ 30 | protected $requestBody; 31 | /** 32 | * @var string|null 33 | */ 34 | protected $description; 35 | /** 36 | * @var Server|null 37 | */ 38 | protected $server; 39 | /** 40 | * @return string|null 41 | */ 42 | public function getOperationId() : ?string 43 | { 44 | return $this->operationId; 45 | } 46 | /** 47 | * @param string|null $operationId 48 | * 49 | * @return self 50 | */ 51 | public function setOperationId(?string $operationId) : self 52 | { 53 | $this->initialized['operationId'] = true; 54 | $this->operationId = $operationId; 55 | return $this; 56 | } 57 | /** 58 | * @return string|null 59 | */ 60 | public function getOperationRef() : ?string 61 | { 62 | return $this->operationRef; 63 | } 64 | /** 65 | * @param string|null $operationRef 66 | * 67 | * @return self 68 | */ 69 | public function setOperationRef(?string $operationRef) : self 70 | { 71 | $this->initialized['operationRef'] = true; 72 | $this->operationRef = $operationRef; 73 | return $this; 74 | } 75 | /** 76 | * @return array|null 77 | */ 78 | public function getParameters() : ?iterable 79 | { 80 | return $this->parameters; 81 | } 82 | /** 83 | * @param array|null $parameters 84 | * 85 | * @return self 86 | */ 87 | public function setParameters(?iterable $parameters) : self 88 | { 89 | $this->initialized['parameters'] = true; 90 | $this->parameters = $parameters; 91 | return $this; 92 | } 93 | /** 94 | * @return mixed 95 | */ 96 | public function getRequestBody() 97 | { 98 | return $this->requestBody; 99 | } 100 | /** 101 | * @param mixed $requestBody 102 | * 103 | * @return self 104 | */ 105 | public function setRequestBody($requestBody) : self 106 | { 107 | $this->initialized['requestBody'] = true; 108 | $this->requestBody = $requestBody; 109 | return $this; 110 | } 111 | /** 112 | * @return string|null 113 | */ 114 | public function getDescription() : ?string 115 | { 116 | return $this->description; 117 | } 118 | /** 119 | * @param string|null $description 120 | * 121 | * @return self 122 | */ 123 | public function setDescription(?string $description) : self 124 | { 125 | $this->initialized['description'] = true; 126 | $this->description = $description; 127 | return $this; 128 | } 129 | /** 130 | * @return Server|null 131 | */ 132 | public function getServer() : ?Server 133 | { 134 | return $this->server; 135 | } 136 | /** 137 | * @param Server|null $server 138 | * 139 | * @return self 140 | */ 141 | public function setServer(?Server $server) : self 142 | { 143 | $this->initialized['server'] = true; 144 | $this->server = $server; 145 | return $this; 146 | } 147 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/ExternalDocumentationNormalizer.php: -------------------------------------------------------------------------------- 1 | setDescription($data['description']); 46 | unset($data['description']); 47 | } 48 | elseif (\array_key_exists('description', $data) && $data['description'] === null) { 49 | $object->setDescription(null); 50 | } 51 | if (\array_key_exists('url', $data) && $data['url'] !== null) { 52 | $object->setUrl($data['url']); 53 | unset($data['url']); 54 | } 55 | elseif (\array_key_exists('url', $data) && $data['url'] === null) { 56 | $object->setUrl(null); 57 | } 58 | foreach ($data as $key => $value) { 59 | if (preg_match('/^x-/', (string) $key)) { 60 | $object[$key] = $value; 61 | } 62 | } 63 | return $object; 64 | } 65 | /** 66 | * @return array|string|int|float|bool|\ArrayObject|null 67 | */ 68 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 69 | { 70 | $data = []; 71 | if ($object->isInitialized('description') && null !== $object->getDescription()) { 72 | $data['description'] = $object->getDescription(); 73 | } 74 | $data['url'] = $object->getUrl(); 75 | foreach ($object as $key => $value) { 76 | if (preg_match('/^x-/', (string) $key)) { 77 | $data[$key] = $value; 78 | } 79 | } 80 | return $data; 81 | } 82 | public function getSupportedTypes(?string $format = null) : array 83 | { 84 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\ExternalDocumentation' => false]; 85 | } 86 | } -------------------------------------------------------------------------------- /Generator/RequestBodyContent/FormBodyContentGenerator.php: -------------------------------------------------------------------------------- 1 | new Expr\Variable('key'), 29 | 'stmts' => [ 30 | new Stmt\Expression(new Expr\Assign(new Expr\Variable('value'), 31 | new Expr\Ternary( 32 | new Expr\FuncCall(new Name('is_int'), [new Arg(new Expr\Variable('value'))]), 33 | new Expr\Cast\String_(new Expr\Variable('value')), 34 | new Expr\Variable('value') 35 | ) 36 | )), 37 | new Stmt\Expression(new Expr\MethodCall(new Expr\Variable('bodyBuilder'), 'addResource', [ 38 | new Arg(new Expr\Variable('key')), 39 | new Arg(new Expr\Variable('value')), 40 | ])), 41 | ], 42 | ]), 43 | new Stmt\Return_(new Expr\Array_([ 44 | new Expr\Array_([ 45 | new Expr\ArrayItem( 46 | new Expr\Array_([new Expr\ArrayItem( 47 | new Expr\BinaryOp\Concat( 48 | new Scalar\String_('multipart/form-data; boundary="'), 49 | new Expr\BinaryOp\Concat( 50 | new Expr\MethodCall(new Expr\Variable('bodyBuilder'), 'getBoundary'), 51 | new Scalar\String_('"') 52 | ) 53 | ) 54 | )]), 55 | new Scalar\String_('Content-Type') 56 | ), 57 | ]), 58 | new Expr\MethodCall(new Expr\Variable('bodyBuilder'), 'build'), 59 | ])), 60 | ]; 61 | } 62 | 63 | return [new Stmt\Return_(new Expr\Array_([ 64 | new Expr\Array_([ 65 | new Expr\ArrayItem( 66 | new Expr\Array_([new Expr\ArrayItem(new Scalar\String_($contentType))]), 67 | new Scalar\String_('Content-Type') 68 | ), 69 | ]), 70 | new Expr\FuncCall(new Name('http_build_query'), [ 71 | new Arg(new Expr\MethodCall( 72 | new Expr\Variable('serializer'), 73 | 'normalize', 74 | [ 75 | new Arg(new Expr\PropertyFetch(new Expr\Variable('this'), 'body')), 76 | new Arg(new Scalar\String_('json')), 77 | ] 78 | )), 79 | ]), 80 | ]))]; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /JsonSchema/Normalizer/ContactNormalizer.php: -------------------------------------------------------------------------------- 1 | setName($data['name']); 46 | unset($data['name']); 47 | } 48 | elseif (\array_key_exists('name', $data) && $data['name'] === null) { 49 | $object->setName(null); 50 | } 51 | if (\array_key_exists('url', $data) && $data['url'] !== null) { 52 | $object->setUrl($data['url']); 53 | unset($data['url']); 54 | } 55 | elseif (\array_key_exists('url', $data) && $data['url'] === null) { 56 | $object->setUrl(null); 57 | } 58 | if (\array_key_exists('email', $data) && $data['email'] !== null) { 59 | $object->setEmail($data['email']); 60 | unset($data['email']); 61 | } 62 | elseif (\array_key_exists('email', $data) && $data['email'] === null) { 63 | $object->setEmail(null); 64 | } 65 | foreach ($data as $key => $value) { 66 | if (preg_match('/^x-/', (string) $key)) { 67 | $object[$key] = $value; 68 | } 69 | } 70 | return $object; 71 | } 72 | /** 73 | * @return array|string|int|float|bool|\ArrayObject|null 74 | */ 75 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 76 | { 77 | $data = []; 78 | if ($object->isInitialized('name') && null !== $object->getName()) { 79 | $data['name'] = $object->getName(); 80 | } 81 | if ($object->isInitialized('url') && null !== $object->getUrl()) { 82 | $data['url'] = $object->getUrl(); 83 | } 84 | if ($object->isInitialized('email') && null !== $object->getEmail()) { 85 | $data['email'] = $object->getEmail(); 86 | } 87 | foreach ($object as $key => $value) { 88 | if (preg_match('/^x-/', (string) $key)) { 89 | $data[$key] = $value; 90 | } 91 | } 92 | return $data; 93 | } 94 | public function getSupportedTypes(?string $format = null) : array 95 | { 96 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Contact' => false]; 97 | } 98 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/OpenIdConnectSecuritySchemeNormalizer.php: -------------------------------------------------------------------------------- 1 | setType($data['type']); 46 | unset($data['type']); 47 | } 48 | elseif (\array_key_exists('type', $data) && $data['type'] === null) { 49 | $object->setType(null); 50 | } 51 | if (\array_key_exists('openIdConnectUrl', $data) && $data['openIdConnectUrl'] !== null) { 52 | $object->setOpenIdConnectUrl($data['openIdConnectUrl']); 53 | unset($data['openIdConnectUrl']); 54 | } 55 | elseif (\array_key_exists('openIdConnectUrl', $data) && $data['openIdConnectUrl'] === null) { 56 | $object->setOpenIdConnectUrl(null); 57 | } 58 | if (\array_key_exists('description', $data) && $data['description'] !== null) { 59 | $object->setDescription($data['description']); 60 | unset($data['description']); 61 | } 62 | elseif (\array_key_exists('description', $data) && $data['description'] === null) { 63 | $object->setDescription(null); 64 | } 65 | foreach ($data as $key => $value) { 66 | if (preg_match('/^x-/', (string) $key)) { 67 | $object[$key] = $value; 68 | } 69 | } 70 | return $object; 71 | } 72 | /** 73 | * @return array|string|int|float|bool|\ArrayObject|null 74 | */ 75 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 76 | { 77 | $data = []; 78 | $data['type'] = $object->getType(); 79 | $data['openIdConnectUrl'] = $object->getOpenIdConnectUrl(); 80 | if ($object->isInitialized('description') && null !== $object->getDescription()) { 81 | $data['description'] = $object->getDescription(); 82 | } 83 | foreach ($object as $key => $value) { 84 | if (preg_match('/^x-/', (string) $key)) { 85 | $data[$key] = $value; 86 | } 87 | } 88 | return $data; 89 | } 90 | public function getSupportedTypes(?string $format = null) : array 91 | { 92 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\OpenIdConnectSecurityScheme' => false]; 93 | } 94 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/OAuth2SecuritySchemeNormalizer.php: -------------------------------------------------------------------------------- 1 | setType($data['type']); 46 | unset($data['type']); 47 | } 48 | elseif (\array_key_exists('type', $data) && $data['type'] === null) { 49 | $object->setType(null); 50 | } 51 | if (\array_key_exists('flows', $data) && $data['flows'] !== null) { 52 | $object->setFlows($this->denormalizer->denormalize($data['flows'], 'Jane\\Component\\OpenApi3\\JsonSchema\\Model\\OAuthFlows', 'json', $context)); 53 | unset($data['flows']); 54 | } 55 | elseif (\array_key_exists('flows', $data) && $data['flows'] === null) { 56 | $object->setFlows(null); 57 | } 58 | if (\array_key_exists('description', $data) && $data['description'] !== null) { 59 | $object->setDescription($data['description']); 60 | unset($data['description']); 61 | } 62 | elseif (\array_key_exists('description', $data) && $data['description'] === null) { 63 | $object->setDescription(null); 64 | } 65 | foreach ($data as $key => $value) { 66 | if (preg_match('/^x-/', (string) $key)) { 67 | $object[$key] = $value; 68 | } 69 | } 70 | return $object; 71 | } 72 | /** 73 | * @return array|string|int|float|bool|\ArrayObject|null 74 | */ 75 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 76 | { 77 | $data = []; 78 | $data['type'] = $object->getType(); 79 | $data['flows'] = $this->normalizer->normalize($object->getFlows(), 'json', $context); 80 | if ($object->isInitialized('description') && null !== $object->getDescription()) { 81 | $data['description'] = $object->getDescription(); 82 | } 83 | foreach ($object as $key => $value) { 84 | if (preg_match('/^x-/', (string) $key)) { 85 | $data[$key] = $value; 86 | } 87 | } 88 | return $data; 89 | } 90 | public function getSupportedTypes(?string $format = null) : array 91 | { 92 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\OAuth2SecurityScheme' => false]; 93 | } 94 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/TagNormalizer.php: -------------------------------------------------------------------------------- 1 | setName($data['name']); 46 | unset($data['name']); 47 | } 48 | elseif (\array_key_exists('name', $data) && $data['name'] === null) { 49 | $object->setName(null); 50 | } 51 | if (\array_key_exists('description', $data) && $data['description'] !== null) { 52 | $object->setDescription($data['description']); 53 | unset($data['description']); 54 | } 55 | elseif (\array_key_exists('description', $data) && $data['description'] === null) { 56 | $object->setDescription(null); 57 | } 58 | if (\array_key_exists('externalDocs', $data) && $data['externalDocs'] !== null) { 59 | $object->setExternalDocs($this->denormalizer->denormalize($data['externalDocs'], 'Jane\\Component\\OpenApi3\\JsonSchema\\Model\\ExternalDocumentation', 'json', $context)); 60 | unset($data['externalDocs']); 61 | } 62 | elseif (\array_key_exists('externalDocs', $data) && $data['externalDocs'] === null) { 63 | $object->setExternalDocs(null); 64 | } 65 | foreach ($data as $key => $value) { 66 | if (preg_match('/^x-/', (string) $key)) { 67 | $object[$key] = $value; 68 | } 69 | } 70 | return $object; 71 | } 72 | /** 73 | * @return array|string|int|float|bool|\ArrayObject|null 74 | */ 75 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 76 | { 77 | $data = []; 78 | $data['name'] = $object->getName(); 79 | if ($object->isInitialized('description') && null !== $object->getDescription()) { 80 | $data['description'] = $object->getDescription(); 81 | } 82 | if ($object->isInitialized('externalDocs') && null !== $object->getExternalDocs()) { 83 | $data['externalDocs'] = $this->normalizer->normalize($object->getExternalDocs(), 'json', $context); 84 | } 85 | foreach ($object as $key => $value) { 86 | if (preg_match('/^x-/', (string) $key)) { 87 | $data[$key] = $value; 88 | } 89 | } 90 | return $data; 91 | } 92 | public function getSupportedTypes(?string $format = null) : array 93 | { 94 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Tag' => false]; 95 | } 96 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/APIKeySecuritySchemeNormalizer.php: -------------------------------------------------------------------------------- 1 | setType($data['type']); 46 | unset($data['type']); 47 | } 48 | elseif (\array_key_exists('type', $data) && $data['type'] === null) { 49 | $object->setType(null); 50 | } 51 | if (\array_key_exists('name', $data) && $data['name'] !== null) { 52 | $object->setName($data['name']); 53 | unset($data['name']); 54 | } 55 | elseif (\array_key_exists('name', $data) && $data['name'] === null) { 56 | $object->setName(null); 57 | } 58 | if (\array_key_exists('in', $data) && $data['in'] !== null) { 59 | $object->setIn($data['in']); 60 | unset($data['in']); 61 | } 62 | elseif (\array_key_exists('in', $data) && $data['in'] === null) { 63 | $object->setIn(null); 64 | } 65 | if (\array_key_exists('description', $data) && $data['description'] !== null) { 66 | $object->setDescription($data['description']); 67 | unset($data['description']); 68 | } 69 | elseif (\array_key_exists('description', $data) && $data['description'] === null) { 70 | $object->setDescription(null); 71 | } 72 | foreach ($data as $key => $value) { 73 | if (preg_match('/^x-/', (string) $key)) { 74 | $object[$key] = $value; 75 | } 76 | } 77 | return $object; 78 | } 79 | /** 80 | * @return array|string|int|float|bool|\ArrayObject|null 81 | */ 82 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 83 | { 84 | $data = []; 85 | $data['type'] = $object->getType(); 86 | $data['name'] = $object->getName(); 87 | $data['in'] = $object->getIn(); 88 | if ($object->isInitialized('description') && null !== $object->getDescription()) { 89 | $data['description'] = $object->getDescription(); 90 | } 91 | foreach ($object as $key => $value) { 92 | if (preg_match('/^x-/', (string) $key)) { 93 | $data[$key] = $value; 94 | } 95 | } 96 | return $data; 97 | } 98 | public function getSupportedTypes(?string $format = null) : array 99 | { 100 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\APIKeySecurityScheme' => false]; 101 | } 102 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/ServerVariableNormalizer.php: -------------------------------------------------------------------------------- 1 | setEnum($values); 50 | unset($data['enum']); 51 | } 52 | elseif (\array_key_exists('enum', $data) && $data['enum'] === null) { 53 | $object->setEnum(null); 54 | } 55 | if (\array_key_exists('default', $data) && $data['default'] !== null) { 56 | $object->setDefault($data['default']); 57 | unset($data['default']); 58 | } 59 | elseif (\array_key_exists('default', $data) && $data['default'] === null) { 60 | $object->setDefault(null); 61 | } 62 | if (\array_key_exists('description', $data) && $data['description'] !== null) { 63 | $object->setDescription($data['description']); 64 | unset($data['description']); 65 | } 66 | elseif (\array_key_exists('description', $data) && $data['description'] === null) { 67 | $object->setDescription(null); 68 | } 69 | foreach ($data as $key => $value_1) { 70 | if (preg_match('/^x-/', (string) $key)) { 71 | $object[$key] = $value_1; 72 | } 73 | } 74 | return $object; 75 | } 76 | /** 77 | * @return array|string|int|float|bool|\ArrayObject|null 78 | */ 79 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 80 | { 81 | $data = []; 82 | if ($object->isInitialized('enum') && null !== $object->getEnum()) { 83 | $values = []; 84 | foreach ($object->getEnum() as $value) { 85 | $values[] = $value; 86 | } 87 | $data['enum'] = $values; 88 | } 89 | $data['default'] = $object->getDefault(); 90 | if ($object->isInitialized('description') && null !== $object->getDescription()) { 91 | $data['description'] = $object->getDescription(); 92 | } 93 | foreach ($object as $key => $value_1) { 94 | if (preg_match('/^x-/', (string) $key)) { 95 | $data[$key] = $value_1; 96 | } 97 | } 98 | return $data; 99 | } 100 | public function getSupportedTypes(?string $format = null) : array 101 | { 102 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\ServerVariable' => false]; 103 | } 104 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/ImplicitOAuthFlowNormalizer.php: -------------------------------------------------------------------------------- 1 | setAuthorizationUrl($data['authorizationUrl']); 46 | unset($data['authorizationUrl']); 47 | } 48 | elseif (\array_key_exists('authorizationUrl', $data) && $data['authorizationUrl'] === null) { 49 | $object->setAuthorizationUrl(null); 50 | } 51 | if (\array_key_exists('refreshUrl', $data) && $data['refreshUrl'] !== null) { 52 | $object->setRefreshUrl($data['refreshUrl']); 53 | unset($data['refreshUrl']); 54 | } 55 | elseif (\array_key_exists('refreshUrl', $data) && $data['refreshUrl'] === null) { 56 | $object->setRefreshUrl(null); 57 | } 58 | if (\array_key_exists('scopes', $data) && $data['scopes'] !== null) { 59 | $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); 60 | foreach ($data['scopes'] as $key => $value) { 61 | $values[$key] = $value; 62 | } 63 | $object->setScopes($values); 64 | unset($data['scopes']); 65 | } 66 | elseif (\array_key_exists('scopes', $data) && $data['scopes'] === null) { 67 | $object->setScopes(null); 68 | } 69 | foreach ($data as $key_1 => $value_1) { 70 | if (preg_match('/^x-/', (string) $key_1)) { 71 | $object[$key_1] = $value_1; 72 | } 73 | } 74 | return $object; 75 | } 76 | /** 77 | * @return array|string|int|float|bool|\ArrayObject|null 78 | */ 79 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 80 | { 81 | $data = []; 82 | $data['authorizationUrl'] = $object->getAuthorizationUrl(); 83 | if ($object->isInitialized('refreshUrl') && null !== $object->getRefreshUrl()) { 84 | $data['refreshUrl'] = $object->getRefreshUrl(); 85 | } 86 | $values = []; 87 | foreach ($object->getScopes() as $key => $value) { 88 | $values[$key] = $value; 89 | } 90 | $data['scopes'] = $values; 91 | foreach ($object as $key_1 => $value_1) { 92 | if (preg_match('/^x-/', (string) $key_1)) { 93 | $data[$key_1] = $value_1; 94 | } 95 | } 96 | return $data; 97 | } 98 | public function getSupportedTypes(?string $format = null) : array 99 | { 100 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\ImplicitOAuthFlow' => false]; 101 | } 102 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/PasswordOAuthFlowNormalizer.php: -------------------------------------------------------------------------------- 1 | setTokenUrl($data['tokenUrl']); 46 | unset($data['tokenUrl']); 47 | } 48 | elseif (\array_key_exists('tokenUrl', $data) && $data['tokenUrl'] === null) { 49 | $object->setTokenUrl(null); 50 | } 51 | if (\array_key_exists('refreshUrl', $data) && $data['refreshUrl'] !== null) { 52 | $object->setRefreshUrl($data['refreshUrl']); 53 | unset($data['refreshUrl']); 54 | } 55 | elseif (\array_key_exists('refreshUrl', $data) && $data['refreshUrl'] === null) { 56 | $object->setRefreshUrl(null); 57 | } 58 | if (\array_key_exists('scopes', $data) && $data['scopes'] !== null) { 59 | $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); 60 | foreach ($data['scopes'] as $key => $value) { 61 | $values[$key] = $value; 62 | } 63 | $object->setScopes($values); 64 | unset($data['scopes']); 65 | } 66 | elseif (\array_key_exists('scopes', $data) && $data['scopes'] === null) { 67 | $object->setScopes(null); 68 | } 69 | foreach ($data as $key_1 => $value_1) { 70 | if (preg_match('/^x-/', (string) $key_1)) { 71 | $object[$key_1] = $value_1; 72 | } 73 | } 74 | return $object; 75 | } 76 | /** 77 | * @return array|string|int|float|bool|\ArrayObject|null 78 | */ 79 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 80 | { 81 | $data = []; 82 | $data['tokenUrl'] = $object->getTokenUrl(); 83 | if ($object->isInitialized('refreshUrl') && null !== $object->getRefreshUrl()) { 84 | $data['refreshUrl'] = $object->getRefreshUrl(); 85 | } 86 | if ($object->isInitialized('scopes') && null !== $object->getScopes()) { 87 | $values = []; 88 | foreach ($object->getScopes() as $key => $value) { 89 | $values[$key] = $value; 90 | } 91 | $data['scopes'] = $values; 92 | } 93 | foreach ($object as $key_1 => $value_1) { 94 | if (preg_match('/^x-/', (string) $key_1)) { 95 | $data[$key_1] = $value_1; 96 | } 97 | } 98 | return $data; 99 | } 100 | public function getSupportedTypes(?string $format = null) : array 101 | { 102 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\PasswordOAuthFlow' => false]; 103 | } 104 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/ClientCredentialsFlowNormalizer.php: -------------------------------------------------------------------------------- 1 | setTokenUrl($data['tokenUrl']); 46 | unset($data['tokenUrl']); 47 | } 48 | elseif (\array_key_exists('tokenUrl', $data) && $data['tokenUrl'] === null) { 49 | $object->setTokenUrl(null); 50 | } 51 | if (\array_key_exists('refreshUrl', $data) && $data['refreshUrl'] !== null) { 52 | $object->setRefreshUrl($data['refreshUrl']); 53 | unset($data['refreshUrl']); 54 | } 55 | elseif (\array_key_exists('refreshUrl', $data) && $data['refreshUrl'] === null) { 56 | $object->setRefreshUrl(null); 57 | } 58 | if (\array_key_exists('scopes', $data) && $data['scopes'] !== null) { 59 | $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); 60 | foreach ($data['scopes'] as $key => $value) { 61 | $values[$key] = $value; 62 | } 63 | $object->setScopes($values); 64 | unset($data['scopes']); 65 | } 66 | elseif (\array_key_exists('scopes', $data) && $data['scopes'] === null) { 67 | $object->setScopes(null); 68 | } 69 | foreach ($data as $key_1 => $value_1) { 70 | if (preg_match('/^x-/', (string) $key_1)) { 71 | $object[$key_1] = $value_1; 72 | } 73 | } 74 | return $object; 75 | } 76 | /** 77 | * @return array|string|int|float|bool|\ArrayObject|null 78 | */ 79 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 80 | { 81 | $data = []; 82 | $data['tokenUrl'] = $object->getTokenUrl(); 83 | if ($object->isInitialized('refreshUrl') && null !== $object->getRefreshUrl()) { 84 | $data['refreshUrl'] = $object->getRefreshUrl(); 85 | } 86 | if ($object->isInitialized('scopes') && null !== $object->getScopes()) { 87 | $values = []; 88 | foreach ($object->getScopes() as $key => $value) { 89 | $values[$key] = $value; 90 | } 91 | $data['scopes'] = $values; 92 | } 93 | foreach ($object as $key_1 => $value_1) { 94 | if (preg_match('/^x-/', (string) $key_1)) { 95 | $data[$key_1] = $value_1; 96 | } 97 | } 98 | return $data; 99 | } 100 | public function getSupportedTypes(?string $format = null) : array 101 | { 102 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\ClientCredentialsFlow' => false]; 103 | } 104 | } -------------------------------------------------------------------------------- /JsonSchema/Model/OpenApi.php: -------------------------------------------------------------------------------- 1 | initialized); 14 | } 15 | /** 16 | * @var string|null 17 | */ 18 | protected $openapi; 19 | /** 20 | * @var Info|null 21 | */ 22 | protected $info; 23 | /** 24 | * @var ExternalDocumentation|null 25 | */ 26 | protected $externalDocs; 27 | /** 28 | * @var Server[]|null 29 | */ 30 | protected $servers; 31 | /** 32 | * @var array[]|null 33 | */ 34 | protected $security; 35 | /** 36 | * @var Tag[]|null 37 | */ 38 | protected $tags; 39 | /** 40 | * @var PathItem[]|mixed[]|null 41 | */ 42 | protected $paths; 43 | /** 44 | * @var Components|null 45 | */ 46 | protected $components; 47 | /** 48 | * @return string|null 49 | */ 50 | public function getOpenapi() : ?string 51 | { 52 | return $this->openapi; 53 | } 54 | /** 55 | * @param string|null $openapi 56 | * 57 | * @return self 58 | */ 59 | public function setOpenapi(?string $openapi) : self 60 | { 61 | $this->initialized['openapi'] = true; 62 | $this->openapi = $openapi; 63 | return $this; 64 | } 65 | /** 66 | * @return Info|null 67 | */ 68 | public function getInfo() : ?Info 69 | { 70 | return $this->info; 71 | } 72 | /** 73 | * @param Info|null $info 74 | * 75 | * @return self 76 | */ 77 | public function setInfo(?Info $info) : self 78 | { 79 | $this->initialized['info'] = true; 80 | $this->info = $info; 81 | return $this; 82 | } 83 | /** 84 | * @return ExternalDocumentation|null 85 | */ 86 | public function getExternalDocs() : ?ExternalDocumentation 87 | { 88 | return $this->externalDocs; 89 | } 90 | /** 91 | * @param ExternalDocumentation|null $externalDocs 92 | * 93 | * @return self 94 | */ 95 | public function setExternalDocs(?ExternalDocumentation $externalDocs) : self 96 | { 97 | $this->initialized['externalDocs'] = true; 98 | $this->externalDocs = $externalDocs; 99 | return $this; 100 | } 101 | /** 102 | * @return Server[]|null 103 | */ 104 | public function getServers() : ?array 105 | { 106 | return $this->servers; 107 | } 108 | /** 109 | * @param Server[]|null $servers 110 | * 111 | * @return self 112 | */ 113 | public function setServers(?array $servers) : self 114 | { 115 | $this->initialized['servers'] = true; 116 | $this->servers = $servers; 117 | return $this; 118 | } 119 | /** 120 | * @return array[]|null 121 | */ 122 | public function getSecurity() : ?array 123 | { 124 | return $this->security; 125 | } 126 | /** 127 | * @param array[]|null $security 128 | * 129 | * @return self 130 | */ 131 | public function setSecurity(?array $security) : self 132 | { 133 | $this->initialized['security'] = true; 134 | $this->security = $security; 135 | return $this; 136 | } 137 | /** 138 | * @return Tag[]|null 139 | */ 140 | public function getTags() : ?array 141 | { 142 | return $this->tags; 143 | } 144 | /** 145 | * @param Tag[]|null $tags 146 | * 147 | * @return self 148 | */ 149 | public function setTags(?array $tags) : self 150 | { 151 | $this->initialized['tags'] = true; 152 | $this->tags = $tags; 153 | return $this; 154 | } 155 | /** 156 | * @return PathItem[]|mixed[] 157 | */ 158 | public function getPaths() 159 | { 160 | return $this->paths; 161 | } 162 | /** 163 | * @param PathItem[]|mixed[] $paths 164 | * 165 | * @return self 166 | */ 167 | public function setPaths($paths) : self 168 | { 169 | $this->initialized['paths'] = true; 170 | $this->paths = $paths; 171 | return $this; 172 | } 173 | /** 174 | * @return Components|null 175 | */ 176 | public function getComponents() : ?Components 177 | { 178 | return $this->components; 179 | } 180 | /** 181 | * @param Components|null $components 182 | * 183 | * @return self 184 | */ 185 | public function setComponents(?Components $components) : self 186 | { 187 | $this->initialized['components'] = true; 188 | $this->components = $components; 189 | return $this; 190 | } 191 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/HTTPSecuritySchemeNormalizer.php: -------------------------------------------------------------------------------- 1 | setScheme($data['scheme']); 46 | unset($data['scheme']); 47 | } 48 | elseif (\array_key_exists('scheme', $data) && $data['scheme'] === null) { 49 | $object->setScheme(null); 50 | } 51 | if (\array_key_exists('bearerFormat', $data) && $data['bearerFormat'] !== null) { 52 | $object->setBearerFormat($data['bearerFormat']); 53 | unset($data['bearerFormat']); 54 | } 55 | elseif (\array_key_exists('bearerFormat', $data) && $data['bearerFormat'] === null) { 56 | $object->setBearerFormat(null); 57 | } 58 | if (\array_key_exists('description', $data) && $data['description'] !== null) { 59 | $object->setDescription($data['description']); 60 | unset($data['description']); 61 | } 62 | elseif (\array_key_exists('description', $data) && $data['description'] === null) { 63 | $object->setDescription(null); 64 | } 65 | if (\array_key_exists('type', $data) && $data['type'] !== null) { 66 | $object->setType($data['type']); 67 | unset($data['type']); 68 | } 69 | elseif (\array_key_exists('type', $data) && $data['type'] === null) { 70 | $object->setType(null); 71 | } 72 | foreach ($data as $key => $value) { 73 | if (preg_match('/^x-/', (string) $key)) { 74 | $object[$key] = $value; 75 | } 76 | } 77 | return $object; 78 | } 79 | /** 80 | * @return array|string|int|float|bool|\ArrayObject|null 81 | */ 82 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 83 | { 84 | $data = []; 85 | $data['scheme'] = $object->getScheme(); 86 | if ($object->isInitialized('bearerFormat') && null !== $object->getBearerFormat()) { 87 | $data['bearerFormat'] = $object->getBearerFormat(); 88 | } 89 | if ($object->isInitialized('description') && null !== $object->getDescription()) { 90 | $data['description'] = $object->getDescription(); 91 | } 92 | $data['type'] = $object->getType(); 93 | foreach ($object as $key => $value) { 94 | if (preg_match('/^x-/', (string) $key)) { 95 | $data[$key] = $value; 96 | } 97 | } 98 | return $data; 99 | } 100 | public function getSupportedTypes(?string $format = null) : array 101 | { 102 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\HTTPSecurityScheme' => false]; 103 | } 104 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/ServerNormalizer.php: -------------------------------------------------------------------------------- 1 | setUrl($data['url']); 46 | unset($data['url']); 47 | } 48 | elseif (\array_key_exists('url', $data) && $data['url'] === null) { 49 | $object->setUrl(null); 50 | } 51 | if (\array_key_exists('description', $data) && $data['description'] !== null) { 52 | $object->setDescription($data['description']); 53 | unset($data['description']); 54 | } 55 | elseif (\array_key_exists('description', $data) && $data['description'] === null) { 56 | $object->setDescription(null); 57 | } 58 | if (\array_key_exists('variables', $data) && $data['variables'] !== null) { 59 | $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); 60 | foreach ($data['variables'] as $key => $value) { 61 | $values[$key] = $this->denormalizer->denormalize($value, 'Jane\\Component\\OpenApi3\\JsonSchema\\Model\\ServerVariable', 'json', $context); 62 | } 63 | $object->setVariables($values); 64 | unset($data['variables']); 65 | } 66 | elseif (\array_key_exists('variables', $data) && $data['variables'] === null) { 67 | $object->setVariables(null); 68 | } 69 | foreach ($data as $key_1 => $value_1) { 70 | if (preg_match('/^x-/', (string) $key_1)) { 71 | $object[$key_1] = $value_1; 72 | } 73 | } 74 | return $object; 75 | } 76 | /** 77 | * @return array|string|int|float|bool|\ArrayObject|null 78 | */ 79 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 80 | { 81 | $data = []; 82 | $data['url'] = $object->getUrl(); 83 | if ($object->isInitialized('description') && null !== $object->getDescription()) { 84 | $data['description'] = $object->getDescription(); 85 | } 86 | if ($object->isInitialized('variables') && null !== $object->getVariables()) { 87 | $values = []; 88 | foreach ($object->getVariables() as $key => $value) { 89 | $values[$key] = $this->normalizer->normalize($value, 'json', $context); 90 | } 91 | $data['variables'] = $values; 92 | } 93 | foreach ($object as $key_1 => $value_1) { 94 | if (preg_match('/^x-/', (string) $key_1)) { 95 | $data[$key_1] = $value_1; 96 | } 97 | } 98 | return $data; 99 | } 100 | public function getSupportedTypes(?string $format = null) : array 101 | { 102 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Server' => false]; 103 | } 104 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/RequestBodyNormalizer.php: -------------------------------------------------------------------------------- 1 | setDescription($data['description']); 46 | unset($data['description']); 47 | } 48 | elseif (\array_key_exists('description', $data) && $data['description'] === null) { 49 | $object->setDescription(null); 50 | } 51 | if (\array_key_exists('content', $data) && $data['content'] !== null) { 52 | $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); 53 | foreach ($data['content'] as $key => $value) { 54 | $values[$key] = $this->denormalizer->denormalize($value, 'Jane\\Component\\OpenApi3\\JsonSchema\\Model\\MediaType', 'json', $context); 55 | } 56 | $object->setContent($values); 57 | unset($data['content']); 58 | } 59 | elseif (\array_key_exists('content', $data) && $data['content'] === null) { 60 | $object->setContent(null); 61 | } 62 | if (\array_key_exists('required', $data) && $data['required'] !== null) { 63 | $object->setRequired($data['required']); 64 | unset($data['required']); 65 | } 66 | elseif (\array_key_exists('required', $data) && $data['required'] === null) { 67 | $object->setRequired(null); 68 | } 69 | foreach ($data as $key_1 => $value_1) { 70 | if (preg_match('/^x-/', (string) $key_1)) { 71 | $object[$key_1] = $value_1; 72 | } 73 | } 74 | return $object; 75 | } 76 | /** 77 | * @return array|string|int|float|bool|\ArrayObject|null 78 | */ 79 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 80 | { 81 | $data = []; 82 | if ($object->isInitialized('description') && null !== $object->getDescription()) { 83 | $data['description'] = $object->getDescription(); 84 | } 85 | $values = []; 86 | foreach ($object->getContent() as $key => $value) { 87 | $values[$key] = $this->normalizer->normalize($value, 'json', $context); 88 | } 89 | $data['content'] = $values; 90 | if ($object->isInitialized('required') && null !== $object->getRequired()) { 91 | $data['required'] = $object->getRequired(); 92 | } 93 | foreach ($object as $key_1 => $value_1) { 94 | if (preg_match('/^x-/', (string) $key_1)) { 95 | $data[$key_1] = $value_1; 96 | } 97 | } 98 | return $data; 99 | } 100 | public function getSupportedTypes(?string $format = null) : array 101 | { 102 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\RequestBody' => false]; 103 | } 104 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/ExampleNormalizer.php: -------------------------------------------------------------------------------- 1 | setSummary($data['summary']); 46 | unset($data['summary']); 47 | } 48 | elseif (\array_key_exists('summary', $data) && $data['summary'] === null) { 49 | $object->setSummary(null); 50 | } 51 | if (\array_key_exists('description', $data) && $data['description'] !== null) { 52 | $object->setDescription($data['description']); 53 | unset($data['description']); 54 | } 55 | elseif (\array_key_exists('description', $data) && $data['description'] === null) { 56 | $object->setDescription(null); 57 | } 58 | if (\array_key_exists('value', $data) && $data['value'] !== null) { 59 | $object->setValue($data['value']); 60 | unset($data['value']); 61 | } 62 | elseif (\array_key_exists('value', $data) && $data['value'] === null) { 63 | $object->setValue(null); 64 | } 65 | if (\array_key_exists('externalValue', $data) && $data['externalValue'] !== null) { 66 | $object->setExternalValue($data['externalValue']); 67 | unset($data['externalValue']); 68 | } 69 | elseif (\array_key_exists('externalValue', $data) && $data['externalValue'] === null) { 70 | $object->setExternalValue(null); 71 | } 72 | foreach ($data as $key => $value) { 73 | if (preg_match('/^x-/', (string) $key)) { 74 | $object[$key] = $value; 75 | } 76 | } 77 | return $object; 78 | } 79 | /** 80 | * @return array|string|int|float|bool|\ArrayObject|null 81 | */ 82 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 83 | { 84 | $data = []; 85 | if ($object->isInitialized('summary') && null !== $object->getSummary()) { 86 | $data['summary'] = $object->getSummary(); 87 | } 88 | if ($object->isInitialized('description') && null !== $object->getDescription()) { 89 | $data['description'] = $object->getDescription(); 90 | } 91 | if ($object->isInitialized('value') && null !== $object->getValue()) { 92 | $data['value'] = $object->getValue(); 93 | } 94 | if ($object->isInitialized('externalValue') && null !== $object->getExternalValue()) { 95 | $data['externalValue'] = $object->getExternalValue(); 96 | } 97 | foreach ($object as $key => $value) { 98 | if (preg_match('/^x-/', (string) $key)) { 99 | $data[$key] = $value; 100 | } 101 | } 102 | return $data; 103 | } 104 | public function getSupportedTypes(?string $format = null) : array 105 | { 106 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Example' => false]; 107 | } 108 | } -------------------------------------------------------------------------------- /Generator/RequestBodyGenerator.php: -------------------------------------------------------------------------------- 1 | generators[$contentType] = $requestBodyGenerator; 28 | } 29 | } 30 | 31 | public function generateMethodParameter(RequestBody|Reference $requestBody, string $reference, Context $context): ?Param 32 | { 33 | if (!$requestBody->getContent()) { 34 | return null; 35 | } 36 | 37 | $name = 'requestBody'; 38 | [$types, $onlyArray] = $this->getTypes($requestBody, $reference, $context); 39 | $paramType = null; 40 | if (\count($types) === 1 && $types[0] !== AbstractBodyContentGenerator::PHP_TYPE_MIXED) { 41 | $paramType = $types[0]; 42 | } 43 | 44 | if ($onlyArray) { 45 | $paramType = 'array'; 46 | } 47 | 48 | $default = null; 49 | if (!$requestBody->getRequired() || !$context->isStrict()) { 50 | $default = new Expr\ConstFetch(new Name('null')); 51 | $paramType = null === $paramType ? $paramType : "?$paramType"; 52 | } 53 | 54 | return new Param(new Expr\Variable($name), $default, $paramType === null ? $paramType : new Name($paramType)); 55 | } 56 | 57 | public function generateMethodDocParameter(RequestBody|Reference $requestBody, string $reference, Context $context): string 58 | { 59 | [$types] = $this->getTypes($requestBody, $reference, $context); 60 | 61 | if (!$requestBody->getRequired() || !$context->isStrict()) { 62 | array_unshift($types, 'null'); 63 | } 64 | 65 | return \sprintf(' * @param %s $%s', implode('|', $types), 'requestBody'); 66 | } 67 | 68 | private function getTypes(?RequestBody $requestBody, string $reference, Context $context): array 69 | { 70 | $types = []; 71 | 72 | if (!$requestBody || !$requestBody->getContent()) { 73 | return $types; 74 | } 75 | 76 | $onlyArray = null; 77 | 78 | foreach ($requestBody->getContent() as $contentType => $content) { 79 | $generator = $this->defaultRequestBodyGenerator; 80 | 81 | if (isset($this->generators[$contentType])) { 82 | $generator = $this->generators[$contentType]; 83 | } 84 | 85 | [$newTypes, $isArray] = $generator->getTypes($content, $reference . '/content/' . $contentType, $context); 86 | 87 | if ($onlyArray === null) { 88 | $onlyArray = $isArray; 89 | } else { 90 | $onlyArray = $onlyArray && $isArray; 91 | } 92 | 93 | $types = array_merge($types, $newTypes); 94 | } 95 | 96 | return [array_unique($types), $onlyArray]; 97 | } 98 | 99 | public function getSerializeStatements(?RequestBody $requestBody, string $reference, Context $context): array 100 | { 101 | if (!$requestBody || !$requestBody->getContent()) { 102 | return [ 103 | new Stmt\Return_(new Expr\Array_([ 104 | new Expr\Array_(), 105 | new Expr\ConstFetch(new Name('null')), 106 | ])), 107 | ]; 108 | } 109 | 110 | $statements = []; 111 | 112 | foreach ($requestBody->getContent() as $contentType => $content) { 113 | $generator = $this->defaultRequestBodyGenerator; 114 | 115 | if (\array_key_exists($contentType, $this->generators)) { 116 | $generator = $this->generators[$contentType]; 117 | } elseif (str_starts_with($contentType, 'application/json') || str_ends_with($contentType, '+json')) { 118 | $generator = $this->generators['application/json']; 119 | } 120 | 121 | $statements[] = new Stmt\If_( 122 | $generator->getTypeCondition($content, $reference . '/content/' . $contentType, $context), 123 | [ 124 | 'stmts' => $generator->getSerializeStatements($content, $contentType, $reference . '/content/' . $contentType, $context), 125 | ] 126 | ); 127 | } 128 | 129 | $statements[] = new Stmt\Return_(new Expr\Array_([ 130 | new Expr\Array_(), 131 | new Expr\ConstFetch(new Name('null')), 132 | ])); 133 | 134 | return $statements; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /JsonSchema/Normalizer/AuthorizationCodeOAuthFlowNormalizer.php: -------------------------------------------------------------------------------- 1 | setAuthorizationUrl($data['authorizationUrl']); 46 | unset($data['authorizationUrl']); 47 | } 48 | elseif (\array_key_exists('authorizationUrl', $data) && $data['authorizationUrl'] === null) { 49 | $object->setAuthorizationUrl(null); 50 | } 51 | if (\array_key_exists('tokenUrl', $data) && $data['tokenUrl'] !== null) { 52 | $object->setTokenUrl($data['tokenUrl']); 53 | unset($data['tokenUrl']); 54 | } 55 | elseif (\array_key_exists('tokenUrl', $data) && $data['tokenUrl'] === null) { 56 | $object->setTokenUrl(null); 57 | } 58 | if (\array_key_exists('refreshUrl', $data) && $data['refreshUrl'] !== null) { 59 | $object->setRefreshUrl($data['refreshUrl']); 60 | unset($data['refreshUrl']); 61 | } 62 | elseif (\array_key_exists('refreshUrl', $data) && $data['refreshUrl'] === null) { 63 | $object->setRefreshUrl(null); 64 | } 65 | if (\array_key_exists('scopes', $data) && $data['scopes'] !== null) { 66 | $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); 67 | foreach ($data['scopes'] as $key => $value) { 68 | $values[$key] = $value; 69 | } 70 | $object->setScopes($values); 71 | unset($data['scopes']); 72 | } 73 | elseif (\array_key_exists('scopes', $data) && $data['scopes'] === null) { 74 | $object->setScopes(null); 75 | } 76 | foreach ($data as $key_1 => $value_1) { 77 | if (preg_match('/^x-/', (string) $key_1)) { 78 | $object[$key_1] = $value_1; 79 | } 80 | } 81 | return $object; 82 | } 83 | /** 84 | * @return array|string|int|float|bool|\ArrayObject|null 85 | */ 86 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 87 | { 88 | $data = []; 89 | $data['authorizationUrl'] = $object->getAuthorizationUrl(); 90 | $data['tokenUrl'] = $object->getTokenUrl(); 91 | if ($object->isInitialized('refreshUrl') && null !== $object->getRefreshUrl()) { 92 | $data['refreshUrl'] = $object->getRefreshUrl(); 93 | } 94 | if ($object->isInitialized('scopes') && null !== $object->getScopes()) { 95 | $values = []; 96 | foreach ($object->getScopes() as $key => $value) { 97 | $values[$key] = $value; 98 | } 99 | $data['scopes'] = $values; 100 | } 101 | foreach ($object as $key_1 => $value_1) { 102 | if (preg_match('/^x-/', (string) $key_1)) { 103 | $data[$key_1] = $value_1; 104 | } 105 | } 106 | return $data; 107 | } 108 | public function getSupportedTypes(?string $format = null) : array 109 | { 110 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\AuthorizationCodeOAuthFlow' => false]; 111 | } 112 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/XMLNormalizer.php: -------------------------------------------------------------------------------- 1 | setName($data['name']); 46 | unset($data['name']); 47 | } 48 | elseif (\array_key_exists('name', $data) && $data['name'] === null) { 49 | $object->setName(null); 50 | } 51 | if (\array_key_exists('namespace', $data) && $data['namespace'] !== null) { 52 | $object->setNamespace($data['namespace']); 53 | unset($data['namespace']); 54 | } 55 | elseif (\array_key_exists('namespace', $data) && $data['namespace'] === null) { 56 | $object->setNamespace(null); 57 | } 58 | if (\array_key_exists('prefix', $data) && $data['prefix'] !== null) { 59 | $object->setPrefix($data['prefix']); 60 | unset($data['prefix']); 61 | } 62 | elseif (\array_key_exists('prefix', $data) && $data['prefix'] === null) { 63 | $object->setPrefix(null); 64 | } 65 | if (\array_key_exists('attribute', $data) && $data['attribute'] !== null) { 66 | $object->setAttribute($data['attribute']); 67 | unset($data['attribute']); 68 | } 69 | elseif (\array_key_exists('attribute', $data) && $data['attribute'] === null) { 70 | $object->setAttribute(null); 71 | } 72 | if (\array_key_exists('wrapped', $data) && $data['wrapped'] !== null) { 73 | $object->setWrapped($data['wrapped']); 74 | unset($data['wrapped']); 75 | } 76 | elseif (\array_key_exists('wrapped', $data) && $data['wrapped'] === null) { 77 | $object->setWrapped(null); 78 | } 79 | foreach ($data as $key => $value) { 80 | if (preg_match('/^x-/', (string) $key)) { 81 | $object[$key] = $value; 82 | } 83 | } 84 | return $object; 85 | } 86 | /** 87 | * @return array|string|int|float|bool|\ArrayObject|null 88 | */ 89 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 90 | { 91 | $data = []; 92 | if ($object->isInitialized('name') && null !== $object->getName()) { 93 | $data['name'] = $object->getName(); 94 | } 95 | if ($object->isInitialized('namespace') && null !== $object->getNamespace()) { 96 | $data['namespace'] = $object->getNamespace(); 97 | } 98 | if ($object->isInitialized('prefix') && null !== $object->getPrefix()) { 99 | $data['prefix'] = $object->getPrefix(); 100 | } 101 | if ($object->isInitialized('attribute') && null !== $object->getAttribute()) { 102 | $data['attribute'] = $object->getAttribute(); 103 | } 104 | if ($object->isInitialized('wrapped') && null !== $object->getWrapped()) { 105 | $data['wrapped'] = $object->getWrapped(); 106 | } 107 | foreach ($object as $key => $value) { 108 | if (preg_match('/^x-/', (string) $key)) { 109 | $data[$key] = $value; 110 | } 111 | } 112 | return $data; 113 | } 114 | public function getSupportedTypes(?string $format = null) : array 115 | { 116 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\XML' => false]; 117 | } 118 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/EncodingNormalizer.php: -------------------------------------------------------------------------------- 1 | setContentType($data['contentType']); 46 | } 47 | elseif (\array_key_exists('contentType', $data) && $data['contentType'] === null) { 48 | $object->setContentType(null); 49 | } 50 | if (\array_key_exists('headers', $data) && $data['headers'] !== null) { 51 | $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); 52 | foreach ($data['headers'] as $key => $value) { 53 | $values[$key] = $this->denormalizer->denormalize($value, 'Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Header', 'json', $context); 54 | } 55 | $object->setHeaders($values); 56 | } 57 | elseif (\array_key_exists('headers', $data) && $data['headers'] === null) { 58 | $object->setHeaders(null); 59 | } 60 | if (\array_key_exists('style', $data) && $data['style'] !== null) { 61 | $object->setStyle($data['style']); 62 | } 63 | elseif (\array_key_exists('style', $data) && $data['style'] === null) { 64 | $object->setStyle(null); 65 | } 66 | if (\array_key_exists('explode', $data) && $data['explode'] !== null) { 67 | $object->setExplode($data['explode']); 68 | } 69 | elseif (\array_key_exists('explode', $data) && $data['explode'] === null) { 70 | $object->setExplode(null); 71 | } 72 | if (\array_key_exists('allowReserved', $data) && $data['allowReserved'] !== null) { 73 | $object->setAllowReserved($data['allowReserved']); 74 | } 75 | elseif (\array_key_exists('allowReserved', $data) && $data['allowReserved'] === null) { 76 | $object->setAllowReserved(null); 77 | } 78 | return $object; 79 | } 80 | /** 81 | * @return array|string|int|float|bool|\ArrayObject|null 82 | */ 83 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 84 | { 85 | $data = []; 86 | if ($object->isInitialized('contentType') && null !== $object->getContentType()) { 87 | $data['contentType'] = $object->getContentType(); 88 | } 89 | if ($object->isInitialized('headers') && null !== $object->getHeaders()) { 90 | $values = []; 91 | foreach ($object->getHeaders() as $key => $value) { 92 | $values[$key] = $this->normalizer->normalize($value, 'json', $context); 93 | } 94 | $data['headers'] = $values; 95 | } 96 | if ($object->isInitialized('style') && null !== $object->getStyle()) { 97 | $data['style'] = $object->getStyle(); 98 | } 99 | if ($object->isInitialized('explode') && null !== $object->getExplode()) { 100 | $data['explode'] = $object->getExplode(); 101 | } 102 | if ($object->isInitialized('allowReserved') && null !== $object->getAllowReserved()) { 103 | $data['allowReserved'] = $object->getAllowReserved(); 104 | } 105 | return $data; 106 | } 107 | public function getSupportedTypes(?string $format = null) : array 108 | { 109 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Encoding' => false]; 110 | } 111 | } -------------------------------------------------------------------------------- /JsonSchema/Normalizer/ResponsesNormalizer.php: -------------------------------------------------------------------------------- 1 | denormalizer->denormalize($data['default'], 'Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Reference', 'json', $context); 48 | } elseif (is_array($data['default']) and isset($data['default']['description'])) { 49 | $value = $this->denormalizer->denormalize($data['default'], 'Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Response', 'json', $context); 50 | } 51 | $object->setDefault($value); 52 | unset($data['default']); 53 | } 54 | elseif (\array_key_exists('default', $data) && $data['default'] === null) { 55 | $object->setDefault(null); 56 | } 57 | foreach ($data as $key => $value_1) { 58 | if (preg_match('/^[1-5](?:\d{2}|XX)$/', (string) $key)) { 59 | $value_2 = $value_1; 60 | if (is_array($value_1) and isset($value_1['$ref'])) { 61 | $value_2 = $this->denormalizer->denormalize($value_1, 'Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Reference', 'json', $context); 62 | } elseif (is_array($value_1) and isset($value_1['description'])) { 63 | $value_2 = $this->denormalizer->denormalize($value_1, 'Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Response', 'json', $context); 64 | } 65 | $object[$key] = $value_2; 66 | } 67 | if (preg_match('/^x-/', (string) $key)) { 68 | $object[$key] = $value_1; 69 | } 70 | } 71 | return $object; 72 | } 73 | /** 74 | * @return array|string|int|float|bool|\ArrayObject|null 75 | */ 76 | public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null 77 | { 78 | $data = []; 79 | if ($object->isInitialized('default') && null !== $object->getDefault()) { 80 | $value = $object->getDefault(); 81 | if (is_object($object->getDefault())) { 82 | $value = $this->normalizer->normalize($object->getDefault(), 'json', $context); 83 | } elseif (is_object($object->getDefault())) { 84 | $value = $this->normalizer->normalize($object->getDefault(), 'json', $context); 85 | } 86 | $data['default'] = $value; 87 | } 88 | foreach ($object as $key => $value_1) { 89 | if (preg_match('/^[1-5](?:\d{2}|XX)$/', (string) $key)) { 90 | $value_2 = $value_1; 91 | if (is_object($value_1)) { 92 | $value_2 = $this->normalizer->normalize($value_1, 'json', $context); 93 | } elseif (is_object($value_1)) { 94 | $value_2 = $this->normalizer->normalize($value_1, 'json', $context); 95 | } 96 | $data[$key] = $value_2; 97 | } 98 | if (preg_match('/^x-/', (string) $key)) { 99 | $data[$key] = $value_1; 100 | } 101 | } 102 | return $data; 103 | } 104 | public function getSupportedTypes(?string $format = null) : array 105 | { 106 | return ['Jane\\Component\\OpenApi3\\JsonSchema\\Model\\Responses' => false]; 107 | } 108 | } --------------------------------------------------------------------------------