Generate OpenAPI specification from Laravel routes and Laravel Data objects
In composer.json
add this repository:
"repositories": [
{
"type": "github",
"url": "https://github.com/xolvionl/laravel-data-openapi-generator"
}
],
composer require xolvio/laravel-data-openapi-generator
Add a app.version
config in app.php
to set the version in the openapi specification:
'version' => env('APP_VERSION', '1.0.0'),
If using vite-plugin-pwa
, make sure to exclude '/api/' routes from the serviceworker using this config:
VitePWA({
workbox: {
navigateFallbackDenylist: [
new RegExp('/api/.+'),
],
},
})
<route lang="json">
{
"meta": {
"public": true
}
}
</route>
<template>
<iframe
:src="url"
style="width: calc(100vw - 40px);height: calc(100vh - 80px); border: none;"
/>
</template>
<script lang="ts" setup>
const url = `${import.meta.env.VITE_APP_URL}/api/openapi`;
</script>
php artisan vendor:publish --tag=openapi-generator-config
php artisan openapi:generate
Swagger available at APP_URL/api/openapi