How to use Swagger Codegen for the integration via API
Generate REST API clients with Swagger Codegen for Java or Python to speed up your FactFinder integration.
Swagger Codegen can generate client code for many programming languages, including Java, Python, JavaScript, Lua, and PHP. Learn more here: https://swagger.io/tools/swagger-codegen/
How to generate Java code with Swagger Codegen 2
1) Clone the Swagger Codegen repository:
git clone https://github.com/swagger-api/swagger-codegen
If needed, install Git first.
2) Move into the repository:
cd swagger-codegen
3) Build the project:
mvn clean package
If needed, install a current Java version and Apache Maven first.
4) Create an output directory:
mkdir ffng-java-client
You can choose any directory name. For convenience, this guide uses ffng-java-client.
5) Open https://[your FactFinder setup here]/Fact-Finder/swagger-ui.html in your browser and copy the Swagger link shown in the page header. In the screenshot below, the linked text is ./rest/v5/swagger. Do not use the invalid URL shown in the screenshot.

Then run:
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i [your swagger-link here] -l java -o ./ffng-java-client
This generates example client code for all request types supported by FactFinder.
6) Move into the generated client directory:
cd ffng-java-client
7) Copy the Search with POST example from ffng-java-client/docs/SearchApi.md into a Java source file, for example src/main/java/examplecompany/ExampleSearchClient.java. Add the missing parts, such as package examplecompany; and public class ExampleSearchClient {.
Make the generated classes from step 5 available in your project’s classpath.
8a) Enter the correct credentials in the basicAuth section and remove the OAuth2 section.
8b) Set the correct FactFinder channel name.
8c) Insert this or a similar code snippet to set the search query:
9) Build the client:
mvn clean install
10) Run your first example search client. Since Maven was used to build the project, an easy option is to start it with Maven as well:
mvn exec:java -Dexec.mainClass=examplecompany.ExampleSearchClient
Use
mvn exec:java -D"exec.mainClass"=examplecompany.ExampleSearchClientif you are using Windows PowerShell.
All other requests can be created in a similar way. You can find code examples for them in the Markdown files in the generated docs folder.
How to generate Python code with Swagger Codegen 2
1) Clone the Swagger Codegen repository:
git clone https://github.com/swagger-api/swagger-codegen
If needed, install Git first.
2) Move into the repository:
cd swagger-codegen
3) Build the project:
mvn clean package
If needed, install a current Java version and Apache Maven first.
4) Create an output directory:
mkdir ffng-python-client
5) Open https://[your FactFinder setup here]/Fact-Finder/swagger-ui.html in your browser and copy the Swagger link shown in the page header. In the screenshot below, the linked text is ./rest/v5/swagger. Do not use the invalid URL shown in the screenshot.

Then run:
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i [your swagger-link here] -l python -o ./ffng-python-client
This generates example client code for all request types supported by FactFinder.
6) Move into the generated client directory:
cd ffng-python-client
7) Copy the Search with POST example from ffng-python-client/docs/SearchApi.md into a Python source file, for example my-example-search-client.py.
8a) Insert the following Python code into your file:
8b) replace the line:
with the line:
9a) Enter the correct credentials in the basicAuth section and remove the OAuth2 section.
9b) Set the correct FactFinder channel name.
9c) Insert this or a similar code snippet to set the search query by replacing this line:
with these three lines:
Start your search client and review the JSON search result printed to standard output.
All other requests can be created in a similar way. You can find code examples for them in the Markdown files in the generated docs folder.
Last updated
Was this helpful?

