mirror of
https://github.com/YMFE/yapi.git
synced 2025-04-12 15:10:23 +08:00
feat: swagger json-schema
This commit is contained in:
parent
aabe214613
commit
53faf3259e
@ -16,8 +16,6 @@ require('tui-editor/dist/tui-editor.css'); // editor ui
|
||||
require('tui-editor/dist/tui-editor-contents.css'); // editor content
|
||||
require('highlight.js/styles/github.css'); // code block highlight
|
||||
require('./editor.css')
|
||||
|
||||
|
||||
var Editor = require('tui-editor');
|
||||
|
||||
function checkIsJsonSchema(json) {
|
||||
|
@ -1,8 +1,7 @@
|
||||
|
||||
import { message } from 'antd'
|
||||
import _ from 'underscore'
|
||||
var jsf = require('common/json-schema-mockjs');
|
||||
|
||||
const deref = require('deref')()
|
||||
|
||||
function improtData(importDataModule) {
|
||||
var SwaggerData, isOAS3;
|
||||
@ -70,11 +69,20 @@ function improtData(importDataModule) {
|
||||
let data = null;
|
||||
try {
|
||||
data = handleSwagger(api)
|
||||
if(data.catname){
|
||||
if(interfaceData.cats.indexOf(data.catname) === -1){
|
||||
interfaceData.cats.push({
|
||||
name: data.catname,
|
||||
desc: data.catname
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
data = null;
|
||||
}
|
||||
if (data) {
|
||||
interfaceData.apis.push(data);
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
@ -96,6 +104,7 @@ function improtData(importDataModule) {
|
||||
api.title = data.summary || data.path;
|
||||
api.desc = data.description;
|
||||
api.catname = data.tags && Array.isArray(data.tags) ? data.tags[0] : null;
|
||||
|
||||
api.path = handlePath(data.path);
|
||||
api.req_params = [];
|
||||
api.req_body_form = [];
|
||||
@ -103,9 +112,11 @@ function improtData(importDataModule) {
|
||||
api.req_query = [];
|
||||
api.req_body_type = 'raw';
|
||||
api.res_body_type = 'raw';
|
||||
|
||||
|
||||
if (data.produces && data.produces.indexOf('application/json') > -1) {
|
||||
api.res_body_type = 'json';
|
||||
api.res_body_is_json_schema = true;
|
||||
}
|
||||
|
||||
if (data.consumes && Array.isArray(data.consumes)) {
|
||||
@ -113,6 +124,7 @@ function improtData(importDataModule) {
|
||||
api.req_body_type = 'form';
|
||||
} else if (data.consumes.indexOf('application/json') > -1) {
|
||||
api.req_body_type = 'json';
|
||||
api.req_body_is_json_schema = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,6 +133,7 @@ function improtData(importDataModule) {
|
||||
try {
|
||||
JSON.parse(api.res_body);
|
||||
api.res_body_type = 'json';
|
||||
api.res_body_is_json_schema = true;
|
||||
} catch (e) {
|
||||
api.res_body_type = 'raw';
|
||||
}
|
||||
@ -218,8 +231,8 @@ function improtData(importDataModule) {
|
||||
try {
|
||||
// data.definitions = SwaggerData.definitions;
|
||||
isOAS3 ? data.components = SwaggerData.components : data.definitions = SwaggerData.definitions
|
||||
|
||||
let jsfData = JSON.stringify(jsf(data), null, 2);
|
||||
let schema = deref(data, true);
|
||||
let jsfData = JSON.stringify(schema, null, 2);
|
||||
return jsfData;
|
||||
} catch (e) {
|
||||
return '';
|
||||
|
@ -13,6 +13,7 @@
|
||||
<div id="yapi" style="height: 100%;"></div>
|
||||
|
||||
<script src="http://127.0.0.1:4000/prd/manifest@dev.js"></script>
|
||||
<script src="http://127.0.0.1:4000/prd/lib3@dev.js"></script>
|
||||
<script src="http://127.0.0.1:4000/prd/lib2@dev.js"></script>
|
||||
<script src="http://127.0.0.1:4000/prd/lib@dev.js"></script>
|
||||
<script src="http://127.0.0.1:4000/prd/index@dev.js"></script>
|
||||
|
@ -23,6 +23,9 @@
|
||||
<script>
|
||||
document.write('<script src="/prd/' + window.WEBPACK_ASSETS['manifest'].js + '"><\/script>');
|
||||
</script>
|
||||
<script>
|
||||
document.write('<script src="/prd/' + window.WEBPACK_ASSETS['lib3'].js + '"><\/script>');
|
||||
</script>
|
||||
<script>
|
||||
document.write('<script src="/prd/' + window.WEBPACK_ASSETS['lib2'].js + '"><\/script>');
|
||||
</script>
|
||||
|
@ -106,6 +106,19 @@ module.exports = {
|
||||
'url',
|
||||
'axios',
|
||||
'moment'
|
||||
],
|
||||
lib3: [
|
||||
'codemirror',
|
||||
"highlight.js",
|
||||
"jquery",
|
||||
"markdown-it",
|
||||
"plantuml-encoder",
|
||||
"squire-rte",
|
||||
"to-mark",
|
||||
"tui-chart",
|
||||
"tui-code-snippet",
|
||||
"tui-color-picker",
|
||||
'tui-editor'
|
||||
]
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user