diff --git a/codegen/internal/generator/generator.go b/codegen/internal/generator/generator.go
index 7525904..c440605 100644
--- a/codegen/internal/generator/generator.go
+++ b/codegen/internal/generator/generator.go
@@ -421,6 +421,7 @@ func (g *Generator) collectProperties(ownerName string, schema *base.Schema) ([]
TypeName: typeInfo.TypeName,
Description: desc,
Required: required,
+ IsReadOnly: schemaIsReadOnly(g.schemaFromProxy(propRef)),
NeedsInitializer: required && !typeInfo.IsValueType && !strings.HasSuffix(typeInfo.TypeName, "?"),
IsValueType: typeInfo.IsValueType,
IsNullable: strings.HasSuffix(typeInfo.TypeName, "?"),
@@ -1310,6 +1311,10 @@ func schemaHasType(schema *base.Schema, target string) bool {
return false
}
+func schemaIsReadOnly(schema *base.Schema) bool {
+ return schema != nil && schema.ReadOnly != nil && *schema.ReadOnly
+}
+
func canonicalMethodName(method string) string {
if method == "" {
return ""
@@ -1345,6 +1350,7 @@ type modelPropertyTemplateData struct {
TypeName string
Description string
Required bool
+ IsReadOnly bool
NeedsInitializer bool
IsValueType bool
IsNullable bool
diff --git a/codegen/internal/generator/templates/model_class.tmpl b/codegen/internal/generator/templates/model_class.tmpl
index a6b0a39..a68d360 100644
--- a/codegen/internal/generator/templates/model_class.tmpl
+++ b/codegen/internal/generator/templates/model_class.tmpl
@@ -26,7 +26,7 @@ public sealed partial class {{ .Name }}
/// {{ .Description }}
{{- end }}
[JsonPropertyName("{{ .JsonName }}")]
- public {{ .TypeName }} {{ .PropertyName }} { get; set; }{{ if .NeedsInitializer }} = default!;{{ end }}
+ public {{ .TypeName }} {{ .PropertyName }} { get;{{- if not .IsReadOnly }} set;{{- end }} }{{ if .NeedsInitializer }} = default!;{{ end }}
{{- end }}
{{- if .HasExtensionData }}
diff --git a/src/SumUp/Models/BasePerson.g.cs b/src/SumUp/Models/BasePerson.g.cs
index 853d08b..8bbfb84 100644
--- a/src/SumUp/Models/BasePerson.g.cs
+++ b/src/SumUp/Models/BasePerson.g.cs
@@ -16,7 +16,7 @@ public sealed partial class BasePerson
public DateTime? Birthdate { get; set; }
/// 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.
[JsonPropertyName("change_status")]
- public string? ChangeStatus { get; set; }
+ public string? ChangeStatus { get; }
/// An [ISO3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code. This definition users `oneOf` with a two-character string type to allow for support of future countries in client code.
[JsonPropertyName("citizenship")]
public string? Citizenship { get; set; }
@@ -31,7 +31,7 @@ public sealed partial class BasePerson
public string? GivenName { get; set; }
/// The unique identifier for the person. This is a [typeid](https://github.com/sumup/typeid).
[JsonPropertyName("id")]
- public string Id { get; set; } = default!;
+ public string Id { get; } = default!;
/// A list of country-specific personal identifiers.
[JsonPropertyName("identifiers")]
public IEnumerable? Identifiers { get; set; }
diff --git a/src/SumUp/Models/Card.g.cs b/src/SumUp/Models/Card.g.cs
index 94329e6..2292ec7 100644
--- a/src/SumUp/Models/Card.g.cs
+++ b/src/SumUp/Models/Card.g.cs
@@ -18,7 +18,7 @@ public sealed partial class Card
public string ExpiryYear { get; set; } = default!;
/// Last 4 digits of the payment card number.
[JsonPropertyName("last_4_digits")]
- public string Last4Digits { get; set; } = default!;
+ public string Last4Digits { get; } = default!;
/// Name of the cardholder as it appears on the payment card.
[JsonPropertyName("name")]
public string Name { get; set; } = default!;
diff --git a/src/SumUp/Models/CardResponse.g.cs b/src/SumUp/Models/CardResponse.g.cs
index 9934476..7f93912 100644
--- a/src/SumUp/Models/CardResponse.g.cs
+++ b/src/SumUp/Models/CardResponse.g.cs
@@ -9,7 +9,7 @@ public sealed partial class CardResponse
{
/// Last 4 digits of the payment card number.
[JsonPropertyName("last_4_digits")]
- public string? Last4Digits { get; set; }
+ public string? Last4Digits { get; }
/// Issuing card network of the payment card used for the transaction.
[JsonPropertyName("type")]
public CardType? Type { get; set; }
diff --git a/src/SumUp/Models/Checkout.g.cs b/src/SumUp/Models/Checkout.g.cs
index f89c0ee..ed4f156 100644
--- a/src/SumUp/Models/Checkout.g.cs
+++ b/src/SumUp/Models/Checkout.g.cs
@@ -28,7 +28,7 @@ public sealed partial class Checkout
public string? Description { get; set; }
/// Unique ID of the checkout resource.
[JsonPropertyName("id")]
- public string? Id { get; set; }
+ public string? Id { get; }
/// Created mandate
[JsonPropertyName("mandate")]
public MandateResponse? Mandate { get; set; }
diff --git a/src/SumUp/Models/CheckoutCreateRequest.g.cs b/src/SumUp/Models/CheckoutCreateRequest.g.cs
index 262d72a..2933b56 100644
--- a/src/SumUp/Models/CheckoutCreateRequest.g.cs
+++ b/src/SumUp/Models/CheckoutCreateRequest.g.cs
@@ -22,13 +22,13 @@ public sealed partial class CheckoutCreateRequest
public string? CustomerId { get; set; }
/// Date and time of the creation of the payment checkout. Response format expressed according to [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) code.
[JsonPropertyName("date")]
- public DateTimeOffset? Date { get; set; }
+ public DateTimeOffset? Date { get; }
/// Short description of the checkout visible in the SumUp dashboard. The description can contribute to reporting, allowing easier identification of a checkout.
[JsonPropertyName("description")]
public string? Description { get; set; }
/// Unique ID of the checkout resource.
[JsonPropertyName("id")]
- public string? Id { get; set; }
+ public string? Id { get; }
/// Unique identifying code of the merchant profile.
[JsonPropertyName("merchant_code")]
public string MerchantCode { get; set; } = default!;
@@ -43,10 +43,10 @@ public sealed partial class CheckoutCreateRequest
public string? ReturnUrl { get; set; }
/// Current status of the checkout.
[JsonPropertyName("status")]
- public string? Status { get; set; }
+ public string? Status { get; }
/// List of transactions related to the payment.
[JsonPropertyName("transactions")]
- public IEnumerable? Transactions { get; set; }
+ public IEnumerable? Transactions { get; }
/// Date and time of the checkout expiration before which the client application needs to send a processing request. If no value is present, the checkout does not have an expiration time.
[JsonPropertyName("valid_until")]
public DateTimeOffset? ValidUntil { get; set; }
diff --git a/src/SumUp/Models/CheckoutSuccess.g.cs b/src/SumUp/Models/CheckoutSuccess.g.cs
index dea5ad4..fdca45a 100644
--- a/src/SumUp/Models/CheckoutSuccess.g.cs
+++ b/src/SumUp/Models/CheckoutSuccess.g.cs
@@ -27,7 +27,7 @@ public sealed partial class CheckoutSuccess
public string? Description { get; set; }
/// Unique ID of the checkout resource.
[JsonPropertyName("id")]
- public string? Id { get; set; }
+ public string? Id { get; }
/// Created mandate
[JsonPropertyName("mandate")]
public MandateResponse? Mandate { get; set; }
@@ -51,10 +51,10 @@ public sealed partial class CheckoutSuccess
public string? Status { get; set; }
/// Transaction code of the successful transaction with which the payment for the checkout is completed.
[JsonPropertyName("transaction_code")]
- public string? TransactionCode { get; set; }
+ public string? TransactionCode { get; }
/// Transaction ID of the successful transaction with which the payment for the checkout is completed.
[JsonPropertyName("transaction_id")]
- public string? TransactionId { get; set; }
+ public string? TransactionId { get; }
/// List of transactions related to the payment.
[JsonPropertyName("transactions")]
public IEnumerable? Transactions { get; set; }
diff --git a/src/SumUp/Models/Merchant.g.cs b/src/SumUp/Models/Merchant.g.cs
index a3e3a0d..a517686 100644
--- a/src/SumUp/Models/Merchant.g.cs
+++ b/src/SumUp/Models/Merchant.g.cs
@@ -20,7 +20,7 @@ public sealed partial class Merchant
public string? BusinessType { get; set; }
/// 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.
[JsonPropertyName("change_status")]
- public string? ChangeStatus { get; set; }
+ public string? ChangeStatus { get; }
[JsonPropertyName("classic")]
public ClassicMerchantIdentifiers? Classic { get; set; }
/// Information about the company or business. This is legal information that is used for verification.
@@ -31,16 +31,16 @@ public sealed partial class Merchant
public string Country { get; set; } = default!;
/// 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).
[JsonPropertyName("created_at")]
- public DateTimeOffset CreatedAt { get; set; } = default!;
+ public DateTimeOffset CreatedAt { get; } = default!;
/// Three-letter [ISO currency code](https://en.wikipedia.org/wiki/ISO_4217) representing the default currency for the account.
[JsonPropertyName("default_currency")]
- public string DefaultCurrency { get; set; } = default!;
+ public string DefaultCurrency { get; } = default!;
/// Merchant's default locale, represented as a BCP47 [RFC5646](https://datatracker.ietf.org/doc/html/rfc5646) language tag. This is typically an ISO 639-1 Alpha-2 [ISO639‑1](https://www.iso.org/iso-639-language-code) language code in lowercase and an ISO 3166-1 Alpha-2 [ISO3166‑1](https://www.iso.org/iso-3166-country-codes.html) country code in uppercase, separated by a dash. For example, en-US or fr-CA. In multilingual countries this is the merchant's preferred locale out of those, that are officially spoken in the country. In a countries with a single official language this will match the official language.
[JsonPropertyName("default_locale")]
public string DefaultLocale { get; set; } = default!;
/// Short unique identifier for the merchant.
[JsonPropertyName("merchant_code")]
- public string MerchantCode { get; set; } = default!;
+ public string MerchantCode { get; } = default!;
/// A set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. **Warning**: Updating Meta will overwrite the existing data. Make sure to always include the complete JSON object.
[JsonPropertyName("meta")]
public Meta? Meta { get; set; }
@@ -52,7 +52,7 @@ public sealed partial class Merchant
public bool? Sandbox { get; set; }
/// 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).
[JsonPropertyName("updated_at")]
- public DateTimeOffset UpdatedAt { get; set; } = default!;
+ public DateTimeOffset UpdatedAt { get; } = default!;
/// The version of the resource. The version reflects a specific change submitted to the API via one of the `PATCH` endpoints.
[JsonPropertyName("version")]
public string? Version { get; set; }
diff --git a/src/SumUp/Models/PaymentInstrumentCard.g.cs b/src/SumUp/Models/PaymentInstrumentCard.g.cs
index 635cc63..accaf24 100644
--- a/src/SumUp/Models/PaymentInstrumentCard.g.cs
+++ b/src/SumUp/Models/PaymentInstrumentCard.g.cs
@@ -9,13 +9,13 @@ public sealed partial class PaymentInstrumentCard
{
/// Indicates whether the payment instrument is active and can be used for payments. To deactivate it, send a `DELETE` request to the resource endpoint.
[JsonPropertyName("active")]
- public bool Active { get; set; }
+ public bool Active { get; }
/// __Required when payment type is `card`.__ Details of the payment card.
[JsonPropertyName("card")]
public Card Card { get; set; } = default!;
/// Unique token identifying the saved payment card for a customer.
[JsonPropertyName("token")]
- public string Token { get; set; } = default!;
+ public string Token { get; } = default!;
/// Type of the payment instrument.
[JsonPropertyName("type")]
public string Type { get; set; } = default!;
diff --git a/src/SumUp/Models/PaymentInstrumentResponse.g.cs b/src/SumUp/Models/PaymentInstrumentResponse.g.cs
index 1dae668..ac1c08b 100644
--- a/src/SumUp/Models/PaymentInstrumentResponse.g.cs
+++ b/src/SumUp/Models/PaymentInstrumentResponse.g.cs
@@ -9,7 +9,7 @@ public sealed partial class PaymentInstrumentResponse
{
/// Indicates whether the payment instrument is active and can be used for payments. To deactivate it, send a `DELETE` request to the resource endpoint.
[JsonPropertyName("active")]
- public bool? Active { get; set; }
+ public bool? Active { get; }
/// Details of the payment card.
[JsonPropertyName("card")]
public PaymentInstrumentResponseCard? Card { get; set; }
@@ -21,7 +21,7 @@ public sealed partial class PaymentInstrumentResponse
public MandateResponse? Mandate { get; set; }
/// Unique token identifying the saved payment card for a customer.
[JsonPropertyName("token")]
- public string? Token { get; set; }
+ public string? Token { get; }
/// Type of the payment instrument.
[JsonPropertyName("type")]
public string? Type { get; set; }
diff --git a/src/SumUp/Models/PaymentInstrumentResponseCard.g.cs b/src/SumUp/Models/PaymentInstrumentResponseCard.g.cs
index b23eefc..29e644f 100644
--- a/src/SumUp/Models/PaymentInstrumentResponseCard.g.cs
+++ b/src/SumUp/Models/PaymentInstrumentResponseCard.g.cs
@@ -9,7 +9,7 @@ public sealed partial class PaymentInstrumentResponseCard
{
/// Last 4 digits of the payment card number.
[JsonPropertyName("last_4_digits")]
- public string? Last4Digits { get; set; }
+ public string? Last4Digits { get; }
/// Issuing card network of the payment card used for the transaction.
[JsonPropertyName("type")]
public CardType? Type { get; set; }
diff --git a/src/SumUp/Models/Person.g.cs b/src/SumUp/Models/Person.g.cs
index a573762..8597dad 100644
--- a/src/SumUp/Models/Person.g.cs
+++ b/src/SumUp/Models/Person.g.cs
@@ -15,7 +15,7 @@ public sealed partial class Person
public DateTime? Birthdate { get; set; }
/// 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.
[JsonPropertyName("change_status")]
- public string? ChangeStatus { get; set; }
+ public string? ChangeStatus { get; }
/// An [ISO3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code. This definition users `oneOf` with a two-character string type to allow for support of future countries in client code.
[JsonPropertyName("citizenship")]
public string? Citizenship { get; set; }
@@ -30,7 +30,7 @@ public sealed partial class Person
public string? GivenName { get; set; }
/// The unique identifier for the person. This is a [typeid](https://github.com/sumup/typeid).
[JsonPropertyName("id")]
- public string Id { get; set; } = default!;
+ public string Id { get; } = default!;
/// A list of country-specific personal identifiers.
[JsonPropertyName("identifiers")]
public IEnumerable? Identifiers { get; set; }
diff --git a/src/SumUp/Models/Timestamps.g.cs b/src/SumUp/Models/Timestamps.g.cs
index 592848e..11df946 100644
--- a/src/SumUp/Models/Timestamps.g.cs
+++ b/src/SumUp/Models/Timestamps.g.cs
@@ -8,8 +8,8 @@ public sealed partial class Timestamps
{
/// 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).
[JsonPropertyName("created_at")]
- public DateTimeOffset CreatedAt { get; set; } = default!;
+ public DateTimeOffset CreatedAt { get; } = default!;
/// 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).
[JsonPropertyName("updated_at")]
- public DateTimeOffset UpdatedAt { get; set; } = default!;
+ public DateTimeOffset UpdatedAt { get; } = default!;
}
\ No newline at end of file