From a5eb1d859b43c3797223b6ea47316e76ec20b94f Mon Sep 17 00:00:00 2001 From: b1ek Date: Mon, 19 Aug 2024 21:26:18 +1000 Subject: [PATCH] feat: swagger ui --- controllers/OpenApiController.php | 12 +++++ views/open-api/index.php | 20 +++++++ web/openapi.yml | 87 +++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 controllers/OpenApiController.php create mode 100644 views/open-api/index.php create mode 100644 web/openapi.yml diff --git a/controllers/OpenApiController.php b/controllers/OpenApiController.php new file mode 100644 index 0000000..e6a5001 --- /dev/null +++ b/controllers/OpenApiController.php @@ -0,0 +1,12 @@ +render('index'); + } + +} diff --git a/views/open-api/index.php b/views/open-api/index.php new file mode 100644 index 0000000..9e501ac --- /dev/null +++ b/views/open-api/index.php @@ -0,0 +1,20 @@ +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); + +?> + + +
diff --git a/web/openapi.yml b/web/openapi.yml new file mode 100644 index 0000000..9a0c288 --- /dev/null +++ b/web/openapi.yml @@ -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 \ No newline at end of file