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
6 changes: 6 additions & 0 deletions codegen/internal/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "?"),
Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -1345,6 +1350,7 @@ type modelPropertyTemplateData struct {
TypeName string
Description string
Required bool
IsReadOnly bool
NeedsInitializer bool
IsValueType bool
IsNullable bool
Expand Down
2 changes: 1 addition & 1 deletion codegen/internal/generator/templates/model_class.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed partial class {{ .Name }}
/// <summary>{{ .Description }}</summary>
{{- 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 }}

Expand Down
4 changes: 2 additions & 2 deletions src/SumUp/Models/BasePerson.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed partial class BasePerson
public DateTime? Birthdate { get; set; }
/// <summary>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.</summary>
[JsonPropertyName("change_status")]
public string? ChangeStatus { get; set; }
public string? ChangeStatus { get; }
/// <summary>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.</summary>
[JsonPropertyName("citizenship")]
public string? Citizenship { get; set; }
Expand All @@ -31,7 +31,7 @@ public sealed partial class BasePerson
public string? GivenName { get; set; }
/// <summary>The unique identifier for the person. This is a [typeid](https://github.com/sumup/typeid).</summary>
[JsonPropertyName("id")]
public string Id { get; set; } = default!;
public string Id { get; } = default!;
/// <summary>A list of country-specific personal identifiers.</summary>
[JsonPropertyName("identifiers")]
public IEnumerable<PersonalIdentifier>? Identifiers { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/SumUp/Models/Card.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public sealed partial class Card
public string ExpiryYear { get; set; } = default!;
/// <summary>Last 4 digits of the payment card number.</summary>
[JsonPropertyName("last_4_digits")]
public string Last4Digits { get; set; } = default!;
public string Last4Digits { get; } = default!;
/// <summary>Name of the cardholder as it appears on the payment card.</summary>
[JsonPropertyName("name")]
public string Name { get; set; } = default!;
Expand Down
2 changes: 1 addition & 1 deletion src/SumUp/Models/CardResponse.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed partial class CardResponse
{
/// <summary>Last 4 digits of the payment card number.</summary>
[JsonPropertyName("last_4_digits")]
public string? Last4Digits { get; set; }
public string? Last4Digits { get; }
/// <summary>Issuing card network of the payment card used for the transaction.</summary>
[JsonPropertyName("type")]
public CardType? Type { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/SumUp/Models/Checkout.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed partial class Checkout
public string? Description { get; set; }
/// <summary>Unique ID of the checkout resource.</summary>
[JsonPropertyName("id")]
public string? Id { get; set; }
public string? Id { get; }
/// <summary>Created mandate</summary>
[JsonPropertyName("mandate")]
public MandateResponse? Mandate { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions src/SumUp/Models/CheckoutCreateRequest.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public sealed partial class CheckoutCreateRequest
public string? CustomerId { get; set; }
/// <summary>Date and time of the creation of the payment checkout. Response format expressed according to [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) code.</summary>
[JsonPropertyName("date")]
public DateTimeOffset? Date { get; set; }
public DateTimeOffset? Date { get; }
/// <summary>Short description of the checkout visible in the SumUp dashboard. The description can contribute to reporting, allowing easier identification of a checkout.</summary>
[JsonPropertyName("description")]
public string? Description { get; set; }
/// <summary>Unique ID of the checkout resource.</summary>
[JsonPropertyName("id")]
public string? Id { get; set; }
public string? Id { get; }
/// <summary>Unique identifying code of the merchant profile.</summary>
[JsonPropertyName("merchant_code")]
public string MerchantCode { get; set; } = default!;
Expand All @@ -43,10 +43,10 @@ public sealed partial class CheckoutCreateRequest
public string? ReturnUrl { get; set; }
/// <summary>Current status of the checkout.</summary>
[JsonPropertyName("status")]
public string? Status { get; set; }
public string? Status { get; }
/// <summary>List of transactions related to the payment.</summary>
[JsonPropertyName("transactions")]
public IEnumerable<CheckoutCreateRequestTransactionsItem>? Transactions { get; set; }
public IEnumerable<CheckoutCreateRequestTransactionsItem>? Transactions { get; }
/// <summary>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.</summary>
[JsonPropertyName("valid_until")]
public DateTimeOffset? ValidUntil { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions src/SumUp/Models/CheckoutSuccess.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed partial class CheckoutSuccess
public string? Description { get; set; }
/// <summary>Unique ID of the checkout resource.</summary>
[JsonPropertyName("id")]
public string? Id { get; set; }
public string? Id { get; }
/// <summary>Created mandate</summary>
[JsonPropertyName("mandate")]
public MandateResponse? Mandate { get; set; }
Expand All @@ -51,10 +51,10 @@ public sealed partial class CheckoutSuccess
public string? Status { get; set; }
/// <summary>Transaction code of the successful transaction with which the payment for the checkout is completed.</summary>
[JsonPropertyName("transaction_code")]
public string? TransactionCode { get; set; }
public string? TransactionCode { get; }
/// <summary>Transaction ID of the successful transaction with which the payment for the checkout is completed.</summary>
[JsonPropertyName("transaction_id")]
public string? TransactionId { get; set; }
public string? TransactionId { get; }
/// <summary>List of transactions related to the payment.</summary>
[JsonPropertyName("transactions")]
public IEnumerable<CheckoutSuccessTransactionsItem>? Transactions { get; set; }
Expand Down
10 changes: 5 additions & 5 deletions src/SumUp/Models/Merchant.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed partial class Merchant
public string? BusinessType { get; set; }
/// <summary>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.</summary>
[JsonPropertyName("change_status")]
public string? ChangeStatus { get; set; }
public string? ChangeStatus { get; }
[JsonPropertyName("classic")]
public ClassicMerchantIdentifiers? Classic { get; set; }
/// <summary>Information about the company or business. This is legal information that is used for verification.</summary>
Expand All @@ -31,16 +31,16 @@ public sealed partial class Merchant
public string Country { get; set; } = default!;
/// <summary>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).</summary>
[JsonPropertyName("created_at")]
public DateTimeOffset CreatedAt { get; set; } = default!;
public DateTimeOffset CreatedAt { get; } = default!;
/// <summary>Three-letter [ISO currency code](https://en.wikipedia.org/wiki/ISO_4217) representing the default currency for the account.</summary>
[JsonPropertyName("default_currency")]
public string DefaultCurrency { get; set; } = default!;
public string DefaultCurrency { get; } = default!;
/// <summary>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.</summary>
[JsonPropertyName("default_locale")]
public string DefaultLocale { get; set; } = default!;
/// <summary>Short unique identifier for the merchant.</summary>
[JsonPropertyName("merchant_code")]
public string MerchantCode { get; set; } = default!;
public string MerchantCode { get; } = default!;
/// <summary>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.</summary>
[JsonPropertyName("meta")]
public Meta? Meta { get; set; }
Expand All @@ -52,7 +52,7 @@ public sealed partial class Merchant
public bool? Sandbox { get; set; }
/// <summary>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).</summary>
[JsonPropertyName("updated_at")]
public DateTimeOffset UpdatedAt { get; set; } = default!;
public DateTimeOffset UpdatedAt { get; } = default!;
/// <summary>The version of the resource. The version reflects a specific change submitted to the API via one of the `PATCH` endpoints.</summary>
[JsonPropertyName("version")]
public string? Version { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/SumUp/Models/PaymentInstrumentCard.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public sealed partial class PaymentInstrumentCard
{
/// <summary>Indicates whether the payment instrument is active and can be used for payments. To deactivate it, send a `DELETE` request to the resource endpoint.</summary>
[JsonPropertyName("active")]
public bool Active { get; set; }
public bool Active { get; }
/// <summary>__Required when payment type is `card`.__ Details of the payment card.</summary>
[JsonPropertyName("card")]
public Card Card { get; set; } = default!;
/// <summary>Unique token identifying the saved payment card for a customer.</summary>
[JsonPropertyName("token")]
public string Token { get; set; } = default!;
public string Token { get; } = default!;
/// <summary>Type of the payment instrument.</summary>
[JsonPropertyName("type")]
public string Type { get; set; } = default!;
Expand Down
4 changes: 2 additions & 2 deletions src/SumUp/Models/PaymentInstrumentResponse.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed partial class PaymentInstrumentResponse
{
/// <summary>Indicates whether the payment instrument is active and can be used for payments. To deactivate it, send a `DELETE` request to the resource endpoint.</summary>
[JsonPropertyName("active")]
public bool? Active { get; set; }
public bool? Active { get; }
/// <summary>Details of the payment card.</summary>
[JsonPropertyName("card")]
public PaymentInstrumentResponseCard? Card { get; set; }
Expand All @@ -21,7 +21,7 @@ public sealed partial class PaymentInstrumentResponse
public MandateResponse? Mandate { get; set; }
/// <summary>Unique token identifying the saved payment card for a customer.</summary>
[JsonPropertyName("token")]
public string? Token { get; set; }
public string? Token { get; }
/// <summary>Type of the payment instrument.</summary>
[JsonPropertyName("type")]
public string? Type { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/SumUp/Models/PaymentInstrumentResponseCard.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed partial class PaymentInstrumentResponseCard
{
/// <summary>Last 4 digits of the payment card number.</summary>
[JsonPropertyName("last_4_digits")]
public string? Last4Digits { get; set; }
public string? Last4Digits { get; }
/// <summary>Issuing card network of the payment card used for the transaction.</summary>
[JsonPropertyName("type")]
public CardType? Type { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/SumUp/Models/Person.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed partial class Person
public DateTime? Birthdate { get; set; }
/// <summary>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.</summary>
[JsonPropertyName("change_status")]
public string? ChangeStatus { get; set; }
public string? ChangeStatus { get; }
/// <summary>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.</summary>
[JsonPropertyName("citizenship")]
public string? Citizenship { get; set; }
Expand All @@ -30,7 +30,7 @@ public sealed partial class Person
public string? GivenName { get; set; }
/// <summary>The unique identifier for the person. This is a [typeid](https://github.com/sumup/typeid).</summary>
[JsonPropertyName("id")]
public string Id { get; set; } = default!;
public string Id { get; } = default!;
/// <summary>A list of country-specific personal identifiers.</summary>
[JsonPropertyName("identifiers")]
public IEnumerable<PersonalIdentifier>? Identifiers { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/SumUp/Models/Timestamps.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public sealed partial class Timestamps
{
/// <summary>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).</summary>
[JsonPropertyName("created_at")]
public DateTimeOffset CreatedAt { get; set; } = default!;
public DateTimeOffset CreatedAt { get; } = default!;
/// <summary>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).</summary>
[JsonPropertyName("updated_at")]
public DateTimeOffset UpdatedAt { get; set; } = default!;
public DateTimeOffset UpdatedAt { get; } = default!;
}
Loading