文档:https://github.com/zircote/swagger-php/blob/master/README.md
composer require zircote/swagger-php
./vendor/bin/openapi --help
php vendor/zircote/swagger-php/bin/openapi ./app/Http/Controllers --format yaml -o ./openapi.yaml
php vendor/zircote/swagger-php/bin/openapi ./app/Http/Controllers --format json -o ./openapi.json
Notice: Use of undefined constant JSON_INVALID_UTF8_IGNORE - assumed 'JSON_INVALID_UTF8_IGNORE'
Warning: A non-numeric value encountered使用PHP 7.2 OK
<template>
<div class="app-container">
<div id="swagger-ui"></div>
</div>
</template>
<script>
import SwaggerUIBundle from 'swagger-ui'
import "swagger-ui/dist/swagger-ui.css";
export default {
mounted(){
const ui = SwaggerUIBundle({
url: 'https://petstore.swagger.io/v2/swagger.json',
dom_id: '#swagger-ui',
deepLinking: false,
presets: [
SwaggerUIBundle.presets.apis
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
onComplete: function() {
// Default API key
ui.preauthorizeApiKey("api_key", "abcdefg");
},
// 2: 请求拦截器
// requestInterceptor: (req) => {
// if (! req.loadSpec) {
// // Add the header to "try it out" calls but not spec fetches
// var token = '111111111111111111111';
// req.headers.Authorization = "bearer " + token;
// }
// return req;
// }
})
}
}
</script>
<style lang="less" scoped>
</style>