public class Pet extends extends ApiClient implements PetPost.PostOperation, PetPut.PutOperation
an api client class which contains all the routes for path="/pet"
Modifier and Type | Method and Description |
---|---|
PetPostResponses.EndpointResponse | post(PetPost.PostRequest request) Add a new pet to the store |
Void | put(PetPut.PutRequest request) |
public PetPostResponses.EndpointResponse post(PetPost.PostRequest request)
Add a new pet to the store
Parameters:
request - the input request
Returns:
the deserialized response
Throws:
IOException, InterruptedException - an exception happened when making the request
ValidationException - the returned response body or header values do not conform the the schema validation requirements
NotImplementedException - the request body serialization or deserialization has not yet been implemented
or the header content type deserialization has not yet been implemented for this contentType
ApiException - server returned a response/contentType not defined in the openapi document
import org.openapijsonschematools.client.configurations.ApiConfiguration;
import org.openapijsonschematools.client.configurations.SchemaConfiguration;
import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags;
import org.openapijsonschematools.client.exceptions.ValidationException;
import org.openapijsonschematools.client.exceptions.NotImplementedException;
import org.openapijsonschematools.client.exceptions.ApiException;
import org.openapijsonschematools.client.schemas.validation.MapUtils;
import org.openapijsonschematools.client.schemas.validation.FrozenList;
import org.openapijsonschematools.client.schemas.validation.FrozenMap;
import org.openapijsonschematools.client.RootServerInfo;
import org.openapijsonschematools.client.paths.pet.post.PetPostSecurityInfo;
import org.openapijsonschematools.client.paths.pet.post.PetPostRequestBody;
import org.openapijsonschematools.client.components.schemas.Pet;
import org.openapijsonschematools.client.servers.RootServer0;
import org.openapijsonschematools.client.servers.RootServer1;
import org.openapijsonschematools.client.servers.RootServer2;
import org.openapijsonschematools.client.securityschemes.SecurityScheme;
import org.openapijsonschematools.client.components.securityschemes.ApiKey;
import org.openapijsonschematools.client.components.securityschemes.HttpSignatureTest;
import org.openapijsonschematools.client.components.securityschemes.PetstoreAuth;
import org.openapijsonschematools.client.paths.pet.post.responses.PetPostCode200Response;
import org.openapijsonschematools.client.paths.pet.post.responses.PetPostCode405Response;
import org.openapijsonschematools.client.servers.RootServerInfo;
import org.openapijsonschematools.client.apis.paths.Pet;
import org.openapijsonschematools.client.paths.pet.post.PetPostResponses;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.AbstractMap;
// if you want to use a server that is not SERVER_0 pass it in here and change the ServerIndex input below
ApiConfiguration.ServerInfo serverInfo = new ApiConfiguration.ServerInfoBuilder()
.rootServerInfo(
new RootServerInfo.RootServerInfoBuilder()
.rootServer0(new RootServer0())
.build()
)
.build();
ApiConfiguration.ServerIndexInfo serverIndexInfo = new ApiConfiguration.ServerIndexInfoBuilder()
.rootServerInfoServerIndex(RootServerInfo.ServerIndex.SERVER_0)
.build();
List<SecurityScheme> securitySchemes = new ArrayList();
securitySchemes.add(
new ApiKey("someApiKey");
);
ApiConfiguration.SecurityIndexInfo securityIndexInfo = new ApiConfiguration.SecurityIndexInfoBuilder()
.petPostSecurityRequirementObject0SecurityIndex(PetPostSecurityRequirementObject0.SecurityIndex.SECURITY_0)
.build();
Duration timeout = Duration.ofSeconds(1L);
Map<String, List<String>> defaultHeaders = Map.of("User-Agent", List.of("OpenAPI-JSON-Schema-Generator/1.0.0/java"));
ApiConfiguration apiConfiguration = new ApiConfiguration(
serverInfo
serverIndexInfo,
securitySchemes,
securityIndexInfo,
timeout,
defaultHeaders
);
SchemaConfiguration schemaConfiguration = new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().build());
Pet apiClient = new Pet(apiConfiguration, schemaConfiguration);
Pet1BoxedMap requestBodyPayload =
Pet.Pet1.validateAndBox(
new Pet.PetMapBuilder()
.name("a")
.photoUrls(
Arrays.asList(
"a"
)
)
.id(1L)
.category(
MapUtils.makeMap(
new AbstractMap.SimpleEntry<String, Object>(
"name",
"a"
),
new AbstractMap.SimpleEntry<String, Object>(
"id",
1L
)
)
)
.tags(
Arrays.asList(
MapUtils.makeMap(
new AbstractMap.SimpleEntry<String, String>(
"name",
"a"
)
)
)
)
.status("available")
.build(),
schemaConfiguration
);
PetPostRequestBody.SealedRequestBody requestBody = new PetPostRequestBody.ApplicationjsonRequestBody(requestBodyPayload);
var request = new PetPost.PostRequestBuilder()
.requestBody(requestBody)
.build();
PetPostResponses.EndpointResponse response;
try {
response = apiClient.post(request);
} catch (PetPostCode405Response.ResponseApiException e) {
// server returned an error response defined in the openapi document
throw e;
} catch (ApiException e) {
// server returned a response/contentType not defined in the openapi document
throw e;
} catch (ValidationException e) {
// the returned response body or header values do not conform the the schema validation requirements
throw e;
} catch (IOException | InterruptedException e) {
// an exception happened when making the request
throw e;
} catch (NotImplementedException e) {
// the request body serialization or deserialization has not yet been implemented
// or the header content type deserialization has not yet been implemented for this contentType
throw e;
}
PetPostResponses.EndpointPetPostCode200Response castResponse = (PetPostResponses.EndpointPetPostCode200Response) response;
public Void put(PetPut.PutRequest request)
Parameters:
request - the input request
Returns:
nothing (Void)
Throws:
IOException, InterruptedException - an exception happened when making the request
ValidationException - the returned response body or header values do not conform the the schema validation requirements
NotImplementedException - the request body serialization or deserialization has not yet been implemented
or the header content type deserialization has not yet been implemented for this contentType
ApiException - server returned a response/contentType not defined in the openapi document
import org.openapijsonschematools.client.configurations.ApiConfiguration;
import org.openapijsonschematools.client.configurations.SchemaConfiguration;
import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags;
import org.openapijsonschematools.client.exceptions.ValidationException;
import org.openapijsonschematools.client.exceptions.NotImplementedException;
import org.openapijsonschematools.client.exceptions.ApiException;
import org.openapijsonschematools.client.schemas.validation.MapUtils;
import org.openapijsonschematools.client.schemas.validation.FrozenList;
import org.openapijsonschematools.client.schemas.validation.FrozenMap;
import org.openapijsonschematools.client.RootServerInfo;
import org.openapijsonschematools.client.paths.pet.put.PetPutSecurityInfo;
import org.openapijsonschematools.client.paths.pet.put.PetPutRequestBody;
import org.openapijsonschematools.client.components.schemas.Pet;
import org.openapijsonschematools.client.servers.RootServer0;
import org.openapijsonschematools.client.servers.RootServer1;
import org.openapijsonschematools.client.servers.RootServer2;
import org.openapijsonschematools.client.securityschemes.SecurityScheme;
import org.openapijsonschematools.client.components.securityschemes.HttpSignatureTest;
import org.openapijsonschematools.client.components.securityschemes.PetstoreAuth;
import org.openapijsonschematools.client.paths.pet.put.responses.PetPutCode400Response;
import org.openapijsonschematools.client.paths.pet.put.responses.PetPutCode404Response;
import org.openapijsonschematools.client.paths.pet.put.responses.PetPutCode405Response;
import org.openapijsonschematools.client.servers.RootServerInfo;
import org.openapijsonschematools.client.apis.paths.Pet;
import org.openapijsonschematools.client.paths.pet.put.PetPutResponses;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.AbstractMap;
// if you want to use a server that is not SERVER_0 pass it in here and change the ServerIndex input below
ApiConfiguration.ServerInfo serverInfo = new ApiConfiguration.ServerInfoBuilder()
.rootServerInfo(
new RootServerInfo.RootServerInfoBuilder()
.rootServer0(new RootServer0())
.build()
)
.build();
ApiConfiguration.ServerIndexInfo serverIndexInfo = new ApiConfiguration.ServerIndexInfoBuilder()
.rootServerInfoServerIndex(RootServerInfo.ServerIndex.SERVER_0)
.build();
List<SecurityScheme> securitySchemes = new ArrayList();
ApiConfiguration.SecurityIndexInfo securityIndexInfo = new ApiConfiguration.SecurityIndexInfoBuilder()
.petPutSecurityRequirementObject0SecurityIndex(PetPutSecurityRequirementObject0.SecurityIndex.SECURITY_0)
.build();
Duration timeout = Duration.ofSeconds(1L);
Map<String, List<String>> defaultHeaders = Map.of("User-Agent", List.of("OpenAPI-JSON-Schema-Generator/1.0.0/java"));
ApiConfiguration apiConfiguration = new ApiConfiguration(
serverInfo
serverIndexInfo,
securitySchemes,
securityIndexInfo,
timeout,
defaultHeaders
);
SchemaConfiguration schemaConfiguration = new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().build());
Pet apiClient = new Pet(apiConfiguration, schemaConfiguration);
Pet1BoxedMap requestBodyPayload =
Pet.Pet1.validateAndBox(
new Pet.PetMapBuilder()
.name("a")
.photoUrls(
Arrays.asList(
"a"
)
)
.id(1L)
.category(
MapUtils.makeMap(
new AbstractMap.SimpleEntry<String, Object>(
"name",
"a"
),
new AbstractMap.SimpleEntry<String, Object>(
"id",
1L
)
)
)
.tags(
Arrays.asList(
MapUtils.makeMap(
new AbstractMap.SimpleEntry<String, String>(
"name",
"a"
)
)
)
)
.status("available")
.build(),
schemaConfiguration
);
PetPutRequestBody.SealedRequestBody requestBody = new PetPutRequestBody.ApplicationjsonRequestBody(requestBodyPayload);
var request = new PetPut.PutRequestBuilder()
.requestBody(requestBody)
.build();
Void response;
try {
response = apiClient.put(request);
} catch (PetPutCode400Response.ResponseApiException | PetPutCode404Response.ResponseApiException | PetPutCode405Response.ResponseApiException e) {
// server returned an error response defined in the openapi document
throw e;
} catch (ApiException e) {
// server returned a response/contentType not defined in the openapi document
throw e;
} catch (ValidationException e) {
// the returned response body or header values do not conform the the schema validation requirements
throw e;
} catch (IOException | InterruptedException e) {
// an exception happened when making the request
throw e;
} catch (NotImplementedException e) {
// the request body serialization or deserialization has not yet been implemented
// or the header content type deserialization has not yet been implemented for this contentType
throw e;
}