Versionen im Vergleich

Schlüssel

  • Diese Zeile wurde hinzugefügt.
  • Diese Zeile wurde entfernt.
  • Formatierung wurde geändert.
Seiteneigenschaften

Deutsch

Dieser Artikel bietet eine Einführung in die Verwendung von Swagger zur Erstellung eines API-Clients.

API-Spezifikationen

Die index.json eines jeden Mikrodienstes enthält die jeweilige LMC-API-Spezifikation. Der Speicherort jeder index.json ist https://cloud.lancom.de/<micro-service>/api-docs/index.json.

Eine Möglichkeit, alle diese Dateien herunterzuladen, ist:

Codeblock
#!/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 bietet ein Java JAR, um Code aus einer gegebenen API-Spezifikation (index-json) zu generieren.

Sie können die neueste Version von hier herunterladen: https://github.com/swagger-api/swagger-codegen/releases

Java-Client

Das folgende Bash-Skript erzeugt einen Java-Client.

Codeblock
#!/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/"

Englisch

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:

Codeblock
#!/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.

Codeblock
#!/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/"