Skip to content

Commit f043d4e

Browse files
author
RobertGroot
committed
Initial version
0 parents  commit f043d4e

23 files changed

+9762
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
.php-cs.cache

README.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# OpenAPI Generator using Laravel Data
2+
3+
Generate OpenAPI specification from Laravel routes and Laravel Data objects
4+
5+
# Install
6+
7+
## Add composer repository
8+
9+
In `composer.json` add:
10+
11+
```json
12+
"repositories": [
13+
{
14+
"type": "gitlab",
15+
"url": "https://gitlab.com/xolvio-nl/laravel-data-openapi-generator"
16+
}
17+
],
18+
```
19+
20+
## Add GitLab auth token
21+
22+
1. Create Auth token with api or api_read rights: https://gitlab.com/-/profile/personal_access_tokens
23+
2. Run `composer config --global --auth gitlab-token.gitlab.com TOKEN_HERE`
24+
25+
## Install
26+
27+
`composer require xolvio/laravel-data-openapi-generator:dev-main`
28+
29+
# Optional
30+
31+
## Version
32+
33+
Add a `app.version` config in `app.php` to set the version in the openapi specification:
34+
```php
35+
'version' => env('APP_VERSION', '1.0.0'),
36+
```
37+
38+
## Vite PWA config
39+
40+
If using `vite-plugin-pwa`, make sure to exclude '/api/' routes from the serviceworker using this config:
41+
42+
```ts
43+
VitePWA({
44+
workbox: {
45+
navigateFallbackDenylist: [
46+
new RegExp('/api/.+'),
47+
],
48+
},
49+
})
50+
```
51+
52+
## Vue page
53+
54+
```vue
55+
<route lang="json">
56+
{
57+
"meta": {
58+
"public": true
59+
}
60+
}
61+
</route>
62+
63+
<template>
64+
<iframe
65+
:src="url"
66+
style="width: calc(100vw - 40px);height: calc(100vh - 80px); border: none;"
67+
/>
68+
</template>
69+
70+
<script lang="ts" setup>
71+
const url = `${import.meta.env.VITE_APP_URL}/api/openapi`;
72+
</script>
73+
```
74+
75+
# Usage
76+
77+
## Config
78+
79+
`php artisan vendor:publish --tag=openapi-generator-config`
80+
81+
## Generate
82+
83+
`php artisan openapi:generate`
84+
85+
## View
86+
87+
Swagger available at `APP_URL/api/openapi`

composer.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "xolvio/laravel-data-openapi-generator",
3+
"description": "Generate OpenAPI specification from Laravel routes and Laravel Data objects.",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"Xolvio\\OpenApiGenerator\\": "src/"
9+
}
10+
},
11+
"extra": {
12+
"laravel": {
13+
"providers": [
14+
"Xolvio\\OpenApiGenerator\\OpenApiServiceProvider"
15+
]
16+
}
17+
},
18+
"authors": [
19+
{
20+
"name": "Robert Groot",
21+
"email": "[email protected]"
22+
}
23+
],
24+
"minimum-stability": "dev",
25+
"prefer-stable": true,
26+
"scripts": {
27+
"format": [
28+
"@php ./vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --verbose --config=./php-cs.php --path-mode=intersection . --ansi"
29+
],
30+
"larastan": [
31+
"vendor/bin/phpstan analyse"
32+
]
33+
},
34+
"require": {
35+
"spatie/laravel-data": "^1",
36+
"laravel/framework": "^8|^9",
37+
"phpdocumentor/reflection-docblock": "^5.3",
38+
"spatie/invade": "^1.0"
39+
},
40+
"require-dev": {
41+
"friendsofphp/php-cs-fixer": "^3.8",
42+
"nunomaduro/larastan": "^2.1",
43+
"orchestra/testbench": "^7.5"
44+
}
45+
}

0 commit comments

Comments
 (0)