Skip to content

Commit

Permalink
chore: json schema everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
mcharytoniuk committed Jan 13, 2024
1 parent e1c580e commit 938154b
Show file tree
Hide file tree
Showing 23 changed files with 642 additions and 276 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"league/commonmark": "^2.4",
"league/oauth2-server": "^8.5",
"nette/php-generator": "^4.1",
"nette/schema": "^1.2",
"nicmart/tree": "^0.7.2",
"nyholm/psr7": "^1.8",
"nyholm/psr7-server": "^1.1",
Expand All @@ -48,7 +47,7 @@
"webonyx/graphql-php": "^15.6",
"dragonmantank/cron-expression": "^3.3",
"league/oauth2-client": "^2.7",
"justinrainbow/json-schema": "^5.2"
"opis/json-schema": "^2.3"
},
"require-dev": {
"mockery/mockery": "^1.6",
Expand Down
262 changes: 191 additions & 71 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ default[timeout] = 1
default[pool_prefill] = false
default[pool_size] = 8

[sentry]
dsn =

[session]
cookie_lifespan = 86400
cookie_name = dmsession
Expand Down
23 changes: 16 additions & 7 deletions docs/pages/docs/features/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ readonly class ManifestConfiguration
```

Then you need to define the configuration provider.
[nette/schema](https://doc.nette.org/en/schema) is used for config validation:
[JSON Schema](https://json-schema.org/) is used for config validation:

```php
<?php
Expand All @@ -169,9 +169,8 @@ namespace App\SingletonProvider\ConfigurationProvider;

use App\ManifestConfiguration;
use Distantmagic\Resonance\Attribute\Singleton;
use Distantmagic\Resonance\JsonSchema;
use Distantmagic\Resonance\SingletonProvider\ConfigurationProvider;
use Nette\Schema\Expect;
use Nette\Schema\Schema;

/**
* @template-extends ConfigurationProvider<ManifestConfiguration, object{
Expand All @@ -187,11 +186,21 @@ final readonly class ManifestConfigurationProvider extends ConfigurationProvider
return 'manifest';
}

protected function getSchema(): Schema
protected function getSchema(): JsonSchema
{
return Expect::structure([
'background_color' => Expect::string()->min(1)->required(),
'theme_color' => Expect::string()->min(1)->required(),
return new JsonSchema([
'type' => 'object',
'properties' => [
'background_color' => [
'type' => 'string',
'minLength' => 1,
],
'theme_color' => [
'type' => 'string',
'minLength' => 1,
]
],
'required' => ['background_color', 'theme_color']
]);
}

Expand Down
Loading

0 comments on commit 938154b

Please sign in to comment.