Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-code-labx committed Jun 2, 2024
2 parents b7baa38 + ef891b9 commit 631eab3
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 54 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Changelog for RESTPresenter

## [1.0.0-rc.2](https://github.com/xtend-packages/rest-presenter/compare/1.0.0-rc.1...1.0.0-rc.2) (2024-05-13)


### Bug Fixes

* Include API key with test generation ([79de5b1](https://github.com/xtend-packages/rest-presenter/commit/79de5b1791e4209a32cea61c992704ac390514cf))

## [1.0.0-rc.1](https://github.com/xtend-packages/rest-presenter/compare/1.0.0-rc.0...1.0.0-rc.1) (2024-05-13)


### Bug Fixes

* No need to remove the API directory via XtendRouter ([c40a819](https://github.com/xtend-packages/rest-presenter/commit/c40a819c5f6defa2afdd39c49ad53dd6881569bf))


### Documentation

* Add info about tests + warning to update phpunit.xml ([bab9042](https://github.com/xtend-packages/rest-presenter/commit/bab904222f88e64a3d025519014334ab96c75f73))

## [1.0.0-rc.0](https://github.com/xtend-packages/rest-presenter/compare/0.11.0...1.0.0-rc.0) (2024-05-13)


### Features

* Extra Security API Key (Enabled by Default) ([b7baa38](https://github.com/xtend-packages/rest-presenter/commit/b7baa380aa8f6caa600a3f04b18a3f431a2d83a5))
* Improve tests + remove service provider ([151bb8b](https://github.com/xtend-packages/rest-presenter/commit/151bb8bc06c3b2ff1867dbdbca1f6b2928558f0c))


### Bug Fixes

* Skip RESTPresenterSetupCommand test issue with expectsChoice ([1a7ee6b](https://github.com/xtend-packages/rest-presenter/commit/1a7ee6b96262bc9a01975266f0eafcc568713659))


### Documentation

* Update for pre-release ([4af1f3d](https://github.com/xtend-packages/rest-presenter/commit/4af1f3d41ae724c9f8eca68cbe08e8ca4479ed8f))

## [0.11.0](https://github.com/xtend-packages/rest-presenter/compare/0.10.1...0.11.0) (2024-05-11)


Expand Down
101 changes: 62 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<picture>
<picture class="filament-hidden">
<source media="(prefers-color-scheme: dark)" srcset="https://www.codelabx.ltd/assets/images/xtend-packages/rest-presenter/rest-presenter-banner-dark.png">
<img alt="XtendLaravel" src="https://www.codelabx.ltd/assets/images/xtend-packages/rest-presenter/rest-presenter-banner-light.png">
</picture>

[![Latest Version on Packagist](https://img.shields.io/packagist/v/xtend-packages/rest-presenter.svg?style=flat-square)](https://packagist.org/packages/xtend-packages/rest-presenter)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/xtend-packages/rest-presenter)](https://packagist.org/packages/xtend-packages/rest-presenter)
[![GitHub License](https://img.shields.io/github/license/xtend-packages/rest-presenter)](https://github.com/xtend-packages/rest-presenter/blob/main/LICENSE.md)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/xtend-packages/rest-presenter/tests.yml?label=tests)](https://github.com/xtend-packages/rest-presenter/actions/workflows/tests.yml)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/xtend-packages/rest-presenter/code-styling.yml?label=code%20style)](https://github.com/xtend-packages/rest-presenter/actions/workflows/code-styling.yml)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/xtend-packages/rest-presenter/phpstan.yml?label=static%20analysis)](https://github.com/xtend-packages/rest-presenter/actions/workflows/phpstan.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/xtend-packages/rest-presenter.svg?style=flat-square)](https://packagist.org/packages/xtend-packages/rest-presenter)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/adam-code-labx)](https://github.com/sponsors/adam-code-labx)
[![GitHub License](https://img.shields.io/github/license/xtend-packages/rest-presenter)](https://github.com/xtend-packages/rest-presenter/blob/main/LICENSE.md)
[![Discord](https://img.shields.io/discord/1033138523584331837?label=Discord&logo=discord)](https://discord.gg/j7EAhVVcyX)

# RESTPresenter

Expand All @@ -22,7 +22,7 @@ Please follow the steps below to get started:

Install package ("minimum-stability": "dev", may be required in your composer.json file):
```bash
composer require xtend-packages/rest-presenter
composer require xtend-packages/rest-presenter:^1.0.0
````
Run the direct setup command for our Filament starter kit to avoid prompts:
```bash
Expand All @@ -32,21 +32,67 @@ To generate your API collection, run the following command below:
```bash
php artisan rest-presenter:generate-api-collection
```

Postman collection generated by default. We also support Insomnia simply set `REST_PRESENTER_EXPORT_PROVIDER=insomnia` in your .env file.
Postman collection generated by default. We also support Insomnia simply by setting the following in your .env file:
```bash
REST_PRESENTER_EXPORT_PROVIDER=insomnia
```

### The following directories with generated files will be created:
- `app/Api/StarterKits/Filament` (contains all generated resources)
- `resources/rest-presenter/postman` (generated Postman collection)
- `resources/rest-presenter/insomnia` (generated Insomnia collection)
- `resources/types/` (generated TypeScript DTOs)
- `tests/StarterKits/Filament` (generated tests)

> **_WARNING:_** Please don't run any tests before you update your phpunit.xml file to include the following:
```xml
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
```
Without this update, it will use your default database connection and refresh the database after each test.
### Tests Failing! Missing Factory Relationships?
If you encounter any issues with the tests, please update your factories to include relationships for your models.\
For example, if you have a Post model but your factory is missing author_id, you will need to update your factory to include this relationship.
### API Collection Auto-Generation
Make sure you only run this command after the setup command to generate your API collection.
```bash
php artisan rest-presenter:generate-api-collection
```
RESTPresenter generates a Postman collection by default.\
To generate an Insomnia collection, set the following in your .env file:
```bash
REST_PRESENTER_EXPORT_PROVIDER=insomnia
```
### Security API Key
Be default RESTPresenter provides a security API key for your API collection.\
The default key is value is `rest-presenter-secret-key`
Please note that the API key is only for local development and should not be used in production.
You can change the API by setting the following in your .env file:
```bash
REST_PRESENTER_AUTH_API_KEY=your-new-secret-key
```
Additionally to opt out of using this feature, set the following in your .env file:
```bash
REST_PRESENTER_AUTH_ENABLE_API_KEY=false
```
### Authentication
RESTPresenter currently provides a simple authentication middleware for your API collection.\
Simply set `public static bool $isAuthenticated = true;` in any resource to use your bearer token for authentication to access the resource.
## Starter Kits
Our initial release includes the following Starter Kits to jumpstart your development:
- [Sanctum Auth Starter Kit](https://github.com/xtend-packages/rest-presenter/discussions/categories/general)
- [Filament API Starter Kit](https://github.com/xtend-packages/rest-presenter/discussions/categories/filament-starter-kit)

## Key Features
- Effortless REST API creation with Laravel API Resources.
Expand All @@ -55,13 +101,20 @@ Our initial release includes the following Starter Kits to jumpstart your develo
- Testing support to ensure reliability and stability.
- Automating API creation from resources in Filament.
- TypeScript auto-generation for API resource DTOs.
- Postman and Insomnia collection generation for easy API testing.
- Secure your API collection with a security API key.
- Simple authentication middleware for your API resources.
## Planned Features
- Release of Sponsorware API Kits for comprehensive API integration.
- Customisable kits providing a solid foundation for API development.
- Future open-sourcing of full kits upon reaching sponsorship milestones.
- Widget API generation for easy integration with your frontend.
- Social Kit for login and registration with social media platforms.
Check out our [Roadmap](https://github.com/orgs/xtend-packages/projects/1/views/1) for upcoming features and improvements. Feel free to open an issue for suggestions or feature requests. Join us on Discord to start a discussion and stay updated on the latest news.\
more to follow soon...
[![Discord](https://img.shields.io/discord/1033138523584331837?label=Discord&logo=discord)](https://discord.gg/j7EAhVVcyX)
## What Makes This Package Unique?
RESTPresenter is more than just a CRUD generator. It offers:
Expand All @@ -71,10 +124,6 @@ RESTPresenter is more than just a CRUD generator. It offers:
- Everything is extendable and customisable to fit your project's needs.
- API Kits to jumpstart your development with pre-built features and resources.

## Roadmap
Check out our [Roadmap](https://github.com/orgs/xtend-packages/projects/1/views/1) for upcoming features and improvements. Feel free to open an issue for suggestions or feature requests. We'll soon be launching our Discord for collaborative discussions.
Meanwhile start a discussion on GitHub to share your thoughts and ideas.

## Requirements

- PHP ^8.2
Expand All @@ -85,7 +134,7 @@ Meanwhile start a discussion on GitHub to share your thoughts and ideas.
You can install the package via composer:

```bash
composer require xtend-packages/rest-presenter
composer require xtend-packages/rest-presenter:^1.0.0
```
Please note: if you receive an error during installing this package, you may need to update your minimum stability requirement to dev in your composer.json file:

Expand Down Expand Up @@ -120,36 +169,10 @@ This command will guide you through creating a new resource. Prompts will allow
### Generate Resources (Blueprint)
Coming soon, leveraging the outstanding capabilities of [Laravel Blueprint](https://blueprint.laravelshift.com/)
### Registering Kits
To register a kit, add it to the starterKits array in the register method of the RESTPresenterServiceProvider. For example:
```php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use XtendPackages\RESTPresenter\Facades\RESTPresenter;
use XtendPackages\RESTPresenter\StarterKits\Auth\Sanctum\SanctumApiKitServiceProvider;
class RESTPresenterServiceProvider extends ServiceProvider
{
public function register(): void
{
RESTPresenter::register($this->app)
->starterKits([
SanctumApiKitServiceProvider::class,
]);
}
}
```
### Configuration
Configure RESTPresenter in the `config/rest-presenter.php` file to customize the package according to your project requirements.
## API Endpoints
Users can import this collection into their Insomnia application to quickly access and test the endpoints provided by RESTPresenter. This file is located [here](https://raw.githubusercontent.com/xtend-packages/rest-presenter/main/resources/insomnia/rest-presenter-Insomnia_2024-04-07.json)
## Testing
RESTPresenter includes a comprehensive testing suite to ensure your API's reliability and stability. Test generators will soon be added to facilitate testing when creating new resources.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xtend-packages/rest-presenter",
"version": "0.11.0",
"version": "1.0.0-rc.2",
"description": "REST API Presenter & Generator for Laravel",
"keywords": [
"code-labx",
Expand Down
10 changes: 8 additions & 2 deletions src/Commands/Generator/stubs/tests/resource.pest.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ describe('{{ modelClassName }}', function (): void {

$response = getJson(
uri: route('api.v1.filament.{{ $modelVarPlural }}.show', ${{ $modelVarSingular }}),
headers: ['x-rest-presenter' => '{{ modelClassName }}'],
headers: [
'x-rest-presenter-api-key' => config('rest-presenter.auth.key'),
'x-rest-presenter' => '{{ modelClassName }}'
],
)->assertOk()->json();

expect($response)
Expand All @@ -29,7 +32,10 @@ describe('{{ modelClassName }}', function (): void {
test('can list all {{ $modelVarPlural }}', function (): void {
$response = getJson(
uri: route('api.v1.filament.{{ $modelVarPlural }}.index'),
headers: ['x-rest-presenter' => '{{ modelClassName }}'],
headers: [
'x-rest-presenter-api-key' => config('rest-presenter.auth.key'),
'x-rest-presenter' => '{{ modelClassName }}'
],
)->assertOk()->json();

expect($response)
Expand Down
10 changes: 8 additions & 2 deletions src/Commands/Generator/stubs/tests/resource.test.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ class {{ testClassName }} extends TestCase
$response = $this->json(
method: 'GET',
uri: route('api.v1.filament.{{ $modelVarPlural }}.show', ${{ $modelVarSingular }}->id),
headers: ['x-rest-presenter' => '{{ modelClassName }}']
headers: [
'x-rest-presenter-api-key' => config('rest-presenter.auth.key'),
'x-rest-presenter' => '{{ modelClassName }}'
],
);

$response->assertStatus(200);
Expand All @@ -58,7 +61,10 @@ class {{ testClassName }} extends TestCase
$response = $this->json(
method: 'GET',
uri: route('api.v1.filament.{{ $modelVarPlural }}.index'),
headers: ['x-rest-presenter' => '{{ modelClassName }}']
headers: [
'x-rest-presenter-api-key' => config('rest-presenter.auth.key'),
'x-rest-presenter' => '{{ modelClassName }}'
],
);

$response->assertStatus(200);
Expand Down
10 changes: 0 additions & 10 deletions src/Support/XtendRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Illuminate\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Routing\PendingResourceRegistration;
use Illuminate\Routing\Router;
use Illuminate\Routing\RouteRegistrar;
Expand All @@ -22,15 +21,6 @@ final class XtendRouter extends Router
public function __construct(Dispatcher $events, ?Container $container = null)
{
parent::__construct($events, $container);

$filesystem = app(Filesystem::class);
if (! $filesystem->isDirectory(app_path('Api'))) {
return;
}
if (! app()->runningUnitTests()) {
return;
}
$filesystem->deleteDirectory(app_path('Api'));
}

public function register(): RouteRegistrar
Expand Down

0 comments on commit 631eab3

Please sign in to comment.