feat: swagger ui

This commit is contained in:
b1ek 2024-08-19 21:26:18 +10:00
parent 926e495a44
commit a5eb1d859b
Signed by: blek
GPG Key ID: 14546221E3595D0C
3 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,12 @@
<?php
namespace app\controllers;
class OpenApiController extends \yii\web\Controller
{
public function actionIndex()
{
return $this->render('index');
}
}

20
views/open-api/index.php Normal file
View File

@ -0,0 +1,20 @@
<?php
/** @var yii\web\View $this */
$this->title = 'OpenAPI spec';
$this->registerJsFile('//unpkg.com/swagger-ui-dist/swagger-ui-bundle.js');
$this->registerCssFile('//unpkg.com/swagger-ui-dist/swagger-ui.css');
$loader = <<< JS
const ui = SwaggerUIBundle({
url: '/openapi.yml',
dom_id: '#swagger-ui'
});
JS;
$this->registerJs($loader, \yii\web\View::POS_END);
?>
<noscript>You need to enable JS to load Swagger UI</noscript>
<div id="swagger-ui"></div>

87
web/openapi.yml Normal file
View File

@ -0,0 +1,87 @@
info:
title: Parameters API
version: '1.0'
openapi: '3.1.0'
tags:
- name: Routes
paths:
/api/list:
get:
tags:
- Routes
summary: Get all parameters
description: Get all parameters
responses:
200:
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Parameter'
example: [
{
"id": 0,
"title": "A thing happening somewhere",
"type": 1,
"icons": null
},
{
"id": 2,
"title": "The fox jumping over a cat",
"type": 1,
"icons": {
"icon": {
"original_name": "fox_jump.jpeg",
"url": "/images/SHA256_HASH.jpeg",
"sha256": "SHA256"
},
"icon_gray": {
"original_name": "fox_jump.gray.jpeg",
"url": "/images/SHA256_HASH.jpeg",
"sha256": "SHA256"
}
}
}
]
components:
schemas:
Image:
type: object
properties:
source_name:
type: string
example: "source_file.jpeg"
url:
type: string
example: "/images/SHA256_HASH.jpeg"
sha256:
type: string
required:
- source_name
- url
- example
Parameter:
type: object
properties:
id:
type: number
example: 0
title:
type: string
example: 'A quick brown fox jumping over a lazy cat'
type:
type: number
example: 0
icons:
type: object
properties:
icon:
$ref: '#/components/schemas/Image'
icon_gray:
$ref: '#/components/schemas/Image'
required:
- id
- title
- type