-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add java generator #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
978209e
feat: add java generator
marceljk af712f4
review feedback
marceljk f52a7b5
adjust generator config
marceljk 9db79a5
review feedback
marceljk f45a2d9
removed generated docs
marceljk 3d6c6e5
- remove invalid characters for valid Java package name
marceljk e674c59
update README.md
marceljk f5ea0a2
removed underscore in package names
marceljk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
templateDir: templates/java | ||
additionalProperties: | ||
artifactUrl: https://github.com/stackitcloud/stackit-sdk-java | ||
developerName: STACKIT Developer Tools | ||
developerEmail: developer-tools@stackit.cloud | ||
developerOrganization: STACKIT | ||
developerOrganizationUrl: https://www.stackit.de | ||
groupId: cloud.stackit | ||
hideGenerationTimestamp: true | ||
licenseName: Apache License 2.0 | ||
licenseUrl: http://www.apache.org/licenses/ | ||
scmConnection: scm:git@github.com:stackitcloud/stackit-sdk-java.git | ||
scmDeveloperConnection: scm:git@github.com:stackitcloud/stackit-sdk-java.git | ||
scmUrl: https://github.com/stackitcloud/stackit-sdk-java |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
git_push.sh | ||
.travis.yml | ||
.gitignore | ||
api/openapi.yaml | ||
tox.ini | ||
**/.github/** | ||
**/AndroidManifest.xml | ||
pom.xml | ||
build.sbt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
#!/bin/bash | ||
# This script clones the SDK repo and updates it with the generated API modules | ||
# Pre-requisites: Java | ||
set -eo pipefail | ||
|
||
ROOT_DIR=$(git rev-parse --show-toplevel) | ||
SDK_REPO_LOCAL_PATH="${ROOT_DIR}/sdk-repo-updated" | ||
|
||
SERVICES_FOLDER="${SDK_REPO_LOCAL_PATH}/services" | ||
|
||
GENERATOR_LOG_LEVEL="error" # Must be a Java log level (error, warn, info...) | ||
|
||
INCLUDE_SERVICES=("resourcemanager") | ||
|
||
generate_java_sdk() { | ||
# Required parameters | ||
local GENERATOR_JAR_PATH=$1 | ||
local GIT_HOST=$2 | ||
local GIT_USER_ID=$3 | ||
|
||
# Optional parameters | ||
local GIT_REPO_ID=$4 | ||
local SDK_REPO_URL=$5 | ||
local SDK_BRANCH=$6 | ||
|
||
# Check required parameters | ||
if [[ -z ${GIT_HOST} ]]; then | ||
echo "! GIT_HOST not specified." | ||
exit 1 | ||
fi | ||
|
||
if [[ -z ${GIT_USER_ID} ]]; then | ||
echo "! GIT_USER_ID id not specified." | ||
exit 1 | ||
fi | ||
|
||
# Check optional parameters and set defaults if not provided | ||
if [[ -z ${GIT_REPO_ID} ]]; then | ||
echo "GIT_REPO_ID not specified, default will be used." | ||
GIT_REPO_ID="stackit-sdk-java" | ||
fi | ||
|
||
if [[ -z ${SDK_REPO_URL} ]]; then | ||
echo "SDK_REPO_URL not specified, default will be used." | ||
SDK_REPO_URL="https://github.com/stackitcloud/stackit-sdk-java.git" | ||
fi | ||
|
||
# Prepare folders | ||
if [[ ! -d $SERVICES_FOLDER ]]; then | ||
mkdir -p "$SERVICES_FOLDER" | ||
fi | ||
|
||
# Clone SDK repo | ||
if [ -d ${SDK_REPO_LOCAL_PATH} ]; then | ||
echo "Old SDK repo clone was found, it will be removed." | ||
rm -rf ${SDK_REPO_LOCAL_PATH} | ||
fi | ||
git clone --quiet -b ${SDK_BRANCH} ${SDK_REPO_URL} ${SDK_REPO_LOCAL_PATH} | ||
|
||
# Backup of the current state of the SDK services dir (services/) | ||
sdk_services_backup_dir=$(mktemp -d) | ||
if [[ ! ${sdk_services_backup_dir} || -d {sdk_services_backup_dir} ]]; then | ||
echo "! Unable to create temporary directory" | ||
exit 1 | ||
fi | ||
cleanup() { | ||
rm -rf ${sdk_services_backup_dir} | ||
} | ||
cp -a "${SERVICES_FOLDER}/." ${sdk_services_backup_dir} | ||
|
||
# Cleanup after we are done | ||
trap cleanup EXIT | ||
|
||
# Remove old contents of services dir (services/) | ||
rm -rf ${SERVICES_FOLDER} | ||
|
||
# Generate SDK for each service | ||
for service_json in ${ROOT_DIR}/oas/*.json; do | ||
service="${service_json##*/}" | ||
service="${service%.json}" | ||
|
||
# Remove invalid characters to ensure a valid Java pkg name | ||
service="${service//-/}" # remove dashes | ||
service="${service// /}" # remove spaces | ||
service=$(echo "${service}" | tr '[:upper:]' '[:lower:]') # convert upper case letters to lower case | ||
service=$(echo "${service}" | tr -d -c '[:alnum:]') # remove non-alphanumeric characters | ||
|
||
# Ensure the package name doesn't start with a number | ||
if [[ "${service}" =~ ^[0-9] ]]; then | ||
service="_${service}" # Prepend a valid prefix if it starts with a number | ||
fi | ||
|
||
if ! [[ ${INCLUDE_SERVICES[*]} =~ ${service} ]]; then | ||
echo "Skipping not included service ${service}" | ||
continue | ||
fi | ||
|
||
if grep -E "^$service$" ${ROOT_DIR}/blacklist.txt; then | ||
echo "Skipping blacklisted service ${service}" | ||
continue | ||
fi | ||
|
||
echo ">> Generating \"${service}\" service..." | ||
cd ${ROOT_DIR} | ||
|
||
mkdir -p "${SERVICES_FOLDER}/${service}/" | ||
cp "${ROOT_DIR}/scripts/generate-sdk/.openapi-generator-ignore-java" "${SERVICES_FOLDER}/${service}/.openapi-generator-ignore" | ||
|
||
SERVICE_DESCRIPTION=$(cat ${service_json} | jq .info.title --raw-output) | ||
|
||
# Run the generator | ||
java -Dlog.level=${GENERATOR_LOG_LEVEL} -jar ${jar_path} generate \ | ||
--generator-name java \ | ||
--input-spec "${service_json}" \ | ||
--output "${SERVICES_FOLDER}/${service}" \ | ||
--git-host ${GIT_HOST} \ | ||
--git-user-id ${GIT_USER_ID} \ | ||
--git-repo-id ${GIT_REPO_ID} \ | ||
--global-property apis,models,modelTests=false,modelDocs=false,apiDocs=false,apiTests=false,supportingFiles \ | ||
rubenhoenle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--additional-properties=artifactId="stackit-sdk-${service}",artifactDescription="${SERVICE_DESCRIPTION}",invokerPackage="cloud.stackit.sdk.${service}",modelPackage="cloud.stackit.sdk.${service}.model",apiPackage="cloud.stackit.sdk.${service}.api" >/dev/null \ | ||
--http-user-agent stackit-sdk-java/"${service}" \ | ||
--config openapi-generator-config-java.yml | ||
|
||
# Remove unnecessary files | ||
rm "${SERVICES_FOLDER}/${service}/.openapi-generator-ignore" | ||
rm -r "${SERVICES_FOLDER}/${service}/.openapi-generator/" | ||
rm "${SERVICES_FOLDER}/${service}/.github/workflows/maven.yml" | ||
|
||
# If the service has a README.md file, move them inside the service folder | ||
if [ -f ${sdk_services_backup_dir}/${service}/README.md ]; then | ||
echo "Found ${service} \"README.md\" file" | ||
cp -r ${sdk_services_backup_dir}/${service}/README.md ${SERVICES_FOLDER}/${service}/README.md | ||
fi | ||
|
||
# If the service has a CHANGELOG file, move it inside the service folder | ||
if [ -f ${sdk_services_backup_dir}/${service}/CHANGELOG.md ]; then | ||
echo "Found ${service} \"CHANGELOG\" file" | ||
cp -r ${sdk_services_backup_dir}/${service}/CHANGELOG.md ${SERVICES_FOLDER}/${service}/CHANGELOG.md | ||
fi | ||
|
||
# If the service has a LICENSE file, move it inside the service folder | ||
if [ -f ${sdk_services_backup_dir}/${service}/LICENSE.md ]; then | ||
echo "Found ${service} \"LICENSE\" file" | ||
cp -r ${sdk_services_backup_dir}/${service}/LICENSE.md ${SERVICES_FOLDER}/${service}/LICENSE.md | ||
fi | ||
|
||
# If the service has a NOTICE file, move it inside the service folder | ||
if [ -f ${sdk_services_backup_dir}/${service}/NOTICE.txt ]; then | ||
echo "Found ${service} \"NOTICE\" file" | ||
cp -r ${sdk_services_backup_dir}/${service}/NOTICE.txt ${SERVICES_FOLDER}/${service}/NOTICE.txt | ||
rubenhoenle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fi | ||
|
||
# If the service has a VERSION file, move it inside the service folder | ||
if [ -f ${sdk_services_backup_dir}/${service}/VERSION ]; then | ||
echo "Found ${service} \"VERSION\" file" | ||
cp -r ${sdk_services_backup_dir}/${service}/VERSION ${SERVICES_FOLDER}/${service}/VERSION | ||
fi | ||
|
||
done | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Java templates | ||
|
||
This folder contains only our customized Java templates. Beside these customized templates, | ||
the original templates of openapi-generator for Java are used. These can be found in the | ||
official GitHub repo of the [openapi-generator](https://github.com/OpenAPITools/openapi-generator/tree/v7.14.0/modules/openapi-generator/src/main/resources/Java). | ||
|
||
If you need to change something in the Java Generator, try always first to add | ||
[user-defined templates](https://openapi-generator.tech/docs/customization#user-defined-templates), | ||
instead of overwriting existing templates. These ensure an easier upgrade process, to newer | ||
versions of the openapi-generator. | ||
|
||
If it's required to customize the original templates, you can copy them into this directory. | ||
Try to minimize the customization as much as possible, to ensure, that we can easily upgrade | ||
to newer versions in the future. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.