-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJaneOpenApi.php
More file actions
76 lines (67 loc) · 3.35 KB
/
JaneOpenApi.php
File metadata and controls
76 lines (67 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Jane\Component\OpenApi31;
use Jane\Component\JsonSchema\Generator\Naming;
use Jane\Component\JsonSchema\Generator\ValidatorGenerator;
use Jane\Component\JsonSchema\JsonSchema\Normalizer\JsonSchemaNormalizer;
use Jane\Component\OpenApi31\Generator\EndpointGenerator;
use Jane\Component\OpenApi31\Generator\GeneratorFactory;
use Jane\Component\OpenApi31\Guesser\OpenApiSchema\GuesserFactory;
use Jane\Component\OpenApi31\Normalizer\SchemaDenormalizer;
use Jane\Component\OpenApi31\Normalizer\SecuritySchemeDenormalizer;
use Jane\Component\OpenApi31\SchemaParser\SchemaParser;
use Jane\Component\OpenApiCommon\Generator\AuthenticationGenerator;
use Jane\Component\OpenApiCommon\Generator\ModelGenerator;
use Jane\Component\OpenApiCommon\Generator\NormalizerGenerator;
use Jane\Component\OpenApiCommon\Generator\RuntimeGenerator;
use Jane\Component\OpenApiCommon\JaneOpenApi as CommonJaneOpenApi;
use PhpParser\ParserFactory;
use Symfony\Component\Serializer\Encoder\JsonDecode;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\YamlEncoder;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Yaml\Dumper;
use Symfony\Component\Yaml\Parser;
class JaneOpenApi extends CommonJaneOpenApi
{
protected const OBJECT_NORMALIZER_CLASS = JsonSchema\Normalizer\JaneObjectNormalizer::class;
protected const WHITELIST_FETCH_CLASS = WhitelistedSchema::class;
protected static function create(array $options = []): CommonJaneOpenApi
{
$serializer = self::buildSerializer();
return new self(
SchemaParser::class,
GuesserFactory::create($serializer, $options),
$options['strict'] ?? true
);
}
protected static function generators(DenormalizerInterface $denormalizer, array $options = []): \Generator
{
$naming = new Naming();
$parser = (new ParserFactory())->createForHostVersion();
yield new ModelGenerator($naming, $parser);
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);
yield new AuthenticationGenerator();
yield GeneratorFactory::build($denormalizer, $options['endpoint-generator'] ?: EndpointGenerator::class);
yield new RuntimeGenerator($naming, $parser);
if ($options['validation'] ?? false) {
yield new ValidatorGenerator($naming);
}
}
public static function buildSerializer(): SerializerInterface|DenormalizerInterface|NormalizerInterface
{
$encoders = [
new JsonEncoder(new JsonEncode([JsonEncode::OPTIONS => \JSON_UNESCAPED_SLASHES]), new JsonDecode()),
new YamlEncoder(new Dumper(), new Parser()),
];
return new Serializer([
new SchemaDenormalizer(),
new SecuritySchemeDenormalizer(),
new JsonSchemaNormalizer(),
new JsonSchema\Normalizer\JaneObjectNormalizer(),
], $encoders);
}
}