Skip to content

Commit 3438873

Browse files
authored
feat: respect readonly fields (#32)
1 parent 002136a commit 3438873

12 files changed

Lines changed: 31 additions & 272 deletions

File tree

codegen/internal/generator/model.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ type schemaField struct {
9898
Type string
9999
DescriptionLines []string
100100
Required bool
101+
ReadOnly bool
101102
}
102103

103104
// enumValueModel captures a single enum constant and its wire value.
@@ -583,6 +584,7 @@ func buildSchemaFields(name string, ref *base.SchemaProxy, resolver *typeResolve
583584
for _, imp := range javaType.Imports {
584585
imports[imp] = struct{}{}
585586
}
587+
readOnly := isReadOnlySchema(propRef)
586588
desc := ""
587589
if schemaFromProxy(propRef) != nil {
588590
desc = schemaFromProxy(propRef).Description
@@ -592,8 +594,9 @@ func buildSchemaFields(name string, ref *base.SchemaProxy, resolver *typeResolve
592594
Type: javaType.Name,
593595
DescriptionLines: splitComment(desc),
594596
Required: required[propName],
597+
ReadOnly: readOnly,
595598
})
596-
if required[propName] {
599+
if required[propName] && !readOnly {
597600
hasRequired = true
598601
}
599602
}
@@ -737,6 +740,12 @@ func schemaHasType(schema *base.Schema, want string) bool {
737740
return false
738741
}
739742

743+
// isReadOnlySchema reports whether the schema marks this value as readOnly.
744+
func isReadOnlySchema(proxy *base.SchemaProxy) bool {
745+
schema := schemaFromProxy(proxy)
746+
return schema != nil && schema.ReadOnly != nil && *schema.ReadOnly
747+
}
748+
740749
// sortedImports deterministically orders import strings so rendered files do
741750
// not churn between runs.
742751
func sortedImports(set map[string]struct{}) []string {

codegen/internal/generator/templates/model.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ public record {{ .ClassName }}(
7777
public static final class Builder {
7878
{{- if .Fields }}
7979
{{- range .Fields }}
80+
{{- if not .ReadOnly }}
8081
private {{ .Type }} {{ .Name }};
8182
{{- end }}
83+
{{- end }}
8284
{{- else }}
8385
private Object value;
8486
{{- end }}
@@ -87,6 +89,7 @@ public record {{ .ClassName }}(
8789

8890
{{- if .Fields }}
8991
{{- range .Fields }}
92+
{{- if not .ReadOnly }}
9093
/**
9194
* Sets the value for {@code {{ .Name }}}.
9295
*
@@ -98,6 +101,7 @@ public record {{ .ClassName }}(
98101
return this;
99102
}
100103
{{- end }}
104+
{{- end }}
101105
{{- else }}
102106
/**
103107
* Sets the wrapped value field.
@@ -121,7 +125,7 @@ public record {{ .ClassName }}(
121125
return new {{ $.ClassName }}(
122126
{{- range $index, $field := .Fields }}
123127
{{- if $index }},
124-
{{ end }} {{ if $field.Required }}Objects.requireNonNull({{ $field.Name }}, {{ quote $field.Name }}){{ else }}{{ $field.Name }}{{ end }}
128+
{{ end }} {{ if $field.ReadOnly }}null{{ else if $field.Required }}Objects.requireNonNull({{ $field.Name }}, {{ quote $field.Name }}){{ else }}{{ $field.Name }}{{ end }}
125129
{{- end }}
126130
);
127131
{{- else }}

src/main/java/com/sumup/sdk/models/BasePerson.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Code generated by sumup-java/codegen. DO NOT EDIT.
22
package com.sumup.sdk.models;
33

4-
import java.util.Objects;
5-
64
/**
75
* Base schema for a person associated with a merchant. This can be a legal representative, business
86
* owner (ultimate beneficial owner), or an officer. A legal representative is the person who
@@ -104,12 +102,10 @@ public static Builder builder() {
104102
public static final class Builder {
105103
private com.sumup.sdk.models.Address address;
106104
private java.time.LocalDate birthdate;
107-
private com.sumup.sdk.models.ChangeStatus changeStatus;
108105
private com.sumup.sdk.models.CountryCode citizenship;
109106
private String countryOfResidence;
110107
private String familyName;
111108
private String givenName;
112-
private String id;
113109
private java.util.List<com.sumup.sdk.models.PersonalIdentifier> identifiers;
114110
private String middleName;
115111
private String nationality;
@@ -148,21 +144,6 @@ public Builder birthdate(java.time.LocalDate birthdate) {
148144
return this;
149145
}
150146

151-
/**
152-
* Sets the value for {@code changeStatus}.
153-
*
154-
* @param changeStatus Reflects the status of changes submitted through the `PATCH` endpoints
155-
* for the merchant or persons. If some changes have not been applied yet, the status will
156-
* be `pending`. If all changes have been applied, the status `done`. The status is only
157-
* returned after write operations or on read endpoints when the `version` query parameter
158-
* is provided.
159-
* @return This builder instance.
160-
*/
161-
public Builder changeStatus(com.sumup.sdk.models.ChangeStatus changeStatus) {
162-
this.changeStatus = changeStatus;
163-
return this;
164-
}
165-
166147
/**
167148
* Sets the value for {@code citizenship}.
168149
*
@@ -211,18 +192,6 @@ public Builder givenName(String givenName) {
211192
return this;
212193
}
213194

214-
/**
215-
* Sets the value for {@code id}.
216-
*
217-
* @param id The unique identifier for the person. This is a
218-
* [typeid](https://github.com/sumup/typeid).
219-
* @return This builder instance.
220-
*/
221-
public Builder id(String id) {
222-
this.id = id;
223-
return this;
224-
}
225-
226195
/**
227196
* Sets the value for {@code identifiers}.
228197
*
@@ -328,12 +297,12 @@ public BasePerson build() {
328297
return new BasePerson(
329298
address,
330299
birthdate,
331-
changeStatus,
300+
null,
332301
citizenship,
333302
countryOfResidence,
334303
familyName,
335304
givenName,
336-
Objects.requireNonNull(id, "id"),
305+
null,
337306
identifiers,
338307
middleName,
339308
nationality,

src/main/java/com/sumup/sdk/models/Card.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public static final class Builder {
4242
private String cvv;
4343
private com.sumup.sdk.models.CardExpiryMonth expiryMonth;
4444
private String expiryYear;
45-
private String last4Digits;
4645
private String name;
4746
private String number;
4847
private com.sumup.sdk.models.CardType type;
@@ -85,17 +84,6 @@ public Builder expiryYear(String expiryYear) {
8584
return this;
8685
}
8786

88-
/**
89-
* Sets the value for {@code last4Digits}.
90-
*
91-
* @param last4Digits Last 4 digits of the payment card number.
92-
* @return This builder instance.
93-
*/
94-
public Builder last4Digits(String last4Digits) {
95-
this.last4Digits = last4Digits;
96-
return this;
97-
}
98-
9987
/**
10088
* Sets the value for {@code name}.
10189
*
@@ -150,7 +138,7 @@ public Card build() {
150138
Objects.requireNonNull(cvv, "cvv"),
151139
Objects.requireNonNull(expiryMonth, "expiryMonth"),
152140
Objects.requireNonNull(expiryYear, "expiryYear"),
153-
Objects.requireNonNull(last4Digits, "last4Digits"),
141+
null,
154142
Objects.requireNonNull(name, "name"),
155143
Objects.requireNonNull(number, "number"),
156144
Objects.requireNonNull(type, "type"),

src/main/java/com/sumup/sdk/models/CardResponse.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,10 @@ public static Builder builder() {
1919

2020
/** Builder for CardResponse instances. */
2121
public static final class Builder {
22-
private String last4Digits;
2322
private com.sumup.sdk.models.CardType type;
2423

2524
private Builder() {}
2625

27-
/**
28-
* Sets the value for {@code last4Digits}.
29-
*
30-
* @param last4Digits Last 4 digits of the payment card number.
31-
* @return This builder instance.
32-
*/
33-
public Builder last4Digits(String last4Digits) {
34-
this.last4Digits = last4Digits;
35-
return this;
36-
}
37-
3826
/**
3927
* Sets the value for {@code type}.
4028
*
@@ -52,7 +40,7 @@ public Builder type(com.sumup.sdk.models.CardType type) {
5240
* @return Immutable CardResponse.
5341
*/
5442
public CardResponse build() {
55-
return new CardResponse(last4Digits, type);
43+
return new CardResponse(null, type);
5644
}
5745
}
5846
}

src/main/java/com/sumup/sdk/models/Checkout.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public static final class Builder {
7676
private String customerId;
7777
private java.time.OffsetDateTime date;
7878
private String description;
79-
private String id;
8079
private com.sumup.sdk.models.MandateResponse mandate;
8180
private String merchantCode;
8281
private String returnUrl;
@@ -157,17 +156,6 @@ public Builder description(String description) {
157156
return this;
158157
}
159158

160-
/**
161-
* Sets the value for {@code id}.
162-
*
163-
* @param id Unique ID of the checkout resource.
164-
* @return This builder instance.
165-
*/
166-
public Builder id(String id) {
167-
this.id = id;
168-
return this;
169-
}
170-
171159
/**
172160
* Sets the value for {@code mandate}.
173161
*
@@ -250,7 +238,7 @@ public Checkout build() {
250238
customerId,
251239
date,
252240
description,
253-
id,
241+
null,
254242
mandate,
255243
merchantCode,
256244
returnUrl,

src/main/java/com/sumup/sdk/models/CheckoutCreateRequest.java

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,11 @@ public static final class Builder {
8686
private String checkoutReference;
8787
private com.sumup.sdk.models.Currency currency;
8888
private String customerId;
89-
private java.time.OffsetDateTime date;
9089
private String description;
91-
private String id;
9290
private String merchantCode;
9391
private com.sumup.sdk.models.CheckoutCreateRequestPurpose purpose;
9492
private String redirectUrl;
9593
private String returnUrl;
96-
private com.sumup.sdk.models.CheckoutCreateRequestStatus status;
97-
private java.util.List<com.sumup.sdk.models.TransactionBase> transactions;
9894
private java.time.OffsetDateTime validUntil;
9995

10096
private Builder() {}
@@ -146,18 +142,6 @@ public Builder customerId(String customerId) {
146142
return this;
147143
}
148144

149-
/**
150-
* Sets the value for {@code date}.
151-
*
152-
* @param date Date and time of the creation of the payment checkout. Response format expressed
153-
* according to [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) code.
154-
* @return This builder instance.
155-
*/
156-
public Builder date(java.time.OffsetDateTime date) {
157-
this.date = date;
158-
return this;
159-
}
160-
161145
/**
162146
* Sets the value for {@code description}.
163147
*
@@ -170,17 +154,6 @@ public Builder description(String description) {
170154
return this;
171155
}
172156

173-
/**
174-
* Sets the value for {@code id}.
175-
*
176-
* @param id Unique ID of the checkout resource.
177-
* @return This builder instance.
178-
*/
179-
public Builder id(String id) {
180-
this.id = id;
181-
return this;
182-
}
183-
184157
/**
185158
* Sets the value for {@code merchantCode}.
186159
*
@@ -232,28 +205,6 @@ public Builder returnUrl(String returnUrl) {
232205
return this;
233206
}
234207

235-
/**
236-
* Sets the value for {@code status}.
237-
*
238-
* @param status Current status of the checkout.
239-
* @return This builder instance.
240-
*/
241-
public Builder status(com.sumup.sdk.models.CheckoutCreateRequestStatus status) {
242-
this.status = status;
243-
return this;
244-
}
245-
246-
/**
247-
* Sets the value for {@code transactions}.
248-
*
249-
* @param transactions List of transactions related to the payment.
250-
* @return This builder instance.
251-
*/
252-
public Builder transactions(java.util.List<com.sumup.sdk.models.TransactionBase> transactions) {
253-
this.transactions = transactions;
254-
return this;
255-
}
256-
257208
/**
258209
* Sets the value for {@code validUntil}.
259210
*
@@ -278,15 +229,15 @@ public CheckoutCreateRequest build() {
278229
Objects.requireNonNull(checkoutReference, "checkoutReference"),
279230
Objects.requireNonNull(currency, "currency"),
280231
customerId,
281-
date,
232+
null,
282233
description,
283-
id,
234+
null,
284235
Objects.requireNonNull(merchantCode, "merchantCode"),
285236
purpose,
286237
redirectUrl,
287238
returnUrl,
288-
status,
289-
transactions,
239+
null,
240+
null,
290241
validUntil);
291242
}
292243
}

0 commit comments

Comments
 (0)