• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wol-soft / php-json-schema-model-generator / 29452850938

15 Jul 2026 09:41PM UTC coverage: 98.788% (+0.02%) from 98.765%
29452850938

push

github

web-flow
Merge pull request #163 from wol-soft/claude/schema-error-line-numbers-b76c62

Add line/column location reporting to SchemaException

602 of 609 new or added lines in 31 files covered. (98.85%)

7010 of 7096 relevant lines covered (98.79%)

553.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
/src/SchemaProvider/OpenAPIv3Provider.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\SchemaProvider;
6

7
use PHPModelGenerator\Exception\SchemaException;
8
use PHPModelGenerator\Model\SchemaDefinition\JsonSchema;
9

10
class OpenAPIv3Provider implements SchemaProviderInterface
11
{
12
    use RefResolverTrait;
13

14
    /** @var array */
15
    private $openAPIv3Spec;
16

17
    private string $rawSource;
18

19
    /**
20
     * OpenAPIv3Provider constructor.
21
     *
22
     * @throws SchemaException
23
     */
24
    public function __construct(private string $sourceFile)
12✔
25
    {
26
        $this->sourceFile = realpath($this->sourceFile) ?: $this->sourceFile;
12✔
27
        $jsonSchema = file_get_contents($this->sourceFile);
12✔
28

29
        if (!$jsonSchema) {
12✔
NEW
30
            throw new SchemaException("Invalid JSON-Schema file {$this->sourceFile}");
×
31
        }
32

33
        $decoded = json_decode($jsonSchema, true);
12✔
34

35
        if (json_last_error() !== JSON_ERROR_NONE) {
12✔
36
            throw SchemaException::invalidJson($this->sourceFile, $jsonSchema);
1✔
37
        }
38

39
        if (!is_array($decoded)) {
11✔
40
            throw new SchemaException("Invalid JSON-Schema file {$this->sourceFile}");
4✔
41
        }
42

43
        $this->openAPIv3Spec = $decoded;
7✔
44
        $this->rawSource = $jsonSchema;
7✔
45

46
        if (
47
            !isset($this->openAPIv3Spec['components']['schemas']) ||
7✔
48
            empty($this->openAPIv3Spec['components']['schemas'])
7✔
49
        ) {
50
            throw new SchemaException(
3✔
51
                "Open API v3 spec file {$this->sourceFile} doesn't contain any schemas to process",
3✔
52
                new JsonSchema($this->sourceFile, $this->openAPIv3Spec, rawSource: $this->rawSource),
3✔
53
            );
3✔
54
        }
55
    }
56

57
    /**
58
     * @inheritDoc
59
     */
60
    public function getSchemas(): iterable
4✔
61
    {
62
        foreach ($this->openAPIv3Spec['components']['schemas'] as $schemaKey => $schema) {
4✔
63
            // use the key of the current schema as $id if no $id is specified
64
            if (!isset($schema['$id'])) {
4✔
65
                $schema['$id'] = $schemaKey;
4✔
66
            }
67

68
            yield new JsonSchema(
4✔
69
                $this->sourceFile,
4✔
70
                array_merge($this->openAPIv3Spec, $schema),
4✔
71
                "/components/schemas/$schemaKey",
4✔
72
                $this->rawSource,
4✔
73
            );
4✔
74
        }
75
    }
76

77
    /**
78
     * @inheritDoc
79
     */
80
    public function getBaseDirectory(): string
4✔
81
    {
82
        return dirname($this->sourceFile);
4✔
83
    }
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc