OpenAPI Petstore
-
API version: 1.0.0
-
Generator version: 7.21.0-SNAPSHOT
This is a sample server Petstore server. For this sample, you can use the api key special-key to test the authorization filters.
Automatically generated by the OpenAPI Generator
Building the API client library requires:
- Java 1.8+
- Maven/Gradle
To install the API client library to your local Maven repository, simply execute:
mvn clean installTo deploy it to a remote Maven repository instead, configure the settings of the repository and execute:
mvn clean deployRefer to the OSSRH Guide for more information.
Add this dependency to your project's POM:
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>petstore-resttemplate</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>Add this dependency to your project's build file:
repositories {
mavenCentral() // Needed if the 'petstore-resttemplate' jar has been published to maven central.
mavenLocal() // Needed if the 'petstore-resttemplate' jar has been published to the local maven repo.
}
dependencies {
implementation "org.openapitools:petstore-resttemplate:1.0.0"
}At first generate the JAR by executing:
mvn clean packageThen manually install the following JARs:
target/petstore-resttemplate-1.0.0.jartarget/lib/*.jar
Please follow the installation instruction and execute the following Java code:
import org.openapitools.client.*;
import org.openapitools.client.auth.*;
import org.openapitools.client.model.*;
import org.openapitools.client.api.PetApi;
public class PetApiExample {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://petstore.swagger.io/v2");
// Configure OAuth2 access token for authorization: petstore_auth
OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth");
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
PetApi apiInstance = new PetApi(defaultClient);
Pet pet = new Pet(); // Pet | Pet object that needs to be added to the store
try {
Pet result = apiInstance.addPet(pet);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#addPet");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}All URIs are relative to http://petstore.swagger.io/v2
| Class | Method | HTTP request | Description |
|---|---|---|---|
| PetApi | addPet | POST /pet | Add a new pet to the store |
Authentication schemes defined for the API:
- Type: OAuth
- Flow: implicit
- Authorization URL: http://petstore.swagger.io/api/oauth/dialog
- Scopes:
- write:pets: modify pets in your account
- read:pets: read your pets
It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issues.