# openapi-java-client

Service Catalog APIs
- API version: 1.0

This specifies a **RESTful API** for Service Catalog.

# Authentication
Our REST APIs are protected using OAuth2 and access control is achieved through scopes. Before you start invoking
the the API you need to obtain an access token with the required scopes. This guide will walk you through the steps
that you will need to follow to obtain an access token.
First you need to obtain the consumer key/secret key pair by calling the dynamic client registration (DCR) endpoint. You can add your preferred grant types
in the payload. A Sample payload is shown below.
```
  {
  \"callbackUrl\":\"www.google.lk\",
  \"clientName\":\"rest_api_service_catalog\",
  \"owner\":\"admin\",
  \"grantType\":\"client_credentials password refresh_token\",
  \"saasApp\":true
  }
```
Create a file (payload.json) with the above sample payload, and use the cURL shown bellow to invoke the DCR endpoint. Authorization header of this should contain the
base64 encoded admin username and password.
**Format of the request**
```
  curl -X POST -H \"Authorization: Basic Base64(admin_username:admin_password)\" -H \"Content-Type: application/json\"
  \\ -d @payload.json https://<host>:<servlet_port>/client-registration/v0.17/register
```
**Sample request**
```
  curl -X POST -H \"Authorization: Basic YWRtaW46YWRtaW4=\" -H \"Content-Type: application/json\"
  \\ -d @payload.json https://localhost:9443/client-registration/v0.17/register
```
Following is a sample response after invoking the above curl.
```
{
\"clientId\": \"fOCi4vNJ59PpHucC2CAYfYuADdMa\",
\"clientName\": \"rest_api_service_catalog\",
\"callBackURL\": \"www.google.lk\",
\"clientSecret\": \"a4FwHlq0iCIKVs2MPIIDnepZnYMa\",
\"isSaasApplication\": true,
\"appOwner\": \"admin\",
\"jsonString\": \"{\\\"grant_types\\\":\\\"client_credentials password refresh_token\\\",\\\"redirect_uris\\\":\\\"www.google.lk\\\",\\\"client_name\\\":\\\"rest_api123\\\"}\",
\"jsonAppAttribute\": \"{}\",
\"tokenType\": null
}
```
Next you must use the above client id and secret to obtain the access token.
We will be using the password grant type for this, you can use any grant type you desire.
You also need to add the proper **scope** when getting the access token. All possible scopes for Service Catalog REST API can be viewed in **OAuth2 Security** section
of this document and scope for each resource is given in **authorization** section of resource documentation.
Following is the format of the request if you are using the password grant type.
```
curl -k -d \"grant_type=password&username=<admin_username>&password=<admin_passowrd>&scope=<scopes seperated by space>\"
\\ -H \"Authorization: Basic base64(cliet_id:client_secret)\"
\\ https://<host>:<servlet_port>/oauth2/token
```
**Sample request**
```
curl https://localhost:9443/oauth2/token -k \\
-H \"Authorization: Basic Zk9DaTR2Tko1OVBwSHVjQzJDQVlmWXVBRGRNYTphNEZ3SGxxMGlDSUtWczJNUElJRG5lcFpuWU1h\" \\
-d \"grant_type=password&username=admin&password=admin&scope=service_catalog:service_view service_catalog:service_write\"
```
Shown below is a sample response to the above request.
```
{
\"access_token\": \"e79bda48-3406-3178-acce-f6e4dbdcbb12\",
\"refresh_token\": \"a757795d-e69f-38b8-bd85-9aded677a97c\",
\"scope\": \"service_catalog:service_view service_catalog:service_write\",
\"token_type\": \"Bearer\",
\"expires_in\": 3600
}
```
Now you have a valid access token, which you can use to invoke an API.
Navigate through the API descriptions to find the required API, obtain an access token as described above and invoke the API with the authentication header.
If you use a different authentication mechanism, this process may change.



*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)*


## Requirements

Building the API client library requires:
1. Java 1.7+
2. Maven/Gradle

## Installation

To install the API client library to your local Maven repository, simply execute:

```shell
mvn clean install
```

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

```shell
mvn clean deploy
```

Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information.

### Maven users

Add this dependency to your project's POM:

```xml
<dependency>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-java-client</artifactId>
  <version>1.0</version>
  <scope>compile</scope>
</dependency>
```

### Gradle users

Add this dependency to your project's build file:

```groovy
compile "org.openapitools:openapi-java-client:1.0"
```

### Others

At first generate the JAR by executing:

```shell
mvn clean package
```

Then manually install the following JARs:

* `target/openapi-java-client-1.0.jar`
* `target/lib/*.jar`

## Getting Started

Please follow the [installation](#installation) instruction and execute the following Java code:

```java

// Import classes:
import org.wso2.am.integration.clients.service.catalog.api.ApiClient;
import org.wso2.am.integration.clients.service.catalog.api.ApiException;
import org.wso2.am.integration.clients.service.catalog.api.Configuration;
import org.wso2.am.integration.clients.service.catalog.api.auth.*;
import org.wso2.am.integration.clients.service.catalog.api.models.*;
import org.wso2.am.integration.clients.service.catalog.api.v1.ServicesApi;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://apis.wso2.com/api/service-catalog/v1");
    
    // Configure OAuth2 access token for authorization: OAuth2Security
    OAuth OAuth2Security = (OAuth) defaultClient.getAuthentication("OAuth2Security");
    OAuth2Security.setAccessToken("YOUR ACCESS TOKEN");

    ServicesApi apiInstance = new ServicesApi(defaultClient);
    ServiceDTO serviceMetadata = new ServiceDTO(); // ServiceDTO | 
    File definitionFile = new File("/path/to/file"); // File | 
    String inlineContent = "inlineContent_example"; // String | Inline content of the document
    try {
      ServiceDTO result = apiInstance.addService(serviceMetadata, definitionFile, inlineContent);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ServicesApi#addService");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

```

## Documentation for API Endpoints

All URIs are relative to *https://apis.wso2.com/api/service-catalog/v1*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*ServicesApi* | [**addService**](docs/ServicesApi.md#addService) | **POST** /services | Add a new service to Service Catalog
*ServicesApi* | [**deleteService**](docs/ServicesApi.md#deleteService) | **DELETE** /services/{serviceId} | Delete a service
*ServicesApi* | [**exportService**](docs/ServicesApi.md#exportService) | **GET** /services/export | Export a service
*ServicesApi* | [**getServiceById**](docs/ServicesApi.md#getServiceById) | **GET** /services/{serviceId} | Get details of a service
*ServicesApi* | [**getServiceDefinition**](docs/ServicesApi.md#getServiceDefinition) | **GET** /services/{serviceId}/definition | Retrieve a service definition
*ServicesApi* | [**getServiceUsage**](docs/ServicesApi.md#getServiceUsage) | **GET** /services/{serviceId}/usage | Retrieve the API Info that use the given service
*ServicesApi* | [**importService**](docs/ServicesApi.md#importService) | **POST** /services/import | Import a service
*ServicesApi* | [**searchServices**](docs/ServicesApi.md#searchServices) | **GET** /services | Retrieve/search services
*ServicesApi* | [**updateService**](docs/ServicesApi.md#updateService) | **PUT** /services/{serviceId} | Update a service
*SettingsApi* | [**getSettings**](docs/SettingsApi.md#getSettings) | **GET** /settings | Retrieve service catalog API settings


## Documentation for Models

 - [APIInfoDTO](docs/APIInfoDTO.md)
 - [APIListDTO](docs/APIListDTO.md)
 - [ErrorDTO](docs/ErrorDTO.md)
 - [ErrorListItemDTO](docs/ErrorListItemDTO.md)
 - [PaginationDTO](docs/PaginationDTO.md)
 - [ServiceDTO](docs/ServiceDTO.md)
 - [ServiceInfoDTO](docs/ServiceInfoDTO.md)
 - [ServiceInfoListDTO](docs/ServiceInfoListDTO.md)
 - [ServiceListDTO](docs/ServiceListDTO.md)
 - [ServiceListExpandedDTO](docs/ServiceListExpandedDTO.md)
 - [ServiceSchemaDTO](docs/ServiceSchemaDTO.md)
 - [SettingsDTO](docs/SettingsDTO.md)
 - [VerifierDTO](docs/VerifierDTO.md)


## Documentation for Authorization

Authentication schemes defined for the API:
### OAuth2Security

- **Type**: OAuth
- **Flow**: password
- **Authorization URL**: 
- **Scopes**: 
  - service_catalog:service_view: view access to services in service catalog
  - service_catalog:service_write: write access to services in service catalog
  - apim:api_view: view access to services for read only users


## Recommendation

It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.

## Author



