forked from byte-it/openapi-spec-generator
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from swisnl/non-eloquent-resources
Generate documentation for non eloquent resources without extra configuration
- Loading branch information
Showing
15 changed files
with
413 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"example": { | ||
"domain": "johnsmith.com", | ||
"name": "Johns site" | ||
}, | ||
"foo": { | ||
"domain": "foo.bar", | ||
"name": "Foo Bar" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace LaravelJsonApi\OpenApiSpec\Tests\Support\Controllers\Api\V1; | ||
|
||
use LaravelJsonApi\Laravel\Http\Controllers\Actions; | ||
use LaravelJsonApi\OpenApiSpec\Tests\Support\Controllers\Controller; | ||
|
||
class SiteController extends Controller | ||
{ | ||
use Actions\FetchMany; | ||
use Actions\FetchOne; | ||
use Actions\Store; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelJsonApi\OpenApiSpec\Tests\Support\Entities; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
|
||
class Site implements Arrayable | ||
{ | ||
private string $slug; | ||
|
||
private ?string $domain; | ||
|
||
private ?string $name; | ||
|
||
public static function fromArray(string $slug, array $values): self | ||
{ | ||
$site = new self($slug); | ||
$site->setDomain($values['domain'] ?? null); | ||
$site->setName($values['name'] ?? null); | ||
|
||
return $site; | ||
} | ||
|
||
public function __construct(string $slug) | ||
{ | ||
$this->slug = $slug; | ||
} | ||
|
||
public function getSlug(): string | ||
{ | ||
return $this->slug; | ||
} | ||
|
||
public function getDomain(): ?string | ||
{ | ||
return $this->domain; | ||
} | ||
|
||
public function setDomain(?string $domain): Site | ||
{ | ||
$this->domain = $domain; | ||
|
||
return $this; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(?string $name): Site | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
$this->getDomain(), | ||
$this->getName(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelJsonApi\OpenApiSpec\Tests\Support\Entities; | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
|
||
class SiteStorage | ||
{ | ||
protected Filesystem $files; | ||
|
||
/** | ||
* @var array<int, array<string, mixed> | ||
*/ | ||
protected array $sites; | ||
|
||
public function __construct(Filesystem $files) | ||
{ | ||
$this->files = $files; | ||
$this->sites = json_decode($files->get('sites.json'), true); | ||
} | ||
|
||
public function find(string $slug): ?Site | ||
{ | ||
if (!isset($this->sites[$slug])) { | ||
return null; | ||
} | ||
|
||
return Site::fromArray($slug, $this->sites[$slug]); | ||
} | ||
|
||
public function cursor(): \Generator | ||
{ | ||
foreach ($this->sites as $slug => $values) { | ||
yield $slug => Site::fromArray($slug, $values); | ||
} | ||
} | ||
|
||
public function all(): array | ||
{ | ||
return iterator_to_array($this->cursor()); | ||
} | ||
|
||
public function store(Site $site): void | ||
{ | ||
$this->sites[$site->getSlug()] = $site->toArray(); | ||
|
||
$this->write(); | ||
} | ||
|
||
public function remove(Site $site): void | ||
{ | ||
unset($this->sites[$site->getSlug()]); | ||
|
||
$this->write(); | ||
} | ||
|
||
public function write(): void | ||
{ | ||
$this->files->put('sites.json', json_encode($this->sites)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.