Skip to content

Commit

Permalink
Merge pull request #171 from Stivo182/feat/api
Browse files Browse the repository at this point in the history
feat(api): Добавление swagger
  • Loading branch information
alei1180 authored Jan 28, 2025
2 parents 9aee886 + 0a1e74a commit bf25c08
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 3 deletions.
59 changes: 59 additions & 0 deletions src/interface/view/api.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>API</title>

<!-- favicon -->
<link rel="apple-touch-icon" sizes="57x57" href="/images/favicons/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/images/favicons/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/images/favicons/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/images/favicons/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/images/favicons/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/images/favicons/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/images/favicons/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/images/favicons/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/images/favicons/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/images/favicons/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/images/favicons/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicons/favicon-16x16.png">
<link rel="manifest" href="/images/favicons/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<!-- /favicon -->

<link rel="stylesheet" type="text/css" href="/static/swagger/swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="/static/swagger/index.css" />
</head>

<body>
<div id="swagger-ui"></div>
<script src="/static/swagger/swagger-ui-bundle.js" charset="UTF-8"></script>
<script src="/static/swagger/swagger-ui-standalone-preset.js" charset="UTF-8"></script>
<script>
window.onload = function() {
window.ui = SwaggerUIBundle({
url: "/static/openapi.json",
dom_id: '#swagger-ui',
deepLinking: true,
docExpansion: 'full',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
presets_config: {
SwaggerUIStandalonePreset: {
TopbarPlugin: false
}
},
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
};
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/interface/view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
enableRequests();
};
req.responseType = "json";
req.open("GET", "/convert?lang=" + lang + "&cmd=" + encodeURIComponent(command));
req.open("GET", "/api/v1/convert?lang=" + lang + "&cmd=" + encodeURIComponent(command));
req.send();

disableRequests();
Expand Down
97 changes: 97 additions & 0 deletions src/interface/view/static/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"openapi": "3.1.0",
"info": {
"title": "curlone",
"description": "Конвертер команды curl в код на языке 1С",
"version": "1.0.0"
},
"servers": [
{
"url": "/api/v1"
}
],
"paths": {
"/convert": {
"get": {
"tags": [
"API"
],
"summary": "Конвертирует команду curl в код на 1С",
"parameters": [
{
"name": "cmd",
"in": "query",
"description": "Команда curl",
"required": true,
"explode": true,
"schema": {
"type": "string"
}
},
{
"name": "lang",
"in": "query",
"description": "Язык",
"required": false,
"explode": true,
"schema": {
"type": "string",
"default": "1c",
"enum": [
"1c",
"connector"
]
}
}
],
"responses": {
"200": {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Result"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Result": {
"description": "Результат конвертации",
"type": "object",
"properties": {
"result": {
"description": "Код на 1С",
"type": "string"
},
"errors": {
"description": "Ошибки и предупреждения",
"type": "array",
"items": {
"$ref": "#/components/schemas/Error"
}
}
}
},
"Error": {
"description": "Описание ошибки",
"type": "object",
"properties": {
"text": {
"description": "Текст ошибки",
"type": "string"
},
"critical": {
"description": "Ошибка критичная",
"type": "boolean"
}
}
}
}
}
}
20 changes: 20 additions & 0 deletions src/interface/view/static/swagger/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after {
box-sizing: inherit;
}

body {
margin: 0;
background: #fafafa;
}

.swagger-ui .topbar {
display: none !important;
}
2 changes: 2 additions & 0 deletions src/interface/view/static/swagger/swagger-ui-bundle.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/interface/view/static/swagger/swagger-ui.css

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions src/interface/Классы/ОсновнойКонтрол.os
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Использовать "../../core"

Перем КонвертерКомандыCURL;
Перем КонвертерКомандыCURL; // см. КонвертерКомандыCURL

&Контроллер("/")
Процедура ПриСозданииОбъекта()
Expand All @@ -13,7 +13,18 @@

КонецПроцедуры

&ТочкаМаршрута("/convert")
&ТочкаМаршрута("/api")
Процедура API(Ответ) Экспорт
Ответ.Перенаправить("/api/v1");
КонецПроцедуры

&ТочкаМаршрута("/api/v1")
&Отображение("./src/interface/view/api.html")
Процедура APIv1() Экспорт

КонецПроцедуры

&ТочкаМаршрута("/api/v1/convert")
Процедура Конвертировать(ПараметрыЗапросаИменные, Ответ) Экспорт
Перем Ошибки;

Expand Down

0 comments on commit bf25c08

Please sign in to comment.