Skip to content

Commit cd0a039

Browse files
Merge pull request #38 from TakayukiHoshi1984/modify_codegen_1_8_2
DeviceConnectCodegen 1.8.2
2 parents c113001 + da117a3 commit cd0a039

25 files changed

Lines changed: 419 additions & 105 deletions

DeviceConnectCodegen/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ DeviceConnect Codegenは、DeviceConnectシステム上で動作するプラグ
3333
|samples/profiles-specs|シェルスクリプトのサンプルに入力するプロファイル定義ファイル群。|
3434

3535
## Get Started
36-
[deviceconnect-codegen-project-1.7.0-dist.zip](https://github.com/TakayukiHoshi1984/DeviceConnect-Experiments/releases/tag/codegen-v1.7.0) をPC上の任意の場所にダウンロードし、解凍してください。
36+
[deviceconnect-codegen-project-1.8.2-dist.zip](https://github.com/TakayukiHoshi1984/DeviceConnect-Experiments/releases/tag/codegen-v1.8.2) をPC上の任意の場所にダウンロードし、解凍してください。
3737

3838
解凍後、ターミナルを起動し、以下のコマンドによりをサンプルのスケルトンコードを生成してください。
3939

DeviceConnectCodegen/RELEASENOTE.TXT

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# 変更履歴
2+
2018/12/10: v1.8.2 [共通] swagger-codegen v2.2.3 を使用するように変更。v2.2.1 に関する脆弱性への対処のため。
3+
[Markdown] 不具合修正: GitHub Wikiにアップロードすると各API仕様へのタグジャンプが行えない。
4+
5+
2018/09/27: v1.8.1 [NodeJS] メンテナンス: NodeJS向けに出力するデバイスプラグインのREADMEにServiceInformationを追加
6+
7+
2018/09/12: v1.8.0 [NodeJS] NodeJS向けに出力するデバイスプラグインのソースコードを改善
8+
29
2018/03/01: v1.6.0 [Android] オプション追加: --gradle-plugin-version, --sdk, --signing-config, --template-dir
310
[共通] 不具合修正: basePathプロパティでプロファイル名が定義されている場合に異常終了
411

DeviceConnectCodegen/modules/deviceconnect-codegen/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.deviceconnect</groupId>
88
<artifactId>deviceconnect-codegen</artifactId>
9-
<version>1.8.1</version>
9+
<version>1.8.2</version>
1010

1111
<packaging>jar</packaging>
1212

@@ -70,7 +70,7 @@
7070
<dependency>
7171
<groupId>io.swagger</groupId>
7272
<artifactId>swagger-codegen</artifactId>
73-
<version>2.2.1</version>
73+
<version>2.2.3</version>
7474
</dependency>
7575
<dependency>
7676
<groupId>junit</groupId>

DeviceConnectCodegen/modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/AbstractCodegenConfig.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
public abstract class AbstractCodegenConfig extends DefaultCodegen implements DConnectCodegenConfig {
2424

25+
protected Swagger originalSwagger;
26+
2527
protected Map<String, Swagger> profileSpecs;
2628

2729
protected abstract String profileFileFolder();
@@ -41,11 +43,26 @@ public void setProfileSpecs(final Map<String, Swagger> profileSpecs) {
4143
this.profileSpecs = profileSpecs;
4244
}
4345

46+
@Override
47+
public Swagger getOriginalSwagger() {
48+
return this.originalSwagger;
49+
}
50+
51+
@Override
52+
public void setOriginalSwagger(final Swagger swagger) {
53+
this.originalSwagger = swagger;
54+
}
55+
4456
@Override
4557
public String escapeUnsafeCharacters(final String input) {
4658
return input.replace("*/", "*_/").replace("/*", "/_*");
4759
}
4860

61+
@Override
62+
public String escapeQuotationMark(final String input) {
63+
return input.replace("\"", "\\\"");
64+
}
65+
4966
protected static String toUpperCapital(final String str, final boolean onlyFirstChar) {
5067
StringBuffer buf = new StringBuffer(str.length());
5168
buf.append(str.substring(0, 1).toUpperCase());

DeviceConnectCodegen/modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/DConnectCodegen.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import org.deviceconnect.codegen.app.HtmlAppCodegenConfig;
2424
import org.deviceconnect.codegen.docs.HtmlDocsCodegenConfig;
2525
import org.deviceconnect.codegen.docs.MarkdownDocsCodegenConfig;
26+
import org.deviceconnect.codegen.util.SortedSwagger;
2627
import org.deviceconnect.codegen.util.SwaggerJsonValidator;
28+
import org.deviceconnect.codegen.util.SwaggerUtils;
2729
import org.slf4j.Logger;
2830
import org.slf4j.LoggerFactory;
2931

@@ -203,9 +205,11 @@ public static void main(String[] args) {
203205
new Codegen() {
204206
@Override
205207
public File writeToFile(final String filename, final String contents) throws IOException {
206-
// LICENSE ファイルは出力させない
208+
// 不要なファイルは出力させない
207209
if (filename != null) {
208-
if (filename.endsWith("LICENSE") || filename.endsWith(".swagger-codegen-ignore")) {
210+
if (filename.endsWith("VERSION")
211+
|| filename.endsWith("LICENSE")
212+
|| filename.endsWith(".swagger-codegen-ignore")) {
209213
return null;
210214
}
211215
}
@@ -264,6 +268,7 @@ private static void parseSwaggerFromFile(File file,
264268
profile.setPaths(subPaths);
265269
}
266270
config.setProfileSpecs(profiles);
271+
config.setOriginalSwagger(SwaggerUtils.cloneSwagger(swagger));
267272
}
268273

269274
private static void parseSwaggerFromDirectory(File dir,
@@ -301,7 +306,9 @@ public boolean accept(final File dir, final String name) {
301306
checkProfileName(config, profileName);
302307
}
303308
config.setProfileSpecs(profileSpecs);
304-
clientOptInput.swagger(mergeSwaggers(profileSpecs));
309+
Swagger swagger = mergeSwaggers(profileSpecs);
310+
config.setOriginalSwagger(SwaggerUtils.cloneSwagger(swagger));
311+
clientOptInput.swagger(swagger);
305312
}
306313

307314
private static boolean checkSwagger(final File file) throws IOException, ProcessingException {
@@ -355,7 +362,7 @@ private static void printDuplicatedPathError(final DuplicatedPathException e) {
355362
}
356363

357364
private static Swagger createProfileSpec(final Swagger swagger) {
358-
Swagger profile = new Swagger();
365+
Swagger profile = new SortedSwagger();
359366
profile.setSwagger(swagger.getSwagger());
360367
Info info = new Info();
361368
info.setTitle(swagger.getInfo().getTitle());
@@ -453,7 +460,7 @@ private static String parseProfileNameFromFileName(final String fileName) {
453460
}
454461

455462
private static Swagger mergeSwaggers(Map<String, Swagger> swaggerMap) {
456-
Swagger merged = new Swagger();
463+
Swagger merged = new SortedSwagger();
457464
merged.setBasePath("/");
458465

459466
// info
@@ -462,6 +469,21 @@ private static Swagger mergeSwaggers(Map<String, Swagger> swaggerMap) {
462469
info.setVersion("1.0.0");
463470
merged.setInfo(info);
464471

472+
// consumes
473+
List<String> allConsumes = new ArrayList<>();
474+
for (Map.Entry<String, Swagger> entry : swaggerMap.entrySet()) {
475+
Swagger swagger = entry.getValue();
476+
List<String> consumes = swagger.getConsumes();
477+
if (consumes != null) {
478+
for (String mimeType : consumes) {
479+
if (!allConsumes.contains(mimeType)) {
480+
allConsumes.add(mimeType);
481+
}
482+
}
483+
}
484+
}
485+
merged.setConsumes(allConsumes);
486+
465487
// paths
466488
Map<String, Path> paths = new HashMap<>();
467489
for (Map.Entry<String, Swagger> swagger : swaggerMap.entrySet()) {

DeviceConnectCodegen/modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/DConnectCodegenConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import io.swagger.models.Swagger;
1313
import org.apache.commons.cli.CommandLine;
1414

15-
import java.io.File;
1615
import java.util.Map;
1716

1817
public interface DConnectCodegenConfig extends CodegenConfig {
@@ -21,6 +20,10 @@ public interface DConnectCodegenConfig extends CodegenConfig {
2120

2221
void setProfileSpecs(Map<String, Swagger> profileSpecs);
2322

23+
Swagger getOriginalSwagger();
24+
25+
void setOriginalSwagger(Swagger swagger);
26+
2427
String getDefaultDisplayName();
2528

2629
ValidationResultSet validateOptions(CommandLine cmd, ClientOpts clientOpts);

DeviceConnectCodegen/modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/DConnectPath.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,16 @@ public String toCanonicalPathName() {
144144
public String toString() {
145145
return getPath();
146146
}
147+
148+
@Override
149+
public boolean equals(final Object o) {
150+
if (o == null) {
151+
return false;
152+
}
153+
if (!(o instanceof DConnectPath)) {
154+
return false;
155+
}
156+
DConnectPath that = (DConnectPath) o;
157+
return that.pathExp.equalsIgnoreCase(this.pathExp);
158+
}
147159
}

DeviceConnectCodegen/modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/MultipleSwaggerConverter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.swagger.models.Model;
1212
import io.swagger.models.Path;
1313
import io.swagger.models.Swagger;
14+
import org.deviceconnect.codegen.util.SortedSwagger;
1415
import org.slf4j.Logger;
1516
import org.slf4j.LoggerFactory;
1617

@@ -52,7 +53,7 @@ private void convert(final Swagger swagger,
5253
String pathName = entry.getKey();
5354
DConnectPath path = DConnectPath.parsePath(basePath, pathName);
5455
counter.count(path.toCanonicalPathName());
55-
LOGGER.info("Base Path: " + path.getBathPath() + ", Sub Path: " + path.getSubPath() + ", Profile: " + path.getProfileName());
56+
LOGGER.debug("Base Path: " + path.getBathPath() + ", Sub Path: " + path.getSubPath() + ", Profile: " + path.getProfileName());
5657

5758
String key = path.getProfileName();
5859
Swagger cache = result.get(key);
@@ -87,7 +88,7 @@ private void convert(final Swagger swagger,
8788
}
8889

8990
private static Swagger createProfileSpec(final Swagger swagger) {
90-
Swagger profile = new Swagger();
91+
Swagger profile = new SortedSwagger();
9192
profile.setSwagger(swagger.getSwagger());
9293
Info info = new Info();
9394
info.setTitle(swagger.getInfo().getTitle());

DeviceConnectCodegen/modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/app/HtmlAppCodegenConfig.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@
1515
import io.swagger.codegen.DefaultCodegen;
1616
import io.swagger.codegen.SupportingFile;
1717
import io.swagger.models.Swagger;
18-
import io.swagger.parser.SwaggerParser;
1918
import org.apache.commons.cli.CommandLine;
19+
import org.deviceconnect.codegen.AbstractCodegenConfig;
2020
import org.deviceconnect.codegen.DConnectCodegenConfig;
2121
import org.deviceconnect.codegen.ValidationResultSet;
2222

2323
import java.util.Map;
2424

25-
public class HtmlAppCodegenConfig extends DefaultCodegen implements DConnectCodegenConfig {
25+
public class HtmlAppCodegenConfig extends AbstractCodegenConfig implements DConnectCodegenConfig {
2626

2727
private Map<String, Swagger> profileSpecs;
2828

29+
@Override
30+
protected String profileFileFolder() {
31+
return null; // Not be used.
32+
}
33+
2934
@Override
3035
public ValidationResultSet validateOptions(final CommandLine cmd, final ClientOpts clientOpts) {
3136
return new ValidationResultSet();

DeviceConnectCodegen/modules/deviceconnect-codegen/src/main/java/org/deviceconnect/codegen/docs/AbstractDocsCodegenConfig.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public void processOpts() {
6868
basePath = "/gotapi/" + profileKey;
6969
profileName = profileKey;
7070
} else {
71-
System.out.println("basePath: " + basePath);
7271
profileName = basePath.split("/")[2];
7372
}
7473

@@ -149,6 +148,13 @@ List<Object> paramList() {
149148
}
150149
Object response = createResponseDocument(profileSpec, op);
151150
Object event = createEventDocument(profileSpec, op);
151+
String tag() {
152+
String tag = this.name;
153+
tag = tag.toLowerCase();
154+
tag = tag.replaceAll(" ", "-"); // 半角スペース -> 半角ハイフン
155+
tag = tag.replaceAll("/", ""); // 半角スラッシュ -> 空文字
156+
return tag;
157+
}
152158
});
153159
}
154160
}
@@ -278,7 +284,7 @@ private Object createResponseDocument(final Swagger swagger, final Operation ope
278284
}
279285

280286
private Object createEventDocument(final Swagger swagger, final Operation operation) {
281-
DConnectOperation dConnectOperation = DConnectOperation.parse(swagger, operation);
287+
DConnectOperation dConnectOperation = DConnectOperation.parse(operation);
282288
if (dConnectOperation == null) {
283289
return null;
284290
}

0 commit comments

Comments
 (0)