Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e6f049c
Merge pull request #37 from TakayukiHoshi1984/modify_nodegot_readme
TakayukiHoshi1984 Sep 27, 2018
7490d4e
swagger-codegen ライブラリを 2.2.2 にアップデート。
masaru-takano Nov 1, 2018
2afa155
GitHub Wikiに投稿した際、目次からAPI仕様詳細へタグジャンプできなくなってしまう問題を修正。
masaru-takano Nov 1, 2018
b2b0a90
swagger-codegen を v2.2.3 にアップデート。
masaru-takano Nov 1, 2018
35fb981
バージョン名を1.8.2に変更。
masaru-takano Nov 1, 2018
582a90c
内部的に変換する前のswaggerを保持。
masaru-takano Nov 6, 2018
bd17420
オリジナルのswaggerを内部的に保持するためにクローンする。
masaru-takano Nov 6, 2018
3120eed
不要な処理を削除。
masaru-takano Dec 6, 2018
00c30c8
不具合修正: 不正なリクエストパスが生成される場合がある。
masaru-takano Dec 6, 2018
a0f80d6
エミュレータのテンプレート修正。
masaru-takano Dec 6, 2018
c03932b
ServiceInformation の内容から不要な情報を削除。
masaru-takano Dec 7, 2018
17cb8f2
エミュレータ側で提供するAPIのパスを修正。
masaru-takano Dec 7, 2018
2fa9f3f
objectプロパティの$refも解析する。
masaru-takano Dec 7, 2018
c3f0e39
API定義のサンプルを修正。
masaru-takano Dec 7, 2018
a35e798
不要な警告が出ないように修正。
masaru-takano Dec 7, 2018
436be2d
consumesプロパティが空の配列の場合に強制終了する問題を修正。
masaru-takano Dec 7, 2018
6921348
API リファレンスの出力順が以前のバージョンと同じになるように調整。
masaru-takano Dec 10, 2018
da117a3
バイナリへのリンクを修正。リリースノート更新。
masaru-takano Dec 10, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DeviceConnectCodegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ DeviceConnect Codegenは、DeviceConnectシステム上で動作するプラグ
|samples/profiles-specs|シェルスクリプトのサンプルに入力するプロファイル定義ファイル群。|

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

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

Expand Down
7 changes: 7 additions & 0 deletions DeviceConnectCodegen/RELEASENOTE.TXT
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# 変更履歴
2018/12/10: v1.8.2 [共通] swagger-codegen v2.2.3 を使用するように変更。v2.2.1 に関する脆弱性への対処のため。
[Markdown] 不具合修正: GitHub Wikiにアップロードすると各API仕様へのタグジャンプが行えない。

2018/09/27: v1.8.1 [NodeJS] メンテナンス: NodeJS向けに出力するデバイスプラグインのREADMEにServiceInformationを追加

2018/09/12: v1.8.0 [NodeJS] NodeJS向けに出力するデバイスプラグインのソースコードを改善

2018/03/01: v1.6.0 [Android] オプション追加: --gradle-plugin-version, --sdk, --signing-config, --template-dir
[共通] 不具合修正: basePathプロパティでプロファイル名が定義されている場合に異常終了

Expand Down
4 changes: 2 additions & 2 deletions DeviceConnectCodegen/modules/deviceconnect-codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.deviceconnect</groupId>
<artifactId>deviceconnect-codegen</artifactId>
<version>1.8.1</version>
<version>1.8.2</version>

<packaging>jar</packaging>

Expand Down Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen</artifactId>
<version>2.2.1</version>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

public abstract class AbstractCodegenConfig extends DefaultCodegen implements DConnectCodegenConfig {

protected Swagger originalSwagger;

protected Map<String, Swagger> profileSpecs;

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

@Override
public Swagger getOriginalSwagger() {
return this.originalSwagger;
}

@Override
public void setOriginalSwagger(final Swagger swagger) {
this.originalSwagger = swagger;
}

@Override
public String escapeUnsafeCharacters(final String input) {
return input.replace("*/", "*_/").replace("/*", "/_*");
}

@Override
public String escapeQuotationMark(final String input) {
return input.replace("\"", "\\\"");
}

protected static String toUpperCapital(final String str, final boolean onlyFirstChar) {
StringBuffer buf = new StringBuffer(str.length());
buf.append(str.substring(0, 1).toUpperCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import org.deviceconnect.codegen.app.HtmlAppCodegenConfig;
import org.deviceconnect.codegen.docs.HtmlDocsCodegenConfig;
import org.deviceconnect.codegen.docs.MarkdownDocsCodegenConfig;
import org.deviceconnect.codegen.util.SortedSwagger;
import org.deviceconnect.codegen.util.SwaggerJsonValidator;
import org.deviceconnect.codegen.util.SwaggerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -203,9 +205,11 @@ public static void main(String[] args) {
new Codegen() {
@Override
public File writeToFile(final String filename, final String contents) throws IOException {
// LICENSE ファイルは出力させない
// 不要なファイルは出力させない
if (filename != null) {
if (filename.endsWith("LICENSE") || filename.endsWith(".swagger-codegen-ignore")) {
if (filename.endsWith("VERSION")
|| filename.endsWith("LICENSE")
|| filename.endsWith(".swagger-codegen-ignore")) {
return null;
}
}
Expand Down Expand Up @@ -264,6 +268,7 @@ private static void parseSwaggerFromFile(File file,
profile.setPaths(subPaths);
}
config.setProfileSpecs(profiles);
config.setOriginalSwagger(SwaggerUtils.cloneSwagger(swagger));
}

private static void parseSwaggerFromDirectory(File dir,
Expand Down Expand Up @@ -301,7 +306,9 @@ public boolean accept(final File dir, final String name) {
checkProfileName(config, profileName);
}
config.setProfileSpecs(profileSpecs);
clientOptInput.swagger(mergeSwaggers(profileSpecs));
Swagger swagger = mergeSwaggers(profileSpecs);
config.setOriginalSwagger(SwaggerUtils.cloneSwagger(swagger));
clientOptInput.swagger(swagger);
}

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

private static Swagger createProfileSpec(final Swagger swagger) {
Swagger profile = new Swagger();
Swagger profile = new SortedSwagger();
profile.setSwagger(swagger.getSwagger());
Info info = new Info();
info.setTitle(swagger.getInfo().getTitle());
Expand Down Expand Up @@ -453,7 +460,7 @@ private static String parseProfileNameFromFileName(final String fileName) {
}

private static Swagger mergeSwaggers(Map<String, Swagger> swaggerMap) {
Swagger merged = new Swagger();
Swagger merged = new SortedSwagger();
merged.setBasePath("/");

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

// consumes
List<String> allConsumes = new ArrayList<>();
for (Map.Entry<String, Swagger> entry : swaggerMap.entrySet()) {
Swagger swagger = entry.getValue();
List<String> consumes = swagger.getConsumes();
if (consumes != null) {
for (String mimeType : consumes) {
if (!allConsumes.contains(mimeType)) {
allConsumes.add(mimeType);
}
}
}
}
merged.setConsumes(allConsumes);

// paths
Map<String, Path> paths = new HashMap<>();
for (Map.Entry<String, Swagger> swagger : swaggerMap.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import io.swagger.models.Swagger;
import org.apache.commons.cli.CommandLine;

import java.io.File;
import java.util.Map;

public interface DConnectCodegenConfig extends CodegenConfig {
Expand All @@ -21,6 +20,10 @@ public interface DConnectCodegenConfig extends CodegenConfig {

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

Swagger getOriginalSwagger();

void setOriginalSwagger(Swagger swagger);

String getDefaultDisplayName();

ValidationResultSet validateOptions(CommandLine cmd, ClientOpts clientOpts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,16 @@ public String toCanonicalPathName() {
public String toString() {
return getPath();
}

@Override
public boolean equals(final Object o) {
if (o == null) {
return false;
}
if (!(o instanceof DConnectPath)) {
return false;
}
DConnectPath that = (DConnectPath) o;
return that.pathExp.equalsIgnoreCase(this.pathExp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.swagger.models.Model;
import io.swagger.models.Path;
import io.swagger.models.Swagger;
import org.deviceconnect.codegen.util.SortedSwagger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

String key = path.getProfileName();
Swagger cache = result.get(key);
Expand Down Expand Up @@ -87,7 +88,7 @@ private void convert(final Swagger swagger,
}

private static Swagger createProfileSpec(final Swagger swagger) {
Swagger profile = new Swagger();
Swagger profile = new SortedSwagger();
profile.setSwagger(swagger.getSwagger());
Info info = new Info();
info.setTitle(swagger.getInfo().getTitle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.SupportingFile;
import io.swagger.models.Swagger;
import io.swagger.parser.SwaggerParser;
import org.apache.commons.cli.CommandLine;
import org.deviceconnect.codegen.AbstractCodegenConfig;
import org.deviceconnect.codegen.DConnectCodegenConfig;
import org.deviceconnect.codegen.ValidationResultSet;

import java.util.Map;

public class HtmlAppCodegenConfig extends DefaultCodegen implements DConnectCodegenConfig {
public class HtmlAppCodegenConfig extends AbstractCodegenConfig implements DConnectCodegenConfig {

private Map<String, Swagger> profileSpecs;

@Override
protected String profileFileFolder() {
return null; // Not be used.
}

@Override
public ValidationResultSet validateOptions(final CommandLine cmd, final ClientOpts clientOpts) {
return new ValidationResultSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public void processOpts() {
basePath = "/gotapi/" + profileKey;
profileName = profileKey;
} else {
System.out.println("basePath: " + basePath);
profileName = basePath.split("/")[2];
}

Expand Down Expand Up @@ -149,6 +148,13 @@ List<Object> paramList() {
}
Object response = createResponseDocument(profileSpec, op);
Object event = createEventDocument(profileSpec, op);
String tag() {
String tag = this.name;
tag = tag.toLowerCase();
tag = tag.replaceAll(" ", "-"); // 半角スペース -> 半角ハイフン
tag = tag.replaceAll("/", ""); // 半角スラッシュ -> 空文字
return tag;
}
});
}
}
Expand Down Expand Up @@ -278,7 +284,7 @@ private Object createResponseDocument(final Swagger swagger, final Operation ope
}

private Object createEventDocument(final Swagger swagger, final Operation operation) {
DConnectOperation dConnectOperation = DConnectOperation.parse(swagger, operation);
DConnectOperation dConnectOperation = DConnectOperation.parse(operation);
if (dConnectOperation == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,8 @@
package org.deviceconnect.codegen.docs;


import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.SupportingFile;
import io.swagger.models.*;
import io.swagger.models.parameters.FormParameter;
import io.swagger.models.parameters.Parameter;
import io.swagger.models.parameters.QueryParameter;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.ObjectProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.RefProperty;
import org.deviceconnect.codegen.DConnectCodegenConfig;
import org.deviceconnect.codegen.models.DConnectOperation;
import io.swagger.models.Swagger;

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.swagger.models.Operation;
import io.swagger.models.Response;
import io.swagger.models.Swagger;
import io.swagger.models.parameters.Parameter;
import io.swagger.models.properties.*;
import io.swagger.models.properties.RefProperty;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -50,7 +49,7 @@ public Response getEventModel() {
return eventModel;
}

public static DConnectOperation parse(final Swagger swagger, final Operation entity) {
public static DConnectOperation parse(final Operation entity) {
Map<String, Object> extensions = entity.getVendorExtensions();
if (extensions != null) {
Object tmp = extensions.get(TYPE);
Expand All @@ -75,10 +74,50 @@ static Response parseEventModel(final Operation parent) {
if (root == null) {
return null;
}
if (!(root instanceof ObjectNode)) {
if (root instanceof Map) {
return parseEventModelAsMap((Map) root);
}
if (root instanceof ObjectNode) {
return parseEventModelAsNode((ObjectNode) root);
}
return null;
}

// For swagger-codegen 2.2.3
static Response parseEventModelAsMap(final Map root) {
Object schemaObj = root.get("schema");
Object examplesObj = root.get("examples");
if (!(schemaObj instanceof Map)) {
return null;
}
ObjectNode rootNode = (ObjectNode) root;
Map schema = (Map) schemaObj;
Object refObj = schema.get("$ref");
if (refObj != null) {
if (!(refObj instanceof String)) {
return null;
}
String ref = (String) refObj;
if (!ref.startsWith(PREFIX_DEFINITION_REF)) {
return null;
}
if (!(examplesObj instanceof Map)) {
return null;
}
Map examples= (Map) examplesObj;

Response eventModel = new Response();
RefProperty refSchema = new RefProperty();
refSchema.set$ref(ref);
eventModel.setSchema(refSchema);
eventModel.setExamples(examples);
return eventModel;
} else {
return null;
}
}

// For swagger-codegen 2.2.1
static Response parseEventModelAsNode(final ObjectNode rootNode) {
JsonNode schema = rootNode.get("schema");
if (schema == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void preprocessSwagger(final Swagger swagger) {

for (Map.Entry<HttpMethod, Operation> operationEntry : path.getOperationMap().entrySet()) {
HttpMethod method = operationEntry.getKey();
DConnectOperation operation = DConnectOperation.parse(swagger, operationEntry.getValue());
DConnectOperation operation = DConnectOperation.parse(operationEntry.getValue());

final Map<String, Object> api = new HashMap<>();
final String interfaceName = dConnectPath.getInterfaceName();
Expand Down
Loading