File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ # ###########################################################################
3+ # Script to generate the client of a REST API from its OpenAPI descriptor
4+ # Requirements in terms of software:
5+ # apk add openjdk21 curl
6+ # ###########################################################################
7+
8+ # Constants
9+ ARTEFACT_BASE_URL=" https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli"
10+ CLI_JAR_FILE=" /tmp/openapi-generator-cli.jar"
11+ CLIENT_SOURCE_FOLDER=" client"
12+
13+ # Utility functions
14+ function write_step(){
15+ echo -e " \e[93m$1 \e[0m"
16+ }
17+
18+ # Entry point
19+ if [ " $# " -lt 1 ]; then
20+ script_name=$( basename " $0 " )
21+ echo " Usage:"
22+ echo " $script_name [OPENAPI_DESCRIPTOR_YAML_FILE] [CLIENT_TECHNOLOGY]"
23+ echo " "
24+ echo " CLIENT_TECHNOLOGY is optional and default to 'java'."
25+ echo " "
26+ echo " Call example:"
27+ echo " $script_name openapi.yml"
28+ echo " $script_name openapi.yml python"
29+ exit 1
30+ fi
31+
32+ # Main processing
33+ openapi_descriptor_file=" $1 "
34+ tech=" java"
35+ if [ $# -eq 2 ]
36+ then
37+ tech=" $2 "
38+ fi
39+ if [ ! -f $CLI_JAR_FILE ]
40+ then
41+ write_step " [+] Download the OpenAPI generator CLI from the Maven repository..."
42+ cli_version=$( curl -sk " $ARTEFACT_BASE_URL /maven-metadata.xml" | grep -F " <release>" | cut -d ' >' -f2 | cut -d ' <' -f1 | tr -d ' ' )
43+ curl -sk --output $CLI_JAR_FILE " $ARTEFACT_BASE_URL /$cli_version /openapi-generator-cli-$cli_version .jar"
44+ file $CLI_JAR_FILE
45+ fi
46+ write_step " [+] Generate the '$tech ' client code into the folder '$CLIENT_SOURCE_FOLDER ' ..."
47+ rm -rf $CLIENT_SOURCE_FOLDER /
48+ java -jar $CLI_JAR_FILE generate -g $tech -o $CLIENT_SOURCE_FOLDER -i $openapi_descriptor_file 1> /dev/null
49+ ls -l $CLIENT_SOURCE_FOLDER
You can’t perform that action at this time.
0 commit comments