Skip to content

Commit

Permalink
docs: oooas
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienbrault committed Apr 22, 2024
1 parent a147afe commit 6612311
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ $label = $instructrice->get(
assert($label === 'positive');
```

You can also use third party json schema libraries like [goldspecdigital/oooas][oooas] to generate the schema:
- [demo/oooas.php](demo/oooas.php)

https://github.com/adrienbrault/instructrice/assets/611271/da69281d-ac56-4135-b2ef-c5e306a56de2

## Supported providers
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"require-dev": {
"ergebnis/composer-normalize": "^2.42",
"goldspecdigital/oooas": "^2.10",
"monolog/monolog": "^3.0",
"php-standard-library/phpstan-extension": "^1.0",
"phpstan/phpstan": "^1.10",
Expand Down
37 changes: 37 additions & 0 deletions demo/oooas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);
use AdrienBrault\Instructrice\Instructrice;
use AdrienBrault\Instructrice\InstructriceFactory;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema;
use Symfony\Component\Console\Output\ConsoleOutputInterface;

$demo = require __DIR__ . '/bootstrap.php';
$demo(function (Instructrice $instructrice, ?string $context, ConsoleOutputInterface $output) {
$instructrice->get(
Schema::object()
->properties(
Schema::string('name'),
Schema::string('dateOfBirth')->format(Schema::FORMAT_DATE_TIME),
Schema::boolean('isAlive'),
Schema::array('significantContributions')
->items(Schema::string()),
)
->toArray(),
'Most impact scientists in history.',
onChunk: InstructriceFactory::createOnChunkDump($output->section()),
);
});

/*
1 array:4 [
"name" => "Marie Curie"
"dateOfBirth" => "1867-11-07"
"isAlive" => false
"significantContributions" => array:3 [
0 => "Pioneered radioactivity research"
1 => "First woman to win a Nobel Prize"
2 => "First person to win two Nobel Prizes in different fields (Physics and Chemistry)"
]
]
*/

0 comments on commit 6612311

Please sign in to comment.