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 informations 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 fact-finder setup here]/fact-finder/swagger-ui.html (your FACT-Finder-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)


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.

8. a. fill in the correct credentials into the basicAuth part and delete the OAuth2-part
8. b. set the correct name of the FactFinder channel.
8. c. insert this or a similar code-snippet to set the search-query:
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://[your fact-finder 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)

and execute:

java -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"

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

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


8. b. replace the line:


configuration = swagger_client.Configuration()


with the line:


configuration = MyConfiguration()

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


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


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


search_request = swagger_client.SearchRequest()


by these 3 lines::


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.