Exemple #1
0
 /**
  * @dataProvider schemaProvider
  */
 public function testRessources(SplFileInfo $testDirectory)
 {
     // 1. Cleanup generated
     $filesystem = new Filesystem();
     if ($filesystem->exists($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated')) {
         $filesystem->remove($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     }
     $filesystem->mkdir($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     // 2. Generate
     $jane = Jane::build();
     $jane->generate($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'schema.json', 'Test', 'Joli\\Jane\\Tests\\Expected', $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     // 3. Compare
     $expectedFinder = new Finder();
     $expectedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'expected');
     $generatedFinder = new Finder();
     $generatedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     $generatedData = [];
     $this->assertEquals(count($expectedFinder), count($generatedFinder));
     foreach ($generatedFinder as $generatedFile) {
         $generatedData[$generatedFile->getRelativePathname()] = $generatedFile->getRealPath();
     }
     foreach ($expectedFinder as $expectedFile) {
         $this->assertArrayHasKey($expectedFile->getRelativePathname(), $generatedData);
         if ($expectedFile->isFile()) {
             $this->assertEquals(file_get_contents($expectedFile->getRealPath()), file_get_contents($generatedData[$expectedFile->getRelativePathname()]));
         }
     }
 }
Exemple #2
0
 public function testBothWay()
 {
     $serializer = Jane::buildSerializer();
     $json = file_get_contents(__DIR__ . '/data/json-schema.json');
     $schema = $serializer->deserialize($json, 'Joli\\Jane\\Model\\JsonSchema', 'json');
     $newJson = $serializer->serialize($schema, 'json');
     $this->assertEquals(json_decode($json), json_decode($newJson));
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $jsonSchemaFilepath = $input->getArgument('json-schema-file');
     $rootClassname = $input->getArgument('root-class');
     $namespace = $input->getArgument('namespace');
     $generateDirectory = $input->getArgument('directory');
     $jane = \Joli\Jane\Jane::build();
     $files = $jane->generate($jsonSchemaFilepath, $rootClassname, $namespace, $generateDirectory);
     foreach ($files as $file) {
         $output->writeln(sprintf("Generated %s", $file));
     }
 }
 public static function build()
 {
     $parser = new Parser(new Lexer());
     $resolver = new Resolver(Jane::buildSerializer());
     $bodyParameter = new BodyParameterGenerator($parser, $resolver);
     $pathParameter = new PathParameterGenerator($parser);
     $formDataParameter = new FormDataParameterGenerator($parser);
     $headerParameter = new HeaderParameterGenerator($parser);
     $queryParameter = new QueryParameterGenerator($parser);
     $operation = new OperationGenerator($resolver, $bodyParameter, $formDataParameter, $headerParameter, $pathParameter, $queryParameter);
     $operationManager = new OperationManager();
     $client = new ClientGenerator($operationManager, $operation, new OperationIdNaming());
     return $client;
 }
 public static function build()
 {
     if (class_exists('PhpParser\\ParserFactory')) {
         $parserFactory = new ParserFactory();
         $parser = $parserFactory->create(ParserFactory::PREFER_PHP5);
     } else {
         $parser = new Parser(new Lexer());
     }
     $resolver = new Resolver(Jane::buildSerializer());
     $bodyParameter = new BodyParameterGenerator($parser, $resolver);
     $pathParameter = new PathParameterGenerator($parser);
     $formDataParameter = new FormDataParameterGenerator($parser);
     $headerParameter = new HeaderParameterGenerator($parser);
     $queryParameter = new QueryParameterGenerator($parser);
     $operation = new OperationGenerator($resolver, $bodyParameter, $formDataParameter, $headerParameter, $pathParameter, $queryParameter);
     $operationManager = new OperationManager();
     $operationNaming = new ChainOperationNaming([new OperationIdNaming(), new OperationUrlNaming()]);
     $client = new ClientGenerator($operationManager, $operation, $operationNaming);
     return $client;
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $options = [];
     if ($input->hasOption('config-file')) {
         $configFile = $input->getOption('config-file');
         if (!file_exists($configFile)) {
             throw new \RuntimeException(sprintf('Config file %s does not exist', $configFile));
         }
         $options = (require $configFile);
         if (!is_array($options)) {
             throw new \RuntimeException(sprintf('Invalid config file specified or invalid return type in file %s', $configFile));
         }
     } else {
         if ($input->hasArgument('json-schema-file') && null !== $input->getArgument('json-schema-file')) {
             $options['json-schema-file'] = $input->getArgument('json-schema-file');
         }
         if ($input->hasArgument('root-class') && null !== $input->getArgument('root-class')) {
             $options['root-class'] = $input->getArgument('root-class');
         }
         if ($input->hasArgument('directory') && null !== $input->getArgument('directory')) {
             $options['directory'] = $input->getArgument('directory');
         }
         if ($input->hasArgument('namespace') && null !== $input->getArgument('namespace')) {
             $options['namespace'] = $input->getArgument('namespace');
         }
         if ($input->hasOption('date-format') && null !== $input->getOption('date-format')) {
             $options['date-format'] = $input->getOption('date-format');
         }
         if ($input->hasOption('no-reference') && null !== $input->getOption('no-reference')) {
             $options['reference'] = !$input->getOption('no-reference');
         }
     }
     $options = $this->resolveConfiguration($options);
     $jane = \Joli\Jane\Jane::build($options);
     $files = $jane->generate($options['json-schema-file'], $options['root-class'], $options['namespace'], $options['directory']);
     foreach ($files as $file) {
         $output->writeln(sprintf("Generated %s", $file));
     }
 }
Exemple #7
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$jane = \Joli\Jane\Jane::build();
$jane->generate(__DIR__ . '/../swagger-spec.json', 'Swagger', 'Joli\\Jane\\Swagger', __DIR__ . '/../generated');