foss42 / apidash

API Dash is a beautiful open-source cross-platform API Client built using Flutter which can help you easily create & customize your API requests, visually inspect responses and generate API integration code. A lightweight alternative to postman/insomnia.
https://apidash.dev
Apache License 2.0
1.43k stars 269 forks source link

Validate JAVA Http Client Codegen and add relevant testcases #353

Closed apoorvdwi closed 5 months ago

apoorvdwi commented 5 months ago

PR Description

This PR fixes the Java http client codegen and adds the relevant tests.

Related Issues

Checklist

Added/updated tests?

We encourage you to add relevant test cases.

Steps to run

Java code is relatively hard to run on local machine due to install overheads which is why I prepared a simple dockerfile given below

# Use the official OpenJDK image for a base image
FROM openjdk:23

# Set the working directory inside the container
WORKDIR /usr/src/myapp

# Copy the Main.java file from the local directory to the container's working directory
COPY Main.java /usr/src/myapp/
COPY 1.png /usr/src/myapp/

# Include Gson JAR file (assuming it is available locally)
COPY gson-2.8.9.jar /usr/src/myapp/

# Add Gson JAR file to the classpath
ENV CLASSPATH=.:/usr/src/myapp/gson-2.8.9.jar

# Compile the Java program
RUN javac Main.java

# Run the Java program when the container launches
CMD ["java", "Main"]
apoorvdwi commented 5 months ago

@ashitaprasad @animator please review this PR Let me know if you face any difficulties in running the code

I'm pasting a few screenshots of code runs just in case

Screenshot 2024-03-23 at 9 42 34 PM Screenshot 2024-03-23 at 9 43 16 PM

animator commented 5 months ago

POST 2 & POST 3 generated code is giving incorrect output.

Response body: {"detail":[{"type":"model_attributes_type","loc":["body"],"msg":"Input should be a valid dictionary or object to extract fields from","input":"{\n\"text\": \"I LOVE Flutter\"\n}","url":"https://errors.pydantic.dev/2.6/v/model_attributes_type"}]}
Response code: 422

Expected Output:

Response body: {"data":"i love flutter"}
Response code: 200
animator commented 5 months ago

Also HEAD2 is

codeGen.getCode(
              CodegenLanguage.javaHttpClient, requestModelHead2, "http"),
          expectedCode);

instead of

codeGen.getCode(
              CodegenLanguage.javaHttpClient, requestModelHead2, "https"),
          expectedCode);
apoorvdwi commented 5 months ago

@ashitaprasad @animator fixed the head2 testcase and json body type parsing

animator commented 5 months ago

Thanks for the PR. LGTM 🚀