Skip to content

Commit 6b7f6d6

Browse files
author
weizx
committed
feat(1.0): 初始化项目,实现了java的实体类和请求接口类的模板
0 parents  commit 6b7f6d6

16 files changed

+20281
-0
lines changed

.gitignore

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
JetBrains.Dockerfile
2+
apiblueprint/
3+
#idea
4+
.idea
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
24+
# nyc test coverage
25+
.nyc_output
26+
27+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
28+
.grunt
29+
30+
# Bower dependency directory (https://bower.io/)
31+
bower_components
32+
33+
# node-waf configuration
34+
.lock-wscript
35+
36+
# Compiled binary addons (http://nodejs.org/api/addons.html)
37+
build/Release
38+
39+
# Dependency directories
40+
node_modules/
41+
jspm_packages/
42+
43+
# Typescript v1 declaration files
44+
typings/
45+
46+
# Optional npm cache directory
47+
.npm
48+
49+
# Optional eslint cache
50+
.eslintcache
51+
52+
# Optional REPL history
53+
.node_repl_history
54+
55+
# Output of 'npm pack'
56+
*.tgz
57+
58+
# Yarn Integrity file
59+
.yarn-integrity
60+
61+
# dotenv environment variables file
62+
.env

Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 选择image
2+
FROM node:latest
3+
4+
# 创建源码目录并设置当前工作路径
5+
RUN mkdir -p /usr/app
6+
WORKDIR /usr/app
7+
8+
# 拷贝源码到目标路径
9+
COPY ./bin /usr/app/bin
10+
COPY ./public /usr/app/public
11+
COPY ./routes /usr/app/routes
12+
COPY ./views /usr/app/views
13+
COPY ./app.js /usr/app/app.js
14+
COPY ./package.json /usr/app/package.json
15+
16+
RUN npm install .
17+
18+
CMD [ "node", "/usr/app/bin/www" ]

app.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var express = require('express');
2+
var path = require('path');
3+
var favicon = require('serve-favicon');
4+
var logger = require('morgan');
5+
var cookieParser = require('cookie-parser');
6+
var bodyParser = require('body-parser');
7+
8+
var index = require('./routes/index');
9+
var apis = require('./routes/beans/apis');
10+
11+
var app = express();
12+
13+
// view engine setup
14+
app.set('views', path.join(__dirname, 'views'));
15+
app.set('view engine', 'jade');
16+
17+
// uncomment after placing your favicon in /public
18+
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
19+
app.use(logger('dev'));
20+
app.use(bodyParser.json());
21+
app.use(bodyParser.urlencoded({extended: false}));
22+
app.use(cookieParser());
23+
app.use(express.static(path.join(__dirname, 'public')));
24+
25+
app.use('/', index);
26+
app.use('/apis', apis);
27+
28+
// catch 404 and forward to error handler
29+
app.use(function (req, res, next) {
30+
var err = new Error('Not Found');
31+
err.status = 404;
32+
next(err);
33+
});
34+
35+
// error handler
36+
app.use(function (err, req, res, next) {
37+
// set locals, only providing error in development
38+
res.locals.message = err.message;
39+
res.locals.error = req.app.get('env') === 'development' ? err : {};
40+
41+
// render the error page
42+
res.status(err.status || 500);
43+
res.render('error');
44+
});
45+
46+
module.exports = app;

bin/www

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app');
8+
var debug = require('debug')('APIBlueprintToJava:server');
9+
var http = require('http');
10+
11+
/**
12+
* Get port from environment and store in Express.
13+
*/
14+
15+
var port = normalizePort(process.env.PORT || '3000');
16+
app.set('port', port);
17+
18+
/**
19+
* Create HTTP server.
20+
*/
21+
22+
var server = http.createServer(app);
23+
24+
/**
25+
* Listen on provided port, on all network interfaces.
26+
*/
27+
28+
server.listen(port);
29+
server.on('error', onError);
30+
server.on('listening', onListening);
31+
32+
/**
33+
* Normalize a port into a number, string, or false.
34+
*/
35+
36+
function normalizePort(val) {
37+
var port = parseInt(val, 10);
38+
39+
if (isNaN(port)) {
40+
// named pipe
41+
return val;
42+
}
43+
44+
if (port >= 0) {
45+
// port number
46+
return port;
47+
}
48+
49+
return false;
50+
}
51+
52+
/**
53+
* Event listener for HTTP server "error" event.
54+
*/
55+
56+
function onError(error) {
57+
if (error.syscall !== 'listen') {
58+
throw error;
59+
}
60+
61+
var bind = typeof port === 'string'
62+
? 'Pipe ' + port
63+
: 'Port ' + port;
64+
65+
// handle specific listen errors with friendly messages
66+
switch (error.code) {
67+
case 'EACCES':
68+
console.error(bind + ' requires elevated privileges');
69+
process.exit(1);
70+
break;
71+
case 'EADDRINUSE':
72+
console.error(bind + ' is already in use');
73+
process.exit(1);
74+
break;
75+
default:
76+
throw error;
77+
}
78+
}
79+
80+
/**
81+
* Event listener for HTTP server "listening" event.
82+
*/
83+
function onListening() {
84+
var addr = server.address();
85+
var bind = typeof addr === 'string'
86+
? 'pipe ' + addr
87+
: 'port ' + addr.port;
88+
debug('Listening on ' + bind);
89+
}

package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "untitled",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"start": "node ./bin/www"
7+
},
8+
"dependencies": {
9+
"body-parser": "~1.16.0",
10+
"cookie-parser": "~1.4.3",
11+
"debug": "~2.6.0",
12+
"express": "~4.14.1",
13+
"jade": "~1.11.0",
14+
"morgan": "~1.7.0",
15+
"serve-favicon": "~2.3.2",
16+
"nodegit": "latest",
17+
"drafter": "latest"
18+
}
19+
}

public/html/bean_template.html

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
<script src="../js/vue.js"></script>
7+
<script src="../js/to_bean.js"></script>
8+
<script src="../js/jquery-3.1.1.js"></script>
9+
</head>
10+
<body>
11+
12+
<span>Api文档Git地址:</span>
13+
<input id="gitUrl" type="text" style="width:300px"
14+
value="https://github.com/free46000"/><br/>
15+
<span>Api文档本地存储位置:</span>
16+
<input id="gitPath" type="text" style="width:300px" value="apiblueprint/git/"/><br/>
17+
<button id="submit">生成</button>
18+
<br/>
19+
20+
<div id="bean" v-if="beans">
21+
<div v-for="bean in beans">
22+
<div :id="bean.className" style="background: cornsilk">
23+
<p>package com.cim120.patient.data.bean.response;</p>
24+
25+
<p v-for="imp in bean.importTypes">import {{imp}};</p>
26+
27+
<p>public class {{ bean.className }} {</p>
28+
<div v-for="field in bean.fields">
29+
private {{field.type}} {{field.name}};
30+
</div>
31+
<div v-for="field in bean.fields">
32+
public void set{{ firstToUpperCase(field.name) }}({{field.type}} {{ field.name }}) {<br>
33+
this.{{field.name}} = {{field.name}};<br>
34+
}<br><br>
35+
public {{field.type}} get{{ firstToUpperCase(field.name) }}() {<br>
36+
return this.{{field.name}};<br>
37+
}<br><br>
38+
</div>
39+
<p>}</p>
40+
41+
</div>
42+
<div>
43+
<p>==========================================================================================</p>
44+
</div>
45+
</div>
46+
</div>
47+
48+
<div id="apiset" v-if="apiArr">
49+
<div style="background: cornsilk">
50+
<p>package com.cim120.patient.data.bean.response;</p>
51+
52+
<p>import java.util.Map;</p>
53+
54+
<p>import okhttp3.ResponseBody;</p>
55+
<p>import retrofit2.http.*;</p>
56+
<p>import rx.Observable;</p>
57+
58+
<p>public interface ApiSet {</p>
59+
<div v-for="api in apiArr">
60+
<p>/**</p>
61+
<p>*{{api.title}} {{api.subTitle}} {{api.tip}}</p>
62+
<p>*/</p>
63+
<p>@{{api.method}}("{{api.href}}")</p>
64+
<p>Observable&lt;Object&gt; request{{api.hrefName}}(
65+
<span v-for="(hrefVar, index) in api.hrefVariables">
66+
@Path("{{hrefVar.content}}") {{hrefVar.element}} {{hrefVar.content}}
67+
<span v-if="index != api.hrefVariables.length-1">,</span>
68+
</span>
69+
<span v-if="api.param">@Body Map&lt;String, String&gt; paramMap</span>
70+
<span>);</span>
71+
</p>
72+
</div>
73+
<p>}</p>
74+
</div>
75+
</div>
76+
</body>
77+
78+
<script>
79+
$("#submit").click(generateCode);
80+
81+
function generateCode() {
82+
var gitPath = $("#gitPath")[0].value;
83+
var gitUrl = $("#gitUrl")[0].value;
84+
85+
$.get('/apis', {path: gitPath, url: gitUrl}, function (apiArr, textStatus) {
86+
if (!apiArr) {
87+
console.log(err);
88+
return;
89+
}
90+
var beans = [];
91+
for (var i in apiArr) {
92+
if ((typeof apiArr[i].response == 'object') && apiArr[i].response.constructor == Object) {
93+
beans = beans.concat(generateBeanFieldFromJson(JSON.stringify(apiArr[i].response), apiArr[i].hrefName));
94+
}
95+
}
96+
new Vue({
97+
el: '#bean',
98+
data: {
99+
beans: beans
100+
},
101+
methods: {
102+
firstToUpperCase: function (str) {
103+
return str.substr(0, 1).toUpperCase() + str.substr(1);
104+
}
105+
}
106+
107+
});
108+
new Vue({
109+
el: '#apiset',
110+
data: {
111+
apiArr: apiArr
112+
},
113+
methods: {
114+
camelCase: function (input) {
115+
return input.replace(/\/{\w*\}/g, '').replace(/\/(.)/g, function (match, group1) {
116+
return group1.toUpperCase();
117+
});
118+
}
119+
}
120+
});
121+
console.log(textStatus);
122+
});
123+
}
124+
</script>
125+
126+
</html>

0 commit comments

Comments
 (0)