Skip to content

Commit 31ce06b

Browse files
authored
Add backward compatible method for LIFF APIs (#1036)
line/line-openapi#26 see also: line/line-bot-sdk-python#486
1 parent b36f7fc commit 31ce06b

File tree

15 files changed

+185
-9
lines changed

15 files changed

+185
-9
lines changed

buildSrc/src/main/java/com/linecorp/bot/codegen/LineJavaCodegenGenerator.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,29 @@ public ModelsMap postProcessModels(ModelsMap objs) {
107107
}
108108

109109
// fill src/main/resources/body/*.java to the body of the class.
110-
try (InputStream inputStream = getClass().getClassLoader()
111-
.getResourceAsStream("body/" + codegenModel.name + ".java")) {
112-
if (inputStream != null) {
113-
String src = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
114-
codegenModel.vendorExtensions.put("x-body", indent4(src));
115-
}
116-
} catch (IOException e) {
117-
// do nothing.
118-
}
110+
String body = readPartialBody("body/model/" + codegenModel.name + ".java");
111+
codegenModel.vendorExtensions.put("x-body", body);
119112
}
120113

121114
return modelsMap;
122115
}
123116

117+
private String readPartialBody(String path) {
118+
// fill src/main/resources/body/*.java to the body of the class.
119+
try (InputStream inputStream = getClass().getClassLoader()
120+
.getResourceAsStream(path)) {
121+
if (inputStream != null) {
122+
System.out.println("Partial body file found: " + path);
123+
String src = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
124+
return indent4(src);
125+
}
126+
} catch (IOException e) {
127+
// do nothing.
128+
}
129+
System.out.println("Partial body file NOT found: " + path);
130+
return null;
131+
}
132+
124133
@Override
125134
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
126135
final Map<String, ModelsMap> processed = super.postProcessAllModels(objs);
@@ -203,6 +212,13 @@ protected ImmutableMap.Builder<String, Mustache.Lambda> addMustacheLambdas() {
203212
.replace("Client", "")
204213
+ "ExceptionBuilder"
205214
);
215+
})
216+
.put("injectbody", (fragment, writer) -> {
217+
String text = fragment.execute();
218+
String body = readPartialBody("body/api/" + text + ".java");
219+
if (body != null) {
220+
writer.write(body);
221+
}
206222
});
207223
}
208224

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@Deprecated
2+
default CompletableFuture<Result<GetAllLiffAppsResponse>> liffV1AppsGet() {
3+
return getAllLIFFApps();
4+
}
5+
6+
@Deprecated
7+
default CompletableFuture<Result<Void>> liffV1AppsLiffIdDelete(@Path("liffId") String liffId) {
8+
return deleteLIFFApp(liffId);
9+
}
10+
11+
@Deprecated
12+
default CompletableFuture<Result<Void>> liffV1AppsLiffIdPut(
13+
@Path("liffId") String liffId,
14+
@Body UpdateLiffAppRequest updateLiffAppRequest) {
15+
return updateLIFFApp(liffId, updateLiffAppRequest);
16+
}
17+
18+
@Deprecated
19+
default CompletableFuture<Result<AddLiffAppResponse>> liffV1AppsPost(@Body AddLiffAppRequest addLiffAppRequest) {
20+
return addLIFFApp(addLiffAppRequest);
21+
}

0 commit comments

Comments
 (0)