Skip to content

Commit

Permalink
Merge pull request #1 from plughacker/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
marcelnicolay authored Jun 28, 2023
2 parents caec761 + 9b265ef commit 522d5f2
Show file tree
Hide file tree
Showing 236 changed files with 35,381 additions and 19,516 deletions.
36 changes: 34 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,39 @@
hs_err_pid*

# build files
target/out
target/openapi-generator-cli.jar
target
.gradle
build

.env

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# General
.DS_Store
.AppleDouble
.LSOverride
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 85 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,93 @@ openapi-generator-cli:=java -jar $(openapi-generator-jar)

generator:=java
library:=okhttp-gson
src_dir:=src/main/java/com/malga/client
output:=target/out
spec:=malga-api
modelGen:=clienttoken charges cards customers sessions
models:=src/main/java/io/malga/model

models: target/spec $(openapi-generator-jar)
rm -rf $(src_dir) $(output)
mkdir -p $(output)
# Generate models (for each service)
models: $(modelGen)

clienttoken: spec=auth-v1
charges: spec=charges-v1
cards: spec=cards-v1
customers: spec=customers-v1
sessions: spec=sessions-v1

bigServices:=clienttoken charges cards customers sessions

services: $(bigServices)

$(modelGen): target/spec $(openapi-generator-jar)
rm -rf $(models)/$@ $(output)
$(openapi-generator-cli) generate \
-i target/spec/openapi/resources/$(spec).yaml \
-g $(generator) \
-o $(output) \
-t templates \
--reserved-words-mappings configuration=configuration \
--ignore-file-override ./.openapi-generator-ignore \
--skip-validate-spec \
--library $(library) \
--model-package $(subst /,.,io.malga.model.$@) \
--api-name-suffix Api \
--global-property modelDocs=false \
--global-property modelTests=false \
--additional-properties=disallowAdditionalPropertiesIfNotPresent=false \
--additional-properties=dateLibrary=java8 \
--additional-properties=serializationLibrary=gson \
--additional-properties=openApiNullable=false \
--openapi-normalizer REMOVE_ANYOF_ONEOF_AND_KEEP_PROPERTIES_ONLY=true \
--openapi-normalizer SIMPLIFY_ANYOF_STRING_AND_ENUM_STRING=true \
--openapi-normalizer SIMPLIFY_BOOLEAN_ENUM=true \
--openapi-normalizer SIMPLIFY_ONEOF_ANYOF=true
mv $(output)/$(models)/$@ $(models)/$@
mv $(output)/$(models)/JSON.java $(models)/$@

$(bigServices): target/spec $(openapi-generator-jar)
rm -rf $(models)/$@ $(output)
rm -rf src/main/java/io/malga/service/$@ $(output)
$(openapi-generator-cli) generate \
-i target/spec/json/$(spec).json \
-g $(generator) \
-o $(output) \
--reserved-words-mappings configuration=configuration \
--ignore-file-override ./.openapi-generator-ignore \
--skip-validate-spec \
--library $(library) \
--model-package $(subst /,.,com.malga.client.api.model) \
--api-package com.malga.client.api \
--api-name-suffix Api \
--global-property modelDocs=false \
--global-property modelTests=false \
--additional-properties=disallowAdditionalPropertiesIfNotPresent=false \
--additional-properties=dateLibrary=java8 \
--additional-properties=serializationLibrary=gson \
--additional-properties=openApiNullable=false \
--openapi-normalizer REMOVE_ANYOF_ONEOF_AND_KEEP_PROPERTIES_ONLY=true \
--openapi-normalizer SIMPLIFY_ANYOF_STRING_AND_ENUM_STRING=true \
--openapi-normalizer SIMPLIFY_BOOLEAN_ENUM=true \
--openapi-normalizer SIMPLIFY_ONEOF_ANYOF=true
mkdir -p $(src_dir)
mv $(output)/$(src_dir)/* $(src_dir)/
-i target/spec/openapi/resources/$(spec).yaml \
-g $(generator) \
-o $(output) \
-t templates \
--reserved-words-mappings configuration=configuration \
--ignore-file-override ./.openapi-generator-ignore \
--skip-validate-spec \
--model-package $(subst /,.,io.malga.model.$@) \
--library $(library) \
--api-package io.malga.service.$@ \
--api-name-suffix Api \
--global-property modelDocs=false \
--global-property modelTests=false \
--additional-properties=openApiNullable=false \
--additional-properties=disallowAdditionalPropertiesIfNotPresent=false \
--additional-properties=dateLibrary=java8 \
--additional-properties=serializationLibrary=gson \
--additional-properties=openApiNullable=false \
--openapi-normalizer REMOVE_ANYOF_ONEOF_AND_KEEP_PROPERTIES_ONLY=true \
--openapi-normalizer SIMPLIFY_ANYOF_STRING_AND_ENUM_STRING=true \
--openapi-normalizer SIMPLIFY_BOOLEAN_ENUM=true \
--openapi-normalizer SIMPLIFY_ONEOF_ANYOF=true
mv $(output)/$(models)/$@ $(models)/$@
mv $(output)/src/main/java/io/malga/service/JSON.java $(models)/$@
mv $(output)/src/main/java/io/malga/service/$@ src/main/java/io/malga/service/$@

$(openapi-generator-jar):
wget --quiet -o /dev/null $(openapi-generator-url) -O $(openapi-generator-jar)
wget --quiet -o /dev/null $(openapi-generator-url) -O $(openapi-generator-jar)

clean:
rm -rf $(output)
rm -rf target/spec
rm -rf target/templates
rm -f target/openapi-generator-cli.jar

target/spec: $(openapi-generator-jar)
git clone https://github.com/plughacker/malga-openapi.git target/spec

# Extract templates
templates: $(openapi-generator-jar)
$(openapi-generator-cli) author template -g $(generator) --library $(library) -o target/templates

.PHONY: models $(services)
116 changes: 58 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,67 +49,67 @@ Please follow the [installation](#installation) instruction and execute the foll
```java

// Import classes:
import com.malga.client.ApiClient;
import com.malga.client.ApiException;
import com.malga.client.Configuration;
import com.malga.client.auth.*;
import com.malga.client.models.*;
import com.malga.client.api.ChargesApi;

import io.malga.client.ApiClient;
import io.malga.client.ApiException;
import io.malga.client.Configuration;
import io.malga.client.models.charge.*;
import io.malga.client.service.charges.ChargesApi;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://sandbox-api.malga.io");

// Configure API key authorization: X-Client-ID
ApiKeyAuth clientID = (ApiKeyAuth) defaultClient.getAuthentication("X-Client-ID");
clientID.setApiKey("YOUR CLIENT ID");

// Configure API key authorization: X-Api-Key
ApiKeyAuth apiKey = (ApiKeyAuth) defaultClient.getAuthentication("X-Api-Key");
apiKey.setApiKey("YOUR API KEY");

ChargesApi chargesApi = new ChargesApi(defaultClient);

ChargeRequest chargeRequest = createCardChargeRequest();
ChargeResponse chargeResponse = chargesApi.charge(chargeRequest);

SourceTypeCard cardOneShot = ((new SourceTypeCard())
.sourceType("card")
.card((new TokenRequest())
.cardExpirationDate("12/2025")
.cardHolderName("John Doe")
.cardNumber("4929564637987814")
.cardCvv("410")
));

PaymentMethodCard paymentMethodCard = (new PaymentMethodCard())
.paymentType(PaymentMethodCard.PaymentTypeEnum.CREDIT)
.installments(1);

ChargeRequest chargeRequest (new ChargeRequest())
.capture(false)
.statementDescriptor("should be statement descriptor")
.merchantId("YOUR MERCHANT ID")
.amount(1000)
.orderId("1234567890")
.capture(false)
.paymentSource((new ChargeRequestPaymentSource(cardOneShot)))
.paymentMethod((new ChargeRequestPaymentMethod(paymentMethodCard)));

ChargesApi chargesApi = new ChargesApi(defaultClient);

try {
ChargeResponse chargeResponse = chargesApi.charge(chargeRequest);
System.out.println(chargeResponse);
} catch (ApiException e) {
System.err.println("Exception when calling CardsApi#getCardById");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://sandbox-api.malga.io");

// Configure API key authorization: X-Client-ID
ApiKeyAuth clientID = (ApiKeyAuth) defaultClient.getAuthentication("X-Client-ID");
clientID.setApiKey("YOUR CLIENT ID");

// Configure API key authorization: X-Api-Key
ApiKeyAuth apiKey = (ApiKeyAuth) defaultClient.getAuthentication("X-Api-Key");
apiKey.setApiKey("YOUR API KEY");

ChargesApi chargesApi = new ChargesApi(defaultClient);

ChargeRequest chargeRequest = createCardChargeRequest();
ChargeResponse chargeResponse = chargesApi.charge(chargeRequest);

SourceTypeCard cardOneShot = ((new SourceTypeCard())
.sourceType("card")
.card((new TokenRequest())
.cardExpirationDate("12/2025")
.cardHolderName("John Doe")
.cardNumber("4929564637987814")
.cardCvv("410")
));

PaymentMethodCard paymentMethodCard = (new PaymentMethodCard())
.paymentType(PaymentMethodCard.PaymentTypeEnum.CREDIT)
.installments(1);

ChargeRequest chargeRequest(new ChargeRequest())
.capture(false)
.statementDescriptor("should be statement descriptor")
.merchantId("YOUR MERCHANT ID")
.amount(1000)
.orderId("1234567890")
.capture(false)
.paymentSource((new ChargeRequestPaymentSource(cardOneShot)))
.paymentMethod((new ChargeRequestPaymentMethod(paymentMethodCard)));

ChargesApi chargesApi = new ChargesApi(defaultClient);

try {
ChargeResponse chargeResponse = chargesApi.charge(chargeRequest);
System.out.println(chargeResponse);
} catch (ApiException e) {
System.err.println("Exception when calling CardsApi#getCardById");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
}

```
Expand Down
55 changes: 52 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id 'java'
id 'java-library'
id 'maven-publish'
}

group 'org.malga'
version '0.5.0'
group 'io.malga'
version '0.1.0'

repositories {
mavenCentral()
Expand All @@ -13,6 +14,54 @@ ext {
jakarta_annotation_version = "1.3.5"
}

publishing {
publications {
maven(MavenPublication) {
groupId = 'io.malga'
artifactId = 'malga-java-api-sdk'
version = '0.1.0'

from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
pom {
name = "Malga Java Api SDK"
description = "Malga Api Client for java"
url = "https://github.com/plughacker/malga-java-api-sdk"
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'Marcel'
name = 'Marcel Nicolay'
email = '[email protected]'
}
}
scm {
connection = 'scm:git:[email protected]:plughacker/malga-java-api-sdk.git'
developerConnection = 'scm:git:[email protected]:plughacker/malga-java-api-sdk.git'
url = '[email protected]:plughacker/malga-java-api-sdk.git'
}
}
}
}
// repositories {
// maven {
// url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
// name = "Central Repository OSSRH"
// }
// }
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
Expand Down
Loading

0 comments on commit 522d5f2

Please sign in to comment.