Created
November 7, 2023 11:45
-
-
Save ayoubAnbara/11751ad967d846064ad4eba072dba5ee to your computer and use it in GitHub Desktop.
Generate Java SDK to Automate SP-API Amazon calls
This file contains 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
#!/bin/bash | |
# Download the Swagger Code Generator from https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/ | |
# clone models: git clone https://github.com/amzn/selling-partner-api-models | |
# put all model.json files in directory with name models | |
# excute this script | |
# Credit: | |
# 1- https://developer-docs.amazon.com/sp-api-blog/docs/automate-your-sp-api-calls-using-java-sdk#tutorial | |
# 2- https://jesseevers.com/spapi-first-application/ | |
cd models | |
basePackage="com.amazon.sellingpartner" | |
#$FILES="models/*" | |
# For every model in the models/ directory, and all subdirectories: | |
for model in * | |
do | |
modelName=$(echo $model | cut -d"/" -f3 | cut -d"." -f1) | |
# Generate a client library | |
# --input-spec $model :: use the current model file | |
# --lang java :: generate a Java library | |
# --template-dir .../ :: use Amazon's premade Java template files | |
# --output ../spapi :: put the generated library in ../spapi | |
# --invoker-package "..." :: put the generated code in the given package | |
# --api-package "..." :: put the generated api code in the given package | |
# --model-package "..." :: put the generated model code in the given package | |
# --group-id "..." :: package metadata | |
# --artifact-id "..." :: package metadata | |
# --additional-properties dateLibrary=java8 :: Use Java 8 date libraries | |
echo "Processing model: $modelName" | |
java -jar ../swagger-codegen-cli.jar generate \ | |
--input-spec $model \ | |
--lang java \ | |
--template-dir ../selling-partner-api-models/clients/sellingpartner-api-aa-java/resources/swagger-codegen/templates/ \ | |
--output ../SwaggerToCL/spapi \ | |
-c ../selling-partner-api-models/clients/sellingpartner-api-aa-java/resources/java/config.json \ | |
--invoker-package "$basePackage" \ | |
--api-package "$basePackage.api" \ | |
--model-package "$basePackage.model.$modelName" \ | |
--group-id "com.amazon" \ | |
--artifact-id "selling-partner-api" \ | |
--additional-properties dateLibrary=java8 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment