mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-15 05:10:47 +08:00
docs: swagger文档
This commit is contained in:
parent
13eae459dd
commit
6dfb9bbcf0
BIN
doc/images/usage/chrome-4.jpg
Normal file
BIN
doc/images/usage/chrome-4.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 127 KiB |
BIN
doc/images/usage/chrome-5.jpg
Normal file
BIN
doc/images/usage/chrome-5.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 310 KiB |
BIN
doc/images/usage/chrome-6.jpg
Normal file
BIN
doc/images/usage/chrome-6.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 927 KiB |
@ -28,4 +28,19 @@
|
||||
|
||||
3.打开yapi平台,进入到项目页面,点击数据管理,选择相应的分组和har导入方式,选择刚才保存的文件路径,开始导入数据
|
||||
|
||||
<div><img class="doc-img" style="width:50%" src="./images/usage/chrome-3.jpg" /></div>
|
||||
<div><img class="doc-img" style="width:50%" src="./images/usage/chrome-3.jpg" /></div>
|
||||
|
||||
## Swagger 数据导入
|
||||
<p>什么是 Swagger ?</p>
|
||||
<div>[Swagger从入门到精通](https://www.gitbook.com/book/huangwenchao/swagger/details)</div>
|
||||
|
||||
<br />
|
||||
1.生成 JSON 语言编写的 Swagger API 文档文件<div> 例如这样的数据 (<a href="http://petstore.swagger.io/v2/swagger.json" target="blank">http://petstore.swagger.io/v2/swagger.json</a>),可以将其内容复制到 JSON 文件中。</div>
|
||||
|
||||
2.打开yapi平台,进入到项目页面,点击数据管理,选择相应的分组和swagger导入方式,选择刚才的文件,开始导入数据
|
||||
|
||||
<div><img class="doc-img" style="width:50%" src="./images/usage/chrome-4.jpg" /></div>
|
||||
|
||||
<div><img class="doc-img" style="width:90%" src="./images/usage/chrome-5.jpg" /></div>
|
||||
|
||||
<div><img class="doc-img" style="width:90%" src="./images/usage/chrome-6.jpg" /></div>
|
@ -142,6 +142,10 @@
|
||||
<li >
|
||||
<a href="#HAR_数据导入">HAR 数据导入</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="#Swagger_数据导入">Swagger 数据导入</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
@ -178,6 +182,18 @@
|
||||
|
||||
<p>3.打开yapi平台,进入到项目页面,点击数据管理,选择相应的分组和har导入方式,选择刚才保存的文件路径,开始导入数据</p>
|
||||
<div><img class="doc-img" style="width:50%" src="./images/usage/chrome-3.jpg" /></div>
|
||||
|
||||
<h2 class="subject" id="Swagger_数据导入">Swagger 数据导入 <a class="hashlink" href="#Swagger_数据导入">#</a></h2><p><p>什么是 Swagger ?</p></p>
|
||||
<div><a href="https://www.gitbook.com/book/huangwenchao/swagger/details">Swagger从入门到精通</a></div>
|
||||
|
||||
<p><br />
|
||||
1.生成 JSON 语言编写的 Swagger API 文档文件<div> 例如这样的数据 (<a href="http://petstore.swagger.io/v2/swagger.json" target="blank">http://petstore.swagger.io/v2/swagger.json</a>),可以将其内容复制到 JSON 文件中。</div></p>
|
||||
<p>2.打开yapi平台,进入到项目页面,点击数据管理,选择相应的分组和swagger导入方式,选择刚才的文件,开始导入数据</p>
|
||||
<div><img class="doc-img" style="width:50%" src="./images/usage/chrome-4.jpg" /></div>
|
||||
|
||||
<div><img class="doc-img" style="width:90%" src="./images/usage/chrome-5.jpg" /></div>
|
||||
|
||||
<div><img class="doc-img" style="width:90%" src="./images/usage/chrome-6.jpg" /></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
BIN
static/doc/images/usage/chrome-4.jpg
Normal file
BIN
static/doc/images/usage/chrome-4.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 127 KiB |
BIN
static/doc/images/usage/chrome-5.jpg
Normal file
BIN
static/doc/images/usage/chrome-5.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 310 KiB |
BIN
static/doc/images/usage/chrome-6.jpg
Normal file
BIN
static/doc/images/usage/chrome-6.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 927 KiB |
@ -175,14 +175,14 @@
|
||||
<pre><code>mockd地址: http<span class="token operator">:</span>//yapi.corp.qunar.com/mock/<span class="token number">29</span>/api/hackathon/login
|
||||
</code></pre><p> 注:项目id可以在项目设置里查看到</p>
|
||||
<h2 class="subject" id="定义mock数据示例">定义mock数据示例 <a class="hashlink" href="#定义mock数据示例">#</a></h2><pre><code><span class="token punctuation">{</span>
|
||||
<span class="token property">"status|0-1"</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> //接口状态
|
||||
"status|<span class="token number">0</span>-<span class="token number">1</span>"<span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> //接口状态
|
||||
<span class="token property">"message"</span><span class="token operator">:</span> <span class="token string">"请求完成"</span><span class="token punctuation">,</span> //消息提示
|
||||
<span class="token property">"data"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token property">"counts"</span><span class="token operator">:</span><span class="token string">"@integer"</span><span class="token punctuation">,</span> //统计数量
|
||||
<span class="token property">"totalSubjectType|4-10"</span><span class="token operator">:</span> <span class="token punctuation">[</span> //<span class="token number">4</span>-<span class="token number">10</span>意味着可以随机生成<span class="token number">4</span>-<span class="token number">10</span>组数据
|
||||
"totalSubjectType|<span class="token number">4</span>-<span class="token number">10</span>"<span class="token operator">:</span> <span class="token punctuation">[</span> //<span class="token number">4</span>-<span class="token number">10</span>意味着可以随机生成<span class="token number">4</span>-<span class="token number">10</span>组数据
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token property">"subjectName|regexp"</span><span class="token operator">:</span> <span class="token string">"大数据|机器学习|工具"</span><span class="token punctuation">,</span> //主题名
|
||||
<span class="token property">"subjectType|+1"</span><span class="token operator">:</span> <span class="token number">1</span> //类型
|
||||
"subjectName|regexp"<span class="token operator">:</span> "大数据|机器学习|工具<span class="token string">", //主题名
|
||||
"</span>subjectType|+<span class="token number">1</span>"<span class="token operator">:</span> <span class="token number">1</span> //类型
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">]</span><span class="token punctuation">,</span>
|
||||
<span class="token property">"data"</span><span class="token operator">:</span><span class="token punctuation">[</span>
|
||||
@ -195,8 +195,8 @@
|
||||
<span class="token punctuation">}</span>
|
||||
</code></pre><h2 class="subject" id="YApi_Mock_跟_mockjs_区别">YApi Mock 跟 mockjs 区别 <a class="hashlink" href="#YApi_Mock_跟_mockjs_区别">#</a></h2><p>1 因为 yapi 基于 json 定义 mock ,无法使用 mockjs 原有的函数功能,正则表达式需要基于 rule 书写,示例如下:</p>
|
||||
<pre><code><span class="token punctuation">{</span>
|
||||
<span class="token property">"name|regexp"</span><span class="token operator">:</span> <span class="token string">"[a-z0-9_]+?"</span><span class="token punctuation">,</span>
|
||||
<span class="token property">"type|regexp"</span><span class="token operator">:</span> <span class="token string">"json|text|xml"</span> //枚举数据类型可这样实现
|
||||
"name|regexp"<span class="token operator">:</span> <span class="token string">"[a-z0-9_]+?"</span><span class="token punctuation">,</span>
|
||||
"type|regexp"<span class="token operator">:</span> "json|text|xml" //枚举数据类型可这样实现
|
||||
<span class="token punctuation">}</span>
|
||||
</code></pre><p>2 支持替换请求的query,body参数</p>
|
||||
<pre><code><span class="token punctuation">{</span>
|
||||
@ -240,9 +240,9 @@ $<span class="token punctuation">.</span><span class="token function">post</span
|
||||
<p><a href="#DPD">2. 数据占位符定义规范(Data Placeholder Definition,DPD)</a></p>
|
||||
<p><span id = "DTD"></span></p>
|
||||
<h3 class="subject" id="数据模板定义规范(Data_Template_Definition,DTD)">数据模板定义规范(Data Template Definition,DTD) <a class="hashlink" href="#数据模板定义规范(Data_Template_Definition,DTD)">#</a></h3><p>数据模板中的每个属性由 3 部分构成:属性名、生成规则、属性值:</p>
|
||||
<pre><code>// 属性名 name (与生成规则之间用 <span class="token string">"|"</span> 隔开)
|
||||
// 生成规则 rule(生成规则有<span class="token number">7</span>种详见下面的生成规则)
|
||||
// 属性值 value(可以含有 <span class="token string">"@占位符"</span> 同时也指定了最终值的初始值和类型)
|
||||
<pre><code>// 属性名 name (与生成规则之间用 "|<span class="token string">" 隔开)
|
||||
// 生成规则 rule(生成规则有7种详见下面的生成规则)
|
||||
// 属性值 value(可以含有 "</span>@占位符" 同时也指定了最终值的初始值和类型)
|
||||
|
||||
'name|rule'<span class="token operator">:</span> value
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
var EXAMPLE_MAX_HEIGHT = 98,
|
||||
DEFAULT_SHOW_PARAMS = 5;
|
||||
|
||||
$(document).ready(function() {
|
||||
// 移动端导航
|
||||
var $openPanel = $('.open-panel');
|
||||
@ -8,6 +11,7 @@ $(document).ready(function() {
|
||||
var $versionSelector = $('.version-selector');
|
||||
var $versionMask = $('.m-version-mask');
|
||||
var isPanelHide = true;
|
||||
var winWidth = $(window).width();
|
||||
var h2 = $('.content-right').find('h2');
|
||||
var h3 = $('.content-right').find('h3');
|
||||
var a = $('.content-left').find('a');
|
||||
@ -121,6 +125,7 @@ $(document).ready(function() {
|
||||
})
|
||||
$versionSelector.click(function(e) {
|
||||
$versionMask.show();
|
||||
console.log('e');
|
||||
});
|
||||
|
||||
$('.markdown-body pre').map(function(i, item) {
|
||||
@ -128,61 +133,59 @@ $(document).ready(function() {
|
||||
$(item).children('code').addClass('js-code-'+i);
|
||||
});
|
||||
|
||||
// var winHeight = $(window).height() - 44,
|
||||
// sidebar = $('.docs-sidebar');
|
||||
var winHeight = $(window).height() - 44,
|
||||
sidebar = $('.docs-sidebar');
|
||||
var docSideNav = $('.docs-sidenav');
|
||||
if (winWidth > 767) {
|
||||
docSideNav.width($contentLeftWidth);
|
||||
}
|
||||
if (sidebar.height() > winHeight) {
|
||||
sidebar.css('max-height', winHeight + 'px');
|
||||
$('.docs-sidenav').css('max-height', winHeight + 'px');
|
||||
if (winWidth < 768) {
|
||||
$('.docs-sidenav').css({
|
||||
'overflow-x': 'hidden'
|
||||
});
|
||||
}
|
||||
var activeMenu,
|
||||
barScroll = false;
|
||||
|
||||
// var docSideNav = $('.docs-sidenav');
|
||||
// if (winWidth > 767) {
|
||||
// docSideNav.width($contentLeftWidth);
|
||||
// }
|
||||
sidebar.on('mouseover', function() {
|
||||
barScroll = true;
|
||||
});
|
||||
sidebar.on('mouseout', function() {
|
||||
barScroll = false;
|
||||
});
|
||||
};
|
||||
|
||||
// if (sidebar.height() > winHeight) {
|
||||
// sidebar.css('max-height', winHeight + 'px');
|
||||
// $('.docs-sidenav').css('max-height', winHeight + 'px');
|
||||
// if (winWidth < 768) {
|
||||
// $('.docs-sidenav').css({
|
||||
// 'overflow-x': 'hidden'
|
||||
// });
|
||||
// }
|
||||
// var activeMenu,
|
||||
// barScroll = false;
|
||||
//
|
||||
// sidebar.on('mouseover', function() {
|
||||
// barScroll = true;
|
||||
// });
|
||||
// sidebar.on('mouseout', function() {
|
||||
// barScroll = false;
|
||||
// });
|
||||
// };
|
||||
$(window).on('scroll', function(e) {
|
||||
if ($(this).scrollTop() > ($('.footer').offset().top - $(window).height())) {
|
||||
winHeight = $(window).height() - $('.footer').outerHeight() - 44;
|
||||
sidebar.css('max-height', winHeight + 'px');
|
||||
$('.docs-sidenav').css('max-height', winHeight + 'px');
|
||||
} else {
|
||||
winHeight = $(window).height() - 44;
|
||||
sidebar.css('max-height', winHeight + 'px');
|
||||
$('.docs-sidenav').css('max-height', winHeight + 'px');
|
||||
}
|
||||
|
||||
// $(window).on('scroll', function(e) {
|
||||
// if ($(this).scrollTop() > ($('.footer').offset().top - $(window).height())) {
|
||||
// winHeight = $(window).height() - $('.footer').outerHeight() - 44;
|
||||
// sidebar.css('max-height', winHeight + 'px');
|
||||
// $('.docs-sidenav').css('max-height', winHeight + 'px');
|
||||
// } else {
|
||||
// winHeight = $(window).height() - 44;
|
||||
// sidebar.css('max-height', winHeight + 'px');
|
||||
// $('.docs-sidenav').css('max-height', winHeight + 'px');
|
||||
// }
|
||||
//
|
||||
// if (!barScroll) {
|
||||
// var activeItem = $('.docs-sidebar li.active a');
|
||||
// if (activeItem.length) {
|
||||
// if (!activeMenu || (activeMenu.attr('href') != activeItem.attr('href'))) {
|
||||
// activeMenu = activeItem;
|
||||
// var top = activeMenu.offset().top - sidebar.offset().top;
|
||||
// if (top < 0) {
|
||||
// //sidebar.scrollTop(sidebar.scrollTop() + top);
|
||||
// $('.docs-sidenav').scrollTop($('.docs-sidenav').scrollTop() + top);
|
||||
// } else if (top > winHeight - 88) {
|
||||
// //sidebar.scrollTop(sidebar.scrollTop() + top - winHeight + 44);
|
||||
// $('.docs-sidenav').scrollTop($('.docs-sidenav').scrollTop() + top - winHeight + 88);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
if (!barScroll) {
|
||||
var activeItem = $('.docs-sidebar li.active a');
|
||||
if (activeItem.length) {
|
||||
if (!activeMenu || (activeMenu.attr('href') != activeItem.attr('href'))) {
|
||||
activeMenu = activeItem;
|
||||
var top = activeMenu.offset().top - sidebar.offset().top;
|
||||
if (top < 0) {
|
||||
//sidebar.scrollTop(sidebar.scrollTop() + top);
|
||||
$('.docs-sidenav').scrollTop($('.docs-sidenav').scrollTop() + top);
|
||||
} else if (top > winHeight - 88) {
|
||||
//sidebar.scrollTop(sidebar.scrollTop() + top - winHeight + 44);
|
||||
$('.docs-sidenav').scrollTop($('.docs-sidenav').scrollTop() + top - winHeight + 88);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 退出全屏浏览器窗口大小改变,不触发resize
|
||||
$(window).on('resize', function(e) {
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user