PHP code example of swaggest / json-schema-maker

1. Go to this page and download the library: Download swaggest/json-schema-maker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

swaggest / json-schema-maker example snippets


$instanceValue = json_decode(file_get_contents(__DIR__ . '/../resources/github-example.json'));
$schema = new \Swaggest\JsonSchema\Schema();
$f = new \Swaggest\JsonSchemaMaker\SchemaMaker($schema);
$f->options->upgradeIntToNumber = true; // Use `type: number` instead of `type: [integer, number]`.

$f->addInstanceValue($instanceValue);

$schemaJson = json_encode(\Swaggest\JsonSchema\Schema::export($schema));     // With object schemas extracted as definitions.
$schemaJsonInline = json_encode($schema);               // With inline object schemas.

mt_srand(1); // Optionally seed random generator for reproducible results.
$schema = \Swaggest\JsonSchema\Schema::import(json_decode(file_get_contents(__DIR__ . '/../resources/github-example-schema-with-examples.json')));

$instanceFaker = new \Swaggest\JsonSchemaMaker\InstanceFaker($schema);
$value = $instanceFaker->makeValue();
$anotherValue = $instanceFaker->makeValue();