Skip to content

Commit 8e928d8

Browse files
committed
vo-refactored-to-generate-okhttp-client-sdk
1 parent 9d954d6 commit 8e928d8

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

src/main/java/io/github/venkat1701/ApiWrapperGenerator.java renamed to src/main/java/io/github/venkat1701/build/utils/okhttp/OkHttpApiClientGenerator.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
package io.github.venkat1701;
1+
package io.github.venkat1701.build.utils.okhttp;
22

33
import com.squareup.javapoet.*;
44
import io.swagger.v3.oas.models.OpenAPI;
55
import io.swagger.v3.oas.models.Operation;
66
import io.swagger.v3.oas.models.PathItem;
7-
import io.swagger.v3.parser.OpenAPIV3Parser;
7+
88
import javax.lang.model.element.Modifier;
99
import java.io.IOException;
1010
import java.nio.file.Paths;
1111
import java.util.Map;
1212

13-
public class ApiWrapperGenerator {
13+
/**
14+
* This ApiWrapperGenerator is responsible for generating the Client SDK with Okhttp.
15+
* @author Venkat
16+
*/
17+
public class OkHttpApiClientGenerator {
1418
public static void generateApiWrapper(OpenAPI openAPI, String outputDir) throws IOException {
15-
// yeh voh class hai jismei saare code jayenge and last mei flush hoga.
1619
TypeSpec.Builder apiWrapperClassBuilder = TypeSpec.classBuilder("ApiWrapper")
1720
.addModifiers(Modifier.PUBLIC);
1821
openAPI.getPaths().forEach((path, pathItem) -> {
@@ -22,10 +25,6 @@ public static void generateApiWrapper(OpenAPI openAPI, String outputDir) throws
2225
if (methodName == null || methodName.isEmpty()) {
2326
methodName = httpMethod.name().toLowerCase() + "_" + path;
2427
}
25-
// basically this will create a separate method for each openapi spec path
26-
// and then handle request-response gracefully with exc handling
27-
28-
//using code block was important and I just made use of jep 378 to write efficient and more readable code.
2928
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(sanitizeMethodName(methodName))
3029
.addModifiers(Modifier.PUBLIC)
3130
.returns(String.class)
@@ -61,18 +60,4 @@ private static String sanitizeMethodName(String methodName) {
6160
return methodName.replaceAll("[^a-zA-Z0-9]", "_");
6261
}
6362

64-
public static void main(String[] args) {
65-
try {
66-
String specPath = "src/main/resources/openapi.yaml";
67-
OpenAPI openAPI = new OpenAPIV3Parser().read(specPath);
68-
if (openAPI == null) {
69-
System.err.println("Failed to parse the OpenAPI specification.");
70-
return;
71-
}
72-
generateApiWrapper(openAPI, "./generated-sources");
73-
System.out.println("API wrapper generated successfully.");
74-
} catch (IOException e) {
75-
e.printStackTrace();
76-
}
77-
}
7863
}

0 commit comments

Comments
 (0)