|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +namespace Membrane\OpenAPIReader\Tests\Fixtures; |
| 8 | + |
| 9 | +use Generator; |
| 10 | +use Membrane\OpenAPIReader\Exception\InvalidOpenAPI; |
| 11 | +use Membrane\OpenAPIReader\ValueObject\Partial; |
| 12 | +use Membrane\OpenAPIReader\ValueObject\Valid\Identifier; |
| 13 | +use Membrane\OpenAPIReader\ValueObject\Valid\Warning; |
| 14 | +use Membrane\OpenAPIReader\ValueObject\Value; |
| 15 | + |
| 16 | +final class ProvidesInvalidatedSchemas |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @return Generator<array{ |
| 20 | + * 0:InvalidOpenAPI, |
| 21 | + * 1:Identifier, |
| 22 | + * 2:Partial\Schema, |
| 23 | + * }> |
| 24 | + */ |
| 25 | + public static function forV3X(): Generator |
| 26 | + { |
| 27 | + $identifier = new Identifier('sut'); |
| 28 | + |
| 29 | + yield 'invalid type' => [ |
| 30 | + InvalidOpenAPI::invalidType($identifier, 'invalid'), |
| 31 | + $identifier, |
| 32 | + new Partial\Schema(type: 'invalid'), |
| 33 | + ]; |
| 34 | + |
| 35 | + yield 'properties without string keys' => [ |
| 36 | + InvalidOpenAPI::mustHaveStringKeys($identifier, 'properties'), |
| 37 | + $identifier, |
| 38 | + new Partial\Schema(properties: [new Partial\Schema()]), |
| 39 | + ]; |
| 40 | + |
| 41 | + yield 'negative maxLength' => [ |
| 42 | + InvalidOpenAPI::keywordMustBeNonNegativeInteger($identifier, 'maxLength'), |
| 43 | + $identifier, |
| 44 | + new Partial\Schema(maxLength: -1), |
| 45 | + ]; |
| 46 | + |
| 47 | + yield 'negative maxItems' => [ |
| 48 | + InvalidOpenAPI::keywordMustBeNonNegativeInteger($identifier, 'maxItems'), |
| 49 | + $identifier, |
| 50 | + new Partial\Schema(maxItems: -1), |
| 51 | + ]; |
| 52 | + |
| 53 | + yield 'negative maxProperties' => [ |
| 54 | + InvalidOpenAPI::keywordMustBeNonNegativeInteger($identifier, 'maxProperties'), |
| 55 | + $identifier, |
| 56 | + new Partial\Schema(maxProperties: -1), |
| 57 | + ]; |
| 58 | + |
| 59 | + yield 'zero multipleOf' => [ |
| 60 | + InvalidOpenAPI::keywordCannotBeZero($identifier, 'multipleOf'), |
| 61 | + $identifier, |
| 62 | + new Partial\Schema(multipleOf: 0), |
| 63 | + ]; |
| 64 | + |
| 65 | + yield 'default does not conform to type' => [ |
| 66 | + InvalidOpenAPI::defaultMustConformToType($identifier), |
| 67 | + $identifier, |
| 68 | + new Partial\Schema(type: 'string', default: new Value(1)), |
| 69 | + ]; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @return Generator<array{ |
| 74 | + * 0:InvalidOpenAPI, |
| 75 | + * 1:Identifier, |
| 76 | + * 2:Partial\Schema, |
| 77 | + * }> |
| 78 | + */ |
| 79 | + public static function forV30(): Generator |
| 80 | + { |
| 81 | + $identifier = new Identifier('sut'); |
| 82 | + |
| 83 | + yield 'numeric exclusiveMaximum' => [ |
| 84 | + InvalidOpenAPI::numericExclusiveMinMaxIn30($identifier, 'exclusiveMaximum'), |
| 85 | + $identifier, |
| 86 | + new Partial\Schema(exclusiveMaximum: 5), |
| 87 | + ]; |
| 88 | + |
| 89 | + yield 'numeric exclusiveMinimum' => [ |
| 90 | + InvalidOpenAPI::numericExclusiveMinMaxIn30($identifier, 'exclusiveMinimum'), |
| 91 | + $identifier, |
| 92 | + new Partial\Schema(exclusiveMinimum: 5), |
| 93 | + ]; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * @return Generator<array{ |
| 98 | + * 0:InvalidOpenAPI, |
| 99 | + * 1:Identifier, |
| 100 | + * 2:Partial\Schema, |
| 101 | + * }> |
| 102 | + */ |
| 103 | + public static function forV31(): Generator |
| 104 | + { |
| 105 | + $identifier = new Identifier('sut'); |
| 106 | + |
| 107 | + yield 'numeric exclusiveMaximum' => [ |
| 108 | + InvalidOpenAPI::boolExclusiveMinMaxIn31($identifier, 'exclusiveMaximum'), |
| 109 | + $identifier, |
| 110 | + new Partial\Schema(exclusiveMaximum: true), |
| 111 | + ]; |
| 112 | + |
| 113 | + yield 'numeric exclusiveMinimum' => [ |
| 114 | + InvalidOpenAPI::boolExclusiveMinMaxIn31($identifier, 'exclusiveMinimum'), |
| 115 | + $identifier, |
| 116 | + new Partial\Schema(exclusiveMinimum: true), |
| 117 | + ]; |
| 118 | + } |
| 119 | +} |
0 commit comments