# How to use Swagger Codegen for the integration via API

**Swagger Codegen** can generate code for many different programming languages. Some examples are Java, Python, JavaScript, Lua and PHP. More information can be found here: <https://swagger.io/tools/swagger-codegen/>

## How to generate Java-Code with Swagger Codegen 2

1\) git clone<https://github.com/swagger-api/swagger-codegen> (if necessary, install git before you execute this command)

2\) cd swagger-codegen

3\) mvn clean package (if necessary, install the newest version of Java and Apache Maven before you execute this command)

4\) mkdir ffng-java-client (You can choose this name or any other name for this directory. For convenience sake, we will refer to this directory as **ffng-java-client**)

5\) open **https\://\[your** **FactFinder** **setup here]/Fact-Finder/swagger-ui.html** (your FactFinder-URL with an appended **/swagger-ui.html**) in your favorite browser and copy the swagger-link that appears in the header of the page. In the example screenshot below, the linked text is **./rest/v5/swagger** (don't use the invalid URL that can be seen in the screenshot)

![](https://1827019324-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQMmNfppEDkleiziCG4Gp%2Fuploads%2Fgit-blob-cf0acc535d843bf6b8f8f5b227d8ea0c71532b10%2Fimage-114.png?alt=media)

and execute:

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i \[your swagger-link here] -l java -o ./ffng-java-client

You just generated example code for clients that can send all kinds of requests that FactFinder accepts.

6\) cd ffng-java-client

7\) copy the **Search with POST** code-example from **ffng-java-client/docs/SearchApi.md** into a java sourcecode file, for example **src/main/java/examplecompany/ExampleSearchClient.java** and insert necessary parts, like `package examplecompany;` and `public class ExampleSearchClient{`.

Make the generated classes, see (5), available in your project's classpath.

8a) fill in the correct credentials into the **basicAuth** part and delete the **OAuth2-part**

8b) set the correct name of the FactFinder channel.

8c) insert this or a similar code-snippet to set the search-query:

```language-plaintext
SearchParams searchParams= new SearchParams();
searchParams.setQuery("*");
searchRequest.setParams(searchParams);
```

9\) mvn clean install

10\) Run your first example search client. As maven was used to build the project, one easy way is to start your example search with maven, too:\
mvn exec:java -Dexec.mainClass=examplecompany.ExampleSearchClient

> (use mvn exec:java -D"exec.mainClass"=examplecompany.ExampleSearchClient if you are using **Window's Powershell**)

All other requests can be created in a similar manner. You can find code examples for them in the md-files in the generated docs-folder.

## How to generate Python-Code with Swagger CodeGen 2

1\) git clone<https://github.com/swagger-api/swagger-codegen> (if necessary install git before you execute this command)

2\) cd swagger-codegen

3\) mvn clean package (if necessary install the newest version of Java and Apache Maven before you execute this command)

4\) mkdir ffng-python-client

5\) open **https:FactFinder setup here]/Fact-Finder/swagger-ui.html** (your FactFinder-URL with an appended **/swagger-ui.html**) in your favorite browser and copy the swagger-link that appears in the header of the page. In the example screenshot below, the linked text is **./rest/v5/swagger** (don't use the invalid URL that can be seen in the screenshot)

![](https://1827019324-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQMmNfppEDkleiziCG4Gp%2Fuploads%2Fgit-blob-cf0acc535d843bf6b8f8f5b227d8ea0c71532b10%2Fimage-46.png?alt=media)

and execute:

-jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i \[your swagger-link here] -l python -o ./ffng-python-client

You just generated example code for clients that can send all kinds of requests that FactFinder accepts.

6\) cd ffng-python-client

7\) copy the **Search with POST** code-example from **ffng-python-client/docs/SearchApi.md** into a python sourcecode file, for example **my-example-search-client.py**

8a) insert the following python-code into your python file:

```language-python
class MyConfiguration(swagger_client.Configuration):
 def auth_settings(self):
 return {
 'basicAuth':
 {
 'type': 'basic',
 'in': 'header',
 'key': 'Authorization',
 'value': self.get_basic_auth_token()
 }
 }
```

8b) replace the line:

```language-python
configuration = swagger_client.Configuration()
```

with the line:

```language-python
configuration = MyConfiguration()
```

9a) fill in the correct credentials into the **basicAuth part** and delete the **OAuth2-part**

9b) set the correct name of the FactFinder channel.

9c) insert this or a similar code-snippet to set the search-query by replacing this line:

```language-python
search_request = swagger_client.SearchRequest()
```

by these 3 lines::

```language-python
query = "*"
search_params = swagger_client.SearchParams(query=query)
search_request = swagger_client.SearchRequest(search_params)
```

10. start your search-client and see the JSON-search result printed to standard-out.

All other requests can be created in a similar manner. You can find code examples for them in the md-files in the generated docs-folder.
