diff --git a/codegen/internal/generator/model.go b/codegen/internal/generator/model.go index 184fd51..74f43ea 100644 --- a/codegen/internal/generator/model.go +++ b/codegen/internal/generator/model.go @@ -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. @@ -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 @@ -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 } } @@ -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 { diff --git a/codegen/internal/generator/templates/model.tmpl b/codegen/internal/generator/templates/model.tmpl index 5737414..7c81fcb 100644 --- a/codegen/internal/generator/templates/model.tmpl +++ b/codegen/internal/generator/templates/model.tmpl @@ -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 }} @@ -87,6 +89,7 @@ public record {{ .ClassName }}( {{- if .Fields }} {{- range .Fields }} +{{- if not .ReadOnly }} /** * Sets the value for {@code {{ .Name }}}. * @@ -98,6 +101,7 @@ public record {{ .ClassName }}( return this; } {{- end }} +{{- end }} {{- else }} /** * Sets the wrapped value field. @@ -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 }} diff --git a/src/main/java/com/sumup/sdk/models/BasePerson.java b/src/main/java/com/sumup/sdk/models/BasePerson.java index b02cee0..0cefdd9 100644 --- a/src/main/java/com/sumup/sdk/models/BasePerson.java +++ b/src/main/java/com/sumup/sdk/models/BasePerson.java @@ -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 @@ -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 identifiers; private String middleName; private String nationality; @@ -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}. * @@ -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}. * @@ -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, diff --git a/src/main/java/com/sumup/sdk/models/Card.java b/src/main/java/com/sumup/sdk/models/Card.java index ac6d690..b4c7787 100644 --- a/src/main/java/com/sumup/sdk/models/Card.java +++ b/src/main/java/com/sumup/sdk/models/Card.java @@ -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; @@ -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}. * @@ -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"), diff --git a/src/main/java/com/sumup/sdk/models/CardResponse.java b/src/main/java/com/sumup/sdk/models/CardResponse.java index eafcb46..47ee1ac 100644 --- a/src/main/java/com/sumup/sdk/models/CardResponse.java +++ b/src/main/java/com/sumup/sdk/models/CardResponse.java @@ -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}. * @@ -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); } } } diff --git a/src/main/java/com/sumup/sdk/models/Checkout.java b/src/main/java/com/sumup/sdk/models/Checkout.java index 2ce0a64..9d39c66 100644 --- a/src/main/java/com/sumup/sdk/models/Checkout.java +++ b/src/main/java/com/sumup/sdk/models/Checkout.java @@ -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; @@ -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}. * @@ -250,7 +238,7 @@ public Checkout build() { customerId, date, description, - id, + null, mandate, merchantCode, returnUrl, diff --git a/src/main/java/com/sumup/sdk/models/CheckoutCreateRequest.java b/src/main/java/com/sumup/sdk/models/CheckoutCreateRequest.java index bb94d70..eea8522 100644 --- a/src/main/java/com/sumup/sdk/models/CheckoutCreateRequest.java +++ b/src/main/java/com/sumup/sdk/models/CheckoutCreateRequest.java @@ -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 transactions; private java.time.OffsetDateTime validUntil; private Builder() {} @@ -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}. * @@ -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}. * @@ -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 transactions) { - this.transactions = transactions; - return this; - } - /** * Sets the value for {@code validUntil}. * @@ -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); } } diff --git a/src/main/java/com/sumup/sdk/models/Merchant2.java b/src/main/java/com/sumup/sdk/models/Merchant2.java index 20b22b8..4e2d0a9 100644 --- a/src/main/java/com/sumup/sdk/models/Merchant2.java +++ b/src/main/java/com/sumup/sdk/models/Merchant2.java @@ -107,13 +107,10 @@ public static final class Builder { private String avatar; private com.sumup.sdk.models.BusinessProfile businessProfile; private String businessType; - private com.sumup.sdk.models.ChangeStatus changeStatus; private com.sumup.sdk.models.ClassicMerchantIdentifiers classic; private com.sumup.sdk.models.Company company; private com.sumup.sdk.models.CountryCode country; - private String defaultCurrency; private String defaultLocale; - private String merchantCode; private com.sumup.sdk.models.Meta meta; private String organizationId; private Boolean sandbox; @@ -174,21 +171,6 @@ public Builder businessType(String businessType) { 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 classic}. * @@ -225,19 +207,6 @@ public Builder country(com.sumup.sdk.models.CountryCode country) { return this; } - /** - * Sets the value for {@code defaultCurrency}. - * - * @param defaultCurrency Three-letter [ISO currency - * code](https://en.wikipedia.org/wiki/ISO_4217) representing the default currency for the - * account. - * @return This builder instance. - */ - public Builder defaultCurrency(String defaultCurrency) { - this.defaultCurrency = defaultCurrency; - return this; - } - /** * Sets the value for {@code defaultLocale}. * @@ -256,17 +225,6 @@ public Builder defaultLocale(String defaultLocale) { return this; } - /** - * Sets the value for {@code merchantCode}. - * - * @param merchantCode Short unique identifier for the merchant. - * @return This builder instance. - */ - public Builder merchantCode(String merchantCode) { - this.merchantCode = merchantCode; - return this; - } - /** * Sets the value for {@code meta}. * @@ -326,13 +284,13 @@ public Merchant2 build() { avatar, businessProfile, businessType, - changeStatus, + null, classic, company, Objects.requireNonNull(country, "country"), - Objects.requireNonNull(defaultCurrency, "defaultCurrency"), + null, Objects.requireNonNull(defaultLocale, "defaultLocale"), - Objects.requireNonNull(merchantCode, "merchantCode"), + null, meta, organizationId, sandbox, diff --git a/src/main/java/com/sumup/sdk/models/PaymentInstrumentCard.java b/src/main/java/com/sumup/sdk/models/PaymentInstrumentCard.java index 6c7fb55..e45fb74 100644 --- a/src/main/java/com/sumup/sdk/models/PaymentInstrumentCard.java +++ b/src/main/java/com/sumup/sdk/models/PaymentInstrumentCard.java @@ -30,25 +30,11 @@ public static Builder builder() { /** Builder for PaymentInstrumentCard instances. */ public static final class Builder { - private Boolean active; private com.sumup.sdk.models.Card card; - private String token; private com.sumup.sdk.models.PaymentInstrumentCardType type; private Builder() {} - /** - * Sets the value for {@code active}. - * - * @param active Indicates whether the payment instrument is active and can be used for - * payments. To deactivate it, send a `DELETE` request to the resource endpoint. - * @return This builder instance. - */ - public Builder active(Boolean active) { - this.active = active; - return this; - } - /** * Sets the value for {@code card}. * @@ -60,17 +46,6 @@ public Builder card(com.sumup.sdk.models.Card card) { return this; } - /** - * Sets the value for {@code token}. - * - * @param token Unique token identifying the saved payment card for a customer. - * @return This builder instance. - */ - public Builder token(String token) { - this.token = token; - return this; - } - /** * Sets the value for {@code type}. * @@ -89,10 +64,7 @@ public Builder type(com.sumup.sdk.models.PaymentInstrumentCardType type) { */ public PaymentInstrumentCard build() { return new PaymentInstrumentCard( - Objects.requireNonNull(active, "active"), - Objects.requireNonNull(card, "card"), - Objects.requireNonNull(token, "token"), - Objects.requireNonNull(type, "type")); + null, Objects.requireNonNull(card, "card"), null, Objects.requireNonNull(type, "type")); } } } diff --git a/src/main/java/com/sumup/sdk/models/PaymentInstrumentResponse.java b/src/main/java/com/sumup/sdk/models/PaymentInstrumentResponse.java index f6765e8..8a42f0b 100644 --- a/src/main/java/com/sumup/sdk/models/PaymentInstrumentResponse.java +++ b/src/main/java/com/sumup/sdk/models/PaymentInstrumentResponse.java @@ -37,27 +37,13 @@ public static Builder builder() { /** Builder for PaymentInstrumentResponse instances. */ public static final class Builder { - private Boolean active; private com.sumup.sdk.models.PaymentInstrumentResponseCard card; private java.time.OffsetDateTime createdAt; private com.sumup.sdk.models.MandateResponse mandate; - private String token; private com.sumup.sdk.models.PaymentInstrumentResponseType type; private Builder() {} - /** - * Sets the value for {@code active}. - * - * @param active Indicates whether the payment instrument is active and can be used for - * payments. To deactivate it, send a `DELETE` request to the resource endpoint. - * @return This builder instance. - */ - public Builder active(Boolean active) { - this.active = active; - return this; - } - /** * Sets the value for {@code card}. * @@ -92,17 +78,6 @@ public Builder mandate(com.sumup.sdk.models.MandateResponse mandate) { return this; } - /** - * Sets the value for {@code token}. - * - * @param token Unique token identifying the saved payment card for a customer. - * @return This builder instance. - */ - public Builder token(String token) { - this.token = token; - return this; - } - /** * Sets the value for {@code type}. * @@ -120,7 +95,7 @@ public Builder type(com.sumup.sdk.models.PaymentInstrumentResponseType type) { * @return Immutable PaymentInstrumentResponse. */ public PaymentInstrumentResponse build() { - return new PaymentInstrumentResponse(active, card, createdAt, mandate, token, type); + return new PaymentInstrumentResponse(null, card, createdAt, mandate, null, type); } } } diff --git a/src/main/java/com/sumup/sdk/models/PaymentInstrumentResponseCard.java b/src/main/java/com/sumup/sdk/models/PaymentInstrumentResponseCard.java index 7d16225..e3a03eb 100644 --- a/src/main/java/com/sumup/sdk/models/PaymentInstrumentResponseCard.java +++ b/src/main/java/com/sumup/sdk/models/PaymentInstrumentResponseCard.java @@ -19,22 +19,10 @@ public static Builder builder() { /** Builder for PaymentInstrumentResponseCard 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}. * @@ -52,7 +40,7 @@ public Builder type(com.sumup.sdk.models.CardType type) { * @return Immutable PaymentInstrumentResponseCard. */ public PaymentInstrumentResponseCard build() { - return new PaymentInstrumentResponseCard(last4Digits, type); + return new PaymentInstrumentResponseCard(null, type); } } } diff --git a/src/main/java/com/sumup/sdk/models/Timestamps.java b/src/main/java/com/sumup/sdk/models/Timestamps.java index e009818..554806f 100644 --- a/src/main/java/com/sumup/sdk/models/Timestamps.java +++ b/src/main/java/com/sumup/sdk/models/Timestamps.java @@ -1,8 +1,6 @@ // Code generated by sumup-java/codegen. DO NOT EDIT. package com.sumup.sdk.models; -import java.util.Objects; - public record Timestamps( /** * The date and time when the resource was created. This is a string as defined in [RFC 3339, @@ -26,45 +24,16 @@ public static Builder builder() { /** Builder for Timestamps instances. */ public static final class Builder { - private java.time.OffsetDateTime createdAt; - private java.time.OffsetDateTime updatedAt; private Builder() {} - /** - * Sets the value for {@code createdAt}. - * - * @param createdAt The date and time when the resource was created. This is a string as defined - * in [RFC 3339, section 5.6](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6). - * @return This builder instance. - */ - public Builder createdAt(java.time.OffsetDateTime createdAt) { - this.createdAt = createdAt; - return this; - } - - /** - * Sets the value for {@code updatedAt}. - * - * @param updatedAt The date and time when the resource was last updated. This is a string as - * defined in [RFC 3339, section - * 5.6](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6). - * @return This builder instance. - */ - public Builder updatedAt(java.time.OffsetDateTime updatedAt) { - this.updatedAt = updatedAt; - return this; - } - /** * Builds an immutable Timestamps instance. * * @return Immutable Timestamps. */ public Timestamps build() { - return new Timestamps( - Objects.requireNonNull(createdAt, "createdAt"), - Objects.requireNonNull(updatedAt, "updatedAt")); + return new Timestamps(null, null); } } }