Skip to content

Commit

Permalink
fix null bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wubin1989 committed May 19, 2021
1 parent 2349122 commit f7cb21d
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public static BizServer convert(Openapi3 openAPI) {
if (CollectionUtils.isNotEmpty(servers)) {
defaultServer = servers.get(0);
}
String host = defaultServer.getUrl();
String host = "";
if (defaultServer != null) {
host = defaultServer.getUrl();
}
String redundantPort = "";
for (String port : redundantPorts) {
if (host.endsWith(port)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ServiceFolderGeneratorTest {

@Test
public void generate() throws IOException {
try (BufferedInputStream is = new BufferedInputStream(ClassLoader.getSystemResourceAsStream("test1.json"))) {
try (BufferedInputStream is = new BufferedInputStream(ClassLoader.getSystemResourceAsStream("userservice_openapi3.json"))) {
BizServer bizServer = ServiceDocParser.parse(is);
ServiceFolderGenerator serviceFolderGenerator = new ServiceFolderGenerator.Builder(bizServer).zip(false).build();
String outputFile = serviceFolderGenerator.generate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ServiceTsGeneratorTest {

@Test
public void generate() throws IOException {
try (BufferedInputStream is = new BufferedInputStream(ClassLoader.getSystemResourceAsStream("test1.json"))) {
try (BufferedInputStream is = new BufferedInputStream(ClassLoader.getSystemResourceAsStream("userservice_openapi3.json"))) {
BizServer bizServer = ServiceDocParser.parse(is);
for (BizService bizService : bizServer.getServices()) {
ServiceTsGenerator serviceTsGenerator = new ServiceTsGenerator(bizService);
Expand Down
274 changes: 274 additions & 0 deletions unionj-generator-service/src/test/resources/userservice_openapi3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
{
"openapi": "3.0.2",
"paths": {
"/userservice/login": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LogInForm"
}
}
},
"required": true
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Auth"
}
}
}
}
}
}
},
"/userservice/pageusers": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PageQuery"
}
}
},
"required": true
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PageRet"
}
}
}
}
}
}
},
"/userservice/signup": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SignUpForm"
}
}
},
"required": true
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"type": "integer",
"format": "int32"
}
}
}
}
}
}
},
"/userservice/user": {
"get": {
"parameters": [
{
"name": "id",
"in": "query",
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserVo"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Auth": {
"title": "Auth",
"type": "object",
"properties": {
"token": {
"type": "string"
},
"user": {
"$ref": "#/components/schemas/UserVo"
}
}
},
"LogInForm": {
"title": "LogInForm",
"type": "object",
"properties": {
"password": {
"type": "string"
},
"username": {
"type": "string"
}
}
},
"Order": {
"title": "Order",
"type": "object",
"properties": {
"col": {
"type": "string"
},
"sort": {
"type": "string"
}
}
},
"Page": {
"title": "Page",
"type": "object",
"properties": {
"offset": {
"type": "integer",
"format": "int32"
},
"orders": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Order"
}
},
"size": {
"type": "integer",
"format": "int32"
}
}
},
"PageFilter": {
"title": "PageFilter",
"type": "object",
"properties": {
"dept": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string"
}
}
},
"PageQuery": {
"title": "PageQuery",
"type": "object",
"properties": {
"filter": {
"$ref": "#/components/schemas/PageFilter"
},
"page": {
"$ref": "#/components/schemas/Page"
}
}
},
"PageRet": {
"title": "PageRet",
"type": "object",
"properties": {
"hasNext": {
"type": "boolean"
},
"items": {
"type": "object"
},
"pageNo": {
"type": "integer",
"format": "int32"
},
"pageSize": {
"type": "integer",
"format": "int32"
},
"total": {
"type": "integer",
"format": "int32"
}
}
},
"Ret": {
"title": "Ret",
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"data": {
"type": "object"
},
"err": {
"type": "object"
},
"mmm": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/UserVo"
}
},
"msg": {
"type": "string"
}
}
},
"SignUpForm": {
"title": "SignUpForm",
"type": "object",
"properties": {
"passConfirm": {
"type": "string"
},
"password": {
"type": "string"
},
"username": {
"type": "string"
}
}
},
"UserVo": {
"title": "UserVo",
"type": "object",
"properties": {
"dept": {
"type": "string"
},
"id": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string"
},
"phone": {
"type": "string"
}
}
}
}
}
}

0 comments on commit f7cb21d

Please sign in to comment.