This section provides an introduction on how to use Swagger to generate an API client.
API Specifications
The index.json
of each micro-service contains its respective LMC API specification. The location of each index.json
is
https://cloud.lancom.de/<micro-service>/api-docs/index.json
.
One way of downloading all of these files is:
#!/bin/bash BASEURL=https://cloud.lancom.de # change this if you are using a private LMC if [ ! -d api-spec ]; then mkdir api-spec fi for i in auth backstage config control devices devicetunnel dsc \ fields geolocation jobs logging messaging monitoring notification \ preferences; # add missing services here do wget $BASEURL/cloud-service-$i/api-docs/index.json -O api-spec/$i.json done
Swagger Code Generator
Swagger provides a Java JAR to generate code from a given API specification (index-json
).
You can download the latest release from here: https://github.com/swagger-api/swagger-codegen/releases
Java Client
The following bash script generates a java client.
#!/bin/bash # usage: # command <index.json> <output-dir> java -Dapis -Dmodels -DsupportingFiles -Dmodels -jar swagger-codegen-cli.jar \ generate -l java \ --library resttemplate \ --additional-properties java8=true \ --api-package de.lcs.lmc.api \ --model-package de.lcs.lmc.dto \ --group-id de.lcs.lmc \ --artifact-id de.lcs.lmc.$(basename $1 .json) \ --artifact-version v1.0 \ -DdateLibrary=other \ -i $1 -o "$2/"