Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
432 changes: 432 additions & 0 deletions docs/API_TOOLS.md

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,28 @@
<artifactId>bugsnag</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>

<!-- Servlet API for filters -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>

</dependencies>
<properties>
<maven-plugin-version>1.0.0</maven-plugin-version>
Expand Down
101 changes: 101 additions & 0 deletions src/main/java/io/swagger/petstore/client/ApiClientConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Copyright 2018 SmartBear Software
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.swagger.petstore.client;

/**
* Configuration class for the PetStore API client.
* Supports builder pattern for fluent configuration.
*
* Usage:
* <pre>
* ApiClientConfig config = ApiClientConfig.builder()
* .baseUrl("http://localhost:8080/api/v3")
* .apiKey("special-key")
* .connectTimeout(5000)
* .readTimeout(10000)
* .build();
* PetStoreClient client = new PetStoreClient(config);
* </pre>
*/
public class ApiClientConfig {

private String baseUrl;
private String apiKey;
private int connectTimeout;
private int readTimeout;

private ApiClientConfig(Builder builder) {
this.baseUrl = builder.baseUrl;
this.apiKey = builder.apiKey;
this.connectTimeout = builder.connectTimeout;
this.readTimeout = builder.readTimeout;
}

public static Builder builder() {
return new Builder();
}

public String getBaseUrl() {
return baseUrl;
}

public String getApiKey() {
return apiKey;
}

public int getConnectTimeout() {
return connectTimeout;
}

public int getReadTimeout() {
return readTimeout;
}

public static class Builder {
private String baseUrl = "http://localhost:8080/api/v3";
private String apiKey = "";
private int connectTimeout = 5000;
private int readTimeout = 10000;

public Builder baseUrl(String baseUrl) {
this.baseUrl = baseUrl;
return this;
}

public Builder apiKey(String apiKey) {
this.apiKey = apiKey;
return this;
}

public Builder connectTimeout(int millis) {
this.connectTimeout = millis;
return this;
}

public Builder readTimeout(int millis) {
this.readTimeout = millis;
return this;
}

public ApiClientConfig build() {
if (baseUrl == null || baseUrl.isEmpty()) {
throw new IllegalArgumentException("baseUrl is required");
}
return new ApiClientConfig(this);
}
}
}
80 changes: 80 additions & 0 deletions src/main/java/io/swagger/petstore/client/ApiResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright 2018 SmartBear Software
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.swagger.petstore.client;

/**
* Generic API response wrapper that encapsulates the HTTP status code,
* parsed response body, and raw response string.
*
* @param <T> The type of the parsed response body
*/
public class ApiResponse<T> {

private int statusCode;
private T body;
private String rawBody;

public ApiResponse() {
}

public ApiResponse(int statusCode, T body, String rawBody) {
this.statusCode = statusCode;
this.body = body;
this.rawBody = rawBody;
}

public int getStatusCode() {
return statusCode;
}

public void setStatusCode(int statusCode) {
this.statusCode = statusCode;
}

public T getBody() {
return body;
}

public void setBody(T body) {
this.body = body;
}

public String getRawBody() {
return rawBody;
}

public void setRawBody(String rawBody) {
this.rawBody = rawBody;
}

public boolean isSuccess() {
return statusCode >= 200 && statusCode < 300;
}

public boolean isClientError() {
return statusCode >= 400 && statusCode < 500;
}

public boolean isServerError() {
return statusCode >= 500;
}

@Override
public String toString() {
return "ApiResponse{statusCode=" + statusCode + ", body=" + rawBody + "}";
}
}
Loading