PHP code example of swaggest / go-code-builder
1. Go to this page and download the library: Download swaggest/go-code-builder 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 / go-code-builder example snippets
namespace MyApp;
use Swaggest\GoCodeBuilder\JsonSchema\GoBuilder;
use Swaggest\GoCodeBuilder\JsonSchema\StructHookCallback;
use Swaggest\GoCodeBuilder\Templates\GoFile;
use Swaggest\GoCodeBuilder\Templates\Struct\StructDef;
use Swaggest\JsonSchema\Schema;
) {
if ('#' === $path) {
$structDef->setName('SwaggerSchema');
} elseif (0 === strpos($path, '#/definitions/')) {
$name = $builder->codeBuilder->exportableName(substr($path, strlen('#/definitions/')));
$structDef->setName($name);
}
});
$builder->getType($schema);
$goFile = new GoFile('swagger');
foreach ($builder->getGeneratedStructs() as $generatedStruct) {
$goFile->getCode()->addSnippet($generatedStruct->structDef);
}
$goFile->getCode()->addSnippet($builder->getCode());