Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion codegen/internal/generator/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type schemaField struct {
Type string
DescriptionLines []string
Required bool
ReadOnly bool
}

// enumValueModel captures a single enum constant and its wire value.
Expand Down Expand Up @@ -583,6 +584,7 @@ func buildSchemaFields(name string, ref *base.SchemaProxy, resolver *typeResolve
for _, imp := range javaType.Imports {
imports[imp] = struct{}{}
}
readOnly := isReadOnlySchema(propRef)
desc := ""
if schemaFromProxy(propRef) != nil {
desc = schemaFromProxy(propRef).Description
Expand All @@ -592,8 +594,9 @@ func buildSchemaFields(name string, ref *base.SchemaProxy, resolver *typeResolve
Type: javaType.Name,
DescriptionLines: splitComment(desc),
Required: required[propName],
ReadOnly: readOnly,
})
if required[propName] {
if required[propName] && !readOnly {
hasRequired = true
}
}
Expand Down Expand Up @@ -737,6 +740,12 @@ func schemaHasType(schema *base.Schema, want string) bool {
return false
}

// isReadOnlySchema reports whether the schema marks this value as readOnly.
func isReadOnlySchema(proxy *base.SchemaProxy) bool {
schema := schemaFromProxy(proxy)
return schema != nil && schema.ReadOnly != nil && *schema.ReadOnly
}

// sortedImports deterministically orders import strings so rendered files do
// not churn between runs.
func sortedImports(set map[string]struct{}) []string {
Expand Down
6 changes: 5 additions & 1 deletion codegen/internal/generator/templates/model.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ public record {{ .ClassName }}(
public static final class Builder {
{{- if .Fields }}
{{- range .Fields }}
{{- if not .ReadOnly }}
private {{ .Type }} {{ .Name }};
{{- end }}
{{- end }}
{{- else }}
private Object value;
{{- end }}
Expand All @@ -87,6 +89,7 @@ public record {{ .ClassName }}(

{{- if .Fields }}
{{- range .Fields }}
{{- if not .ReadOnly }}
/**
* Sets the value for {@code {{ .Name }}}.
*
Expand All @@ -98,6 +101,7 @@ public record {{ .ClassName }}(
return this;
}
{{- end }}
{{- end }}
{{- else }}
/**
* Sets the wrapped value field.
Expand All @@ -121,7 +125,7 @@ public record {{ .ClassName }}(
return new {{ $.ClassName }}(
{{- range $index, $field := .Fields }}
{{- if $index }},
{{ end }} {{ if $field.Required }}Objects.requireNonNull({{ $field.Name }}, {{ quote $field.Name }}){{ else }}{{ $field.Name }}{{ end }}
{{ end }} {{ if $field.ReadOnly }}null{{ else if $field.Required }}Objects.requireNonNull({{ $field.Name }}, {{ quote $field.Name }}){{ else }}{{ $field.Name }}{{ end }}
{{- end }}
);
{{- else }}
Expand Down
35 changes: 2 additions & 33 deletions src/main/java/com/sumup/sdk/models/BasePerson.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Code generated by sumup-java/codegen. DO NOT EDIT.
package com.sumup.sdk.models;

import java.util.Objects;

/**
* Base schema for a person associated with a merchant. This can be a legal representative, business
* owner (ultimate beneficial owner), or an officer. A legal representative is the person who
Expand Down Expand Up @@ -104,12 +102,10 @@ public static Builder builder() {
public static final class Builder {
private com.sumup.sdk.models.Address address;
private java.time.LocalDate birthdate;
private com.sumup.sdk.models.ChangeStatus changeStatus;
private com.sumup.sdk.models.CountryCode citizenship;
private String countryOfResidence;
private String familyName;
private String givenName;
private String id;
private java.util.List<com.sumup.sdk.models.PersonalIdentifier> identifiers;
private String middleName;
private String nationality;
Expand Down Expand Up @@ -148,21 +144,6 @@ public Builder birthdate(java.time.LocalDate birthdate) {
return this;
}

/**
* Sets the value for {@code changeStatus}.
*
* @param changeStatus Reflects the status of changes submitted through the `PATCH` endpoints
* for the merchant or persons. If some changes have not been applied yet, the status will
* be `pending`. If all changes have been applied, the status `done`. The status is only
* returned after write operations or on read endpoints when the `version` query parameter
* is provided.
* @return This builder instance.
*/
public Builder changeStatus(com.sumup.sdk.models.ChangeStatus changeStatus) {
this.changeStatus = changeStatus;
return this;
}

/**
* Sets the value for {@code citizenship}.
*
Expand Down Expand Up @@ -211,18 +192,6 @@ public Builder givenName(String givenName) {
return this;
}

/**
* Sets the value for {@code id}.
*
* @param id The unique identifier for the person. This is a
* [typeid](https://github.com/sumup/typeid).
* @return This builder instance.
*/
public Builder id(String id) {
this.id = id;
return this;
}

/**
* Sets the value for {@code identifiers}.
*
Expand Down Expand Up @@ -328,12 +297,12 @@ public BasePerson build() {
return new BasePerson(
address,
birthdate,
changeStatus,
null,
citizenship,
countryOfResidence,
familyName,
givenName,
Objects.requireNonNull(id, "id"),
null,
identifiers,
middleName,
nationality,
Expand Down
14 changes: 1 addition & 13 deletions src/main/java/com/sumup/sdk/models/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public static final class Builder {
private String cvv;
private com.sumup.sdk.models.CardExpiryMonth expiryMonth;
private String expiryYear;
private String last4Digits;
private String name;
private String number;
private com.sumup.sdk.models.CardType type;
Expand Down Expand Up @@ -85,17 +84,6 @@ public Builder expiryYear(String expiryYear) {
return this;
}

/**
* Sets the value for {@code last4Digits}.
*
* @param last4Digits Last 4 digits of the payment card number.
* @return This builder instance.
*/
public Builder last4Digits(String last4Digits) {
this.last4Digits = last4Digits;
return this;
}

/**
* Sets the value for {@code name}.
*
Expand Down Expand Up @@ -150,7 +138,7 @@ public Card build() {
Objects.requireNonNull(cvv, "cvv"),
Objects.requireNonNull(expiryMonth, "expiryMonth"),
Objects.requireNonNull(expiryYear, "expiryYear"),
Objects.requireNonNull(last4Digits, "last4Digits"),
null,
Objects.requireNonNull(name, "name"),
Objects.requireNonNull(number, "number"),
Objects.requireNonNull(type, "type"),
Expand Down
14 changes: 1 addition & 13 deletions src/main/java/com/sumup/sdk/models/CardResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,10 @@ public static Builder builder() {

/** Builder for CardResponse instances. */
public static final class Builder {
private String last4Digits;
private com.sumup.sdk.models.CardType type;

private Builder() {}

/**
* Sets the value for {@code last4Digits}.
*
* @param last4Digits Last 4 digits of the payment card number.
* @return This builder instance.
*/
public Builder last4Digits(String last4Digits) {
this.last4Digits = last4Digits;
return this;
}

/**
* Sets the value for {@code type}.
*
Expand All @@ -52,7 +40,7 @@ public Builder type(com.sumup.sdk.models.CardType type) {
* @return Immutable CardResponse.
*/
public CardResponse build() {
return new CardResponse(last4Digits, type);
return new CardResponse(null, type);
}
}
}
14 changes: 1 addition & 13 deletions src/main/java/com/sumup/sdk/models/Checkout.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public static final class Builder {
private String customerId;
private java.time.OffsetDateTime date;
private String description;
private String id;
private com.sumup.sdk.models.MandateResponse mandate;
private String merchantCode;
private String returnUrl;
Expand Down Expand Up @@ -157,17 +156,6 @@ public Builder description(String description) {
return this;
}

/**
* Sets the value for {@code id}.
*
* @param id Unique ID of the checkout resource.
* @return This builder instance.
*/
public Builder id(String id) {
this.id = id;
return this;
}

/**
* Sets the value for {@code mandate}.
*
Expand Down Expand Up @@ -250,7 +238,7 @@ public Checkout build() {
customerId,
date,
description,
id,
null,
mandate,
merchantCode,
returnUrl,
Expand Down
57 changes: 4 additions & 53 deletions src/main/java/com/sumup/sdk/models/CheckoutCreateRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,11 @@ public static final class Builder {
private String checkoutReference;
private com.sumup.sdk.models.Currency currency;
private String customerId;
private java.time.OffsetDateTime date;
private String description;
private String id;
private String merchantCode;
private com.sumup.sdk.models.CheckoutCreateRequestPurpose purpose;
private String redirectUrl;
private String returnUrl;
private com.sumup.sdk.models.CheckoutCreateRequestStatus status;
private java.util.List<com.sumup.sdk.models.TransactionBase> transactions;
private java.time.OffsetDateTime validUntil;

private Builder() {}
Expand Down Expand Up @@ -146,18 +142,6 @@ public Builder customerId(String customerId) {
return this;
}

/**
* Sets the value for {@code date}.
*
* @param date Date and time of the creation of the payment checkout. Response format expressed
* according to [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) code.
* @return This builder instance.
*/
public Builder date(java.time.OffsetDateTime date) {
this.date = date;
return this;
}

/**
* Sets the value for {@code description}.
*
Expand All @@ -170,17 +154,6 @@ public Builder description(String description) {
return this;
}

/**
* Sets the value for {@code id}.
*
* @param id Unique ID of the checkout resource.
* @return This builder instance.
*/
public Builder id(String id) {
this.id = id;
return this;
}

/**
* Sets the value for {@code merchantCode}.
*
Expand Down Expand Up @@ -232,28 +205,6 @@ public Builder returnUrl(String returnUrl) {
return this;
}

/**
* Sets the value for {@code status}.
*
* @param status Current status of the checkout.
* @return This builder instance.
*/
public Builder status(com.sumup.sdk.models.CheckoutCreateRequestStatus status) {
this.status = status;
return this;
}

/**
* Sets the value for {@code transactions}.
*
* @param transactions List of transactions related to the payment.
* @return This builder instance.
*/
public Builder transactions(java.util.List<com.sumup.sdk.models.TransactionBase> transactions) {
this.transactions = transactions;
return this;
}

/**
* Sets the value for {@code validUntil}.
*
Expand All @@ -278,15 +229,15 @@ public CheckoutCreateRequest build() {
Objects.requireNonNull(checkoutReference, "checkoutReference"),
Objects.requireNonNull(currency, "currency"),
customerId,
date,
null,
description,
id,
null,
Objects.requireNonNull(merchantCode, "merchantCode"),
purpose,
redirectUrl,
returnUrl,
status,
transactions,
null,
null,
validUntil);
}
}
Expand Down
Loading
Loading