Skip to content

Commit 59d4a5a

Browse files
committed
Script to add version header to java sdk on generation (#100)
* feat: script to add version header to java dsdk on generation, some test fixes that are already merged in java sdk * feat: generation now also injects headers for setInterceptor function of ApiClient * fix: java sdk version name
1 parent 0070c43 commit 59d4a5a

15 files changed

+338
-487
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,7 @@ target/
7676
node_modules
7777

7878
#macOS
79-
.DS_Store
79+
.DS_Store
80+
81+
#local env
82+
.env

README.md

Lines changed: 220 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ The project is wrapped with npm, we strongly advice to install Node LTS to acces
1111
## Generating Unit Client Libraries
1212

1313
Below you can find examples for generating client libraries using [OpenAPI generator](https://openapi-generator.tech/).
14-
You may also use any other known generator, such as [Swagger Codegen](https://github.com/swagger-api/swagger-codegen#generating-a-client-from-local-files), download the jar from [here](https://mvnrepository.com/artifact/io.swagger.codegen.v3/swagger-codegen-cli)
1514

1615
The following examples are with the use of [openapi-generator-cli](https://github.com/OpenAPITools/openapi-generator-cli).
1716

@@ -20,129 +19,239 @@ The following examples are with the use of [openapi-generator-cli](https://githu
2019
### bundle
2120

2221
```commandline
23-
Bundles the open api specification into one file inside of dist folder
22+
Bundles the open api specification into one file inside the dist folder
2423
```
2524

2625
### generate-java
2726

2827
```commandline
29-
Runs the bundle command and generates java sdk inside of dist folder
28+
Runs the bundle command and generates java sdk inside the dist folder.
3029
```
3130

32-
### lint
33-
34-
```commandline
35-
Runs redocly lint for schemas to detect any potential issues
36-
```
37-
38-
### format
31+
### generate-node
3932

4033
```commandline
41-
Applies prettier formatting to the schemas
34+
Runs the bundle command and generates node sdk inside the dist folder.
4235
```
4336

44-
## Legacy
45-
46-
All of the info listed below is related to the legacy functionality and will be deprecated or updated soon
47-
48-
### unit-java
37+
### generate-ruby
4938

5039
```commandline
51-
openapi-generator-cli generate -g java -i openapi.json -o unit
40+
Runs the bundle command and generates ruby sdk inside the dist folder.
5241
```
5342

54-
### unit-python
55-
56-
We recommend using our script which can be found in this repository:
43+
### generate-python
5744

5845
```commandline
59-
python "./generate.py"
46+
Runs the bundle command and generates python sdk inside the dist folder.
6047
```
6148

62-
Or generate by yourself with swagger-codegen-cli:
63-
64-
```
65-
java -jar swagger-codegen-cli-3.0.47.jar generate -i openapi.json -l python -o unit
66-
```
67-
68-
### unit-typescript-axios
49+
### lint
6950

7051
```commandline
71-
openapi-generator-cli generate -g typescript-axios -i openapi.json -o unit -p npmName=TypescriptUnitClient
52+
Runs redocly lint for schemas to detect any potential issues
7253
```
7354

74-
### unit-ruby
55+
### format
7556

7657
```commandline
77-
openapi-generator-cli generate -g ruby -i openapi.json -o unit
58+
Applies prettier formatting to the schemas
7859
```
7960

8061
## Generated Clients Usage Examples
8162

82-
#### Python
83-
84-
```
85-
from datetime import date, timedelta
86-
from swagger_client import configuration, api_client, Address, CreateIndividualApplicationAttributes, FullName, Phone,
87-
CreateIndividualApplication, CreateBusinessApplication, CreateBusinessApplicationAttributes, BeneficialOwner, \
88-
Contact, Officer
89-
90-
_configuration = configuration.Configuration()
91-
_configuration.api_key['Authorization'] = "access_token"
92-
_configuration.api_key_prefix['Authorization'] = 'Bearer'
93-
94-
api_client = api_client.ApiClient(configuration=_configuration)
95-
96-
address = Address(street="1600 Pennsylvania Avenue Northwest", city="Washington", state="CA",
97-
postal_code="20500",
98-
country="US")
99-
attr = CreateIndividualApplicationAttributes(FullName("Peter", "Parker"), "[email protected]",
100-
Phone("1", "2025550108"), ssn,
101-
address=address, date_of_birth="2001-08-10", dba="Piedpiper Inc",
102-
ein="123456789", sole_proprietorship=False,
103-
idempotency_key=str(uuid.uuid1()),
104-
jwt_subject="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9fQ")
105-
106-
application_request = {"data": CreateIndividualApplication(attributes=attr)}
107-
108-
application = CreateApplicationApi(api_client).execute(application_request).data
109-
customer_id = application.relationships.customer.data.id
110-
111-
attributes = CreateDepositAccountAttributes("checking", {"purpose": "sdk-test"})
112-
relationships = CreateDepositAccountRelationships(customer={"data": {"type": "customer", "id": customer_id}})
113-
req = CreateDepositAccount("depositAccount", attributes, relationships)
114-
115-
account = CreateAnAccountApi(api_client).execute({"data": req})
116-
```
117-
118-
you can find more examples in the unit/e2e_tests directory
119-
12063
#### Java
12164

12265
String access_token = "access_token";
12366
ApiClient cl = new ApiClient();
124-
cl.setBearerToken(access_token);
125-
Configuration.setDefaultApiClient(cl);
126-
127-
GetListRecurringPaymentsApi api = new GetListRecurringPaymentsApi();
128-
129-
UnitRecurringPaymentListResponse response = api.execute();
67+
ObjectMapper mapper = cl.getObjectMapper();
68+
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); // To allow certain requests with empty bodies
69+
cl.setObjectMapper(mapper);
70+
cl.setRequestInterceptor(r -> {
71+
r.header("Authorization", "Bearer " + access_token);
72+
});
73+
UnitApi unitApi = new UnitApi(cl);
74+
75+
CreateBusinessApplication createBusinessApplication = new CreateBusinessApplication();
76+
CreateBusinessApplicationAttributes attr = new CreateBusinessApplicationAttributes();
77+
78+
attr.setName("Peter Parker");
79+
80+
Address address = new Address();
81+
address.setStreet("20 Ingram St");
82+
address.setCity("Forest Hills");
83+
address.setPostalCode("11375");
84+
address.setCountry("US");
85+
address.setState("NY");
86+
attr.setAddress(address);
87+
88+
89+
Phone p = new Phone();
90+
p.setNumber("5555555555");
91+
p.setCountryCode("1");
92+
attr.setPhone(p);
93+
94+
attr.setStateOfIncorporation("DE");
95+
attr.setEin("123456789");
96+
attr.setEntityType(EntityType.CORPORATION);
97+
attr.setIp("127.0.0.1");
98+
attr.setAnnualRevenue(BusinessAnnualRevenue.BETWEEN250K_AND500K);
99+
attr.setNumberOfEmployees(BusinessNumberOfEmployees.BETWEEN100_AND500);
100+
attr.setCashFlow(CashFlow.PREDICTABLE);
101+
attr.setYearOfIncorporation("1999");
102+
List<String> countriesOfOperation = new ArrayList<String>();
103+
countriesOfOperation.add("US");
104+
countriesOfOperation.add("CA");
105+
106+
attr.setCountriesOfOperation(countriesOfOperation);
107+
108+
attr.setWebsite(null);
109+
110+
String email = "[email protected]";
111+
Contact contact = new Contact();
112+
contact.setEmail(email);
113+
contact.setPhone(p);
114+
FullName fn = new FullName();
115+
fn.setFirst("Peter");
116+
fn.setLast("Parker");
117+
contact.setFullName(fn);
118+
attr.setContact(contact);
119+
120+
121+
CreateOfficer officer = new CreateOfficer();
122+
officer.setAnnualIncome(AnnualIncome.BETWEEN50K_AND100K);
123+
officer.setFullName(fn);
124+
officer.setAddress(address);
125+
officer.setEmail(email);
126+
officer.setPhone(p);
127+
LocalDate dateOfBirh = LocalDate.of(1997, 11, 1);
128+
officer.setDateOfBirth(dateOfBirh);
129+
officer.setTitle(CreateOfficer.TitleEnum.CEO);
130+
officer.setOccupation(Occupation.ARCHITECT_OR_ENGINEER);
131+
officer.setSourceOfIncome(SourceOfIncome.BUSINESS_OWNERSHIP_INTERESTS);
132+
officer.setSsn("123456789");
133+
134+
attr.setOfficer(officer);
135+
attr.setBusinessVertical(BusinessVertical.ARTS_ENTERTAINMENT_AND_RECREATION);
136+
137+
List<CreateBeneficialOwner> beneficialOwners = new ArrayList<CreateBeneficialOwner>();
138+
CreateBeneficialOwner beneficialOwner = new CreateBeneficialOwner();
139+
beneficialOwner.setAddress(address);
140+
beneficialOwner.setFullName(fn);
141+
beneficialOwner.setDateOfBirth(dateOfBirh);
142+
beneficialOwner.setSsn("721074426");
143+
beneficialOwner.setEmail(email);
144+
beneficialOwner.setPhone(p);
145+
beneficialOwner.setOccupation(Occupation.ARCHITECT_OR_ENGINEER);
146+
beneficialOwner.setAnnualIncome(AnnualIncome.BETWEEN100K_AND250K);
147+
beneficialOwner.setSourceOfIncome(SourceOfIncome.BUSINESS_OWNERSHIP_INTERESTS);
148+
beneficialOwners.add(beneficialOwner);
149+
attr.setBeneficialOwners(beneficialOwners);
150+
151+
createBusinessApplication.setAttributes(attr);
152+
153+
CreateApplicationRequest ca = new CreateApplicationRequest();
154+
ca.data(new CreateApplicationRequestData(createBusinessApplication));
155+
156+
UnitCreateApplicationResponse res = unitApi.createApplication(ca)
157+
158+
you can find more examples in the unit/e2e_tests/java directory
130159

131160
#### Typescript
132161

133-
import { GetAccountApi } from "./api";
162+
import {
163+
Address,
164+
AnnualIncome,
165+
BusinessAnnualRevenue,
166+
BusinessNumberOfEmployees,
167+
BusinessVertical,
168+
CashFlow,
169+
CreateApplicationRequest,
170+
EntityType,
171+
FullName,
172+
Occupation,
173+
OfficerTitleEnum,
174+
Phone,
175+
SourceOfIncome,
176+
UnitApi,
177+
} from "./api";
134178
import { Configuration } from "./configuration";
135179

136-
const token = "your_token"
137-
const con: Configuration = new Configuration({accessToken: token})
138-
const api: GetAccountApi = new GetAccountApi(con)
139-
async function exec() {
140-
return (await api.execute("12345")).data
141-
}
142-
143-
exec().then((res) => {
144-
console.log(res)
145-
})
180+
const config: Configuration = new Configuration({
181+
accessToken: "access_token"
182+
});
183+
const unitApi: UnitApi = new UnitApi(config);
184+
185+
const address: Address = {
186+
street: "20 Ingram St",
187+
city: "Forest Hills",
188+
postalCode: "11375",
189+
country: "US",
190+
state: "NY",
191+
};
192+
const phone: Phone = {
193+
number: "5555555555",
194+
countryCode: "1",
195+
};
196+
const fullName: FullName = {
197+
first: "Peter",
198+
last: "Parker",
199+
};
200+
const email = "[email protected]";
201+
const dateOfBirth = "1997-11-01";
202+
const today = new Date();
203+
204+
const req: CreateApplicationRequest = {
205+
data: {
206+
type: "businessApplication",
207+
attributes: {
208+
name: "Peter Parker",
209+
address,
210+
phone,
211+
stateOfIncorporation: "DE",
212+
ein: "123456789",
213+
entityType: EntityType.Corporation,
214+
ip: "127.0.0.1",
215+
annualRevenue: BusinessAnnualRevenue.Between1mAnd5m,
216+
numberOfEmployees: BusinessNumberOfEmployees.Between100And500,
217+
cashFlow: CashFlow.Predictable,
218+
countriesOfOperation: ["US", "CA"],
219+
businessVertical: BusinessVertical.AgricultureForestryFishingOrHunting,
220+
yearOfIncorporation: (today.getFullYear() - 2).toString(),
221+
contact: {
222+
email,
223+
fullName,
224+
phone,
225+
},
226+
officer: {
227+
annualIncome: AnnualIncome.Between100kAnd250k,
228+
fullName,
229+
address,
230+
email,
231+
phone,
232+
dateOfBirth,
233+
title: OfficerTitleEnum.Ceo,
234+
occupation: Occupation.ArchitectOrEngineer,
235+
sourceOfIncome: SourceOfIncome.BusinessOwnershipInterests,
236+
ssn: "123456789",
237+
},
238+
beneficialOwners: [
239+
{
240+
address,
241+
fullName,
242+
dateOfBirth,
243+
ssn: "721074426",
244+
email,
245+
phone,
246+
occupation: Occupation.ArchitectOrEngineer,
247+
sourceOfIncome: SourceOfIncome.BusinessOwnershipInterests,
248+
},
249+
],
250+
},
251+
},
252+
};
253+
254+
let res = await unitApi.createApplication(req);
146255

147256
## Known Generators Issues
148257

@@ -164,12 +273,35 @@ When generating a python-sdk, you should change the configurations to:
164273
"name": "Authorization"
165274
}
166275

276+
### Java responses
277+
278+
We are using `Java native` as a library template during generation of the java sdk and there are issues with types in responses containing raw text or binary files.
279+
In order to fix that we have a custom script in place. If you would generate a library yourself you should call the `fix-java-file-get-requests` script from package.json providing the `--path=./dist/java-sdk/src/main/java/unit/java/sdk/api/UnitApi.java` argument to fix the errors after the generation.
280+
167281
### CLI version
168282

169283
Use the follow command to check the openapi-generator-cli version:
170284

171285
`openapi-generator-cli version`
172286

173-
We recommend using v7.0.1, you can change the version with the command:
287+
We recommend using v7.9.0, you can change the version with the command:
288+
289+
`openapi-generator-cli version-manager set 7.9.0`
290+
291+
## Legacy
174292

175-
`openapi-generator-cli version-manager set 7.0.1`
293+
All of the info listed below is related to the legacy functionality and will be deprecated or updated soon
294+
295+
### unit-python
296+
297+
We recommend using our script which can be found in this repository:
298+
299+
```commandline
300+
python "./generate.py"
301+
```
302+
303+
Or generate by yourself with swagger-codegen-cli:
304+
305+
```
306+
java -jar swagger-codegen-cli-3.0.47.jar generate -i openapi.json -l python -o unit
307+
```

0 commit comments

Comments
 (0)