diff --git a/src/PollinationSDK.Tests/Api/LicenseTests.cs b/src/PollinationSDK.Tests/Api/LicenseTests.cs index 1a153423..2176c298 100644 --- a/src/PollinationSDK.Tests/Api/LicenseTests.cs +++ b/src/PollinationSDK.Tests/Api/LicenseTests.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using System.IO; using System.Linq; namespace PollinationSDK.Test @@ -26,6 +27,15 @@ public void GetLicenseKeyTest() var key = Utilities.GetValidLicenseKey("rhino_plugin"); Assert.IsTrue(!string.IsNullOrEmpty(key)); } + + [Test] + public void DeserializeLicense() + { + var f = Path.GetFullPath(@"../../../TestSample/licensePublic.json"); + var json = System.IO.File.ReadAllText(f); + var l = LicensePublic.FromJson(json); + Assert.IsNotNull(l); + } } } diff --git a/src/PollinationSDK.Tests/TestSample/licensePublic.json b/src/PollinationSDK.Tests/TestSample/licensePublic.json new file mode 100644 index 00000000..516856b1 --- /dev/null +++ b/src/PollinationSDK.Tests/TestSample/licensePublic.json @@ -0,0 +1,26 @@ +{ + "id": "7832b8b1-xxxx-xxxx-xxxx-8ee6253b0aab", + "created_at": "2023-12-11T00:26:25.877353+00:00", + "updated_at": "2023-12-25T03:00:27.492802+00:00", + "key": "5A87B3-XXXXXX-XXXXXX-XXXXXX-XXXXXX-666F6E", + "revoked": false, + "suspended": false, + "total_activations": 0, + "total_deactivations": 0, + "validity": 0, + "allowed_activations": 20, + "type": "hosted-floating", + "server_sync_grace_period": 86400, + "server_sync_interval": 3600, + "lease_duration": 3630, + "product_id": "95e61f3a-xxxx-xxxx-xxxx-5aaa9321ba23", + "notes": null, + "metadata": [ + { + "id": "f38f378d-xxxx-xxxx-xxxx-5ca758a917e2", + "key": "pollination/account-id", + "value": "1da45dba-xxxx-xxxx-xxxx-b5df2f28e3bd", + "visible": false + } + ] +} \ No newline at end of file diff --git a/src/PollinationSDK/Model/License.cs b/src/PollinationSDK/Model/License.cs index 61560324..6913bcea 100644 --- a/src/PollinationSDK/Model/License.cs +++ b/src/PollinationSDK/Model/License.cs @@ -47,12 +47,12 @@ protected License() /// A URL to the license used for the package.. public License ( - string name, // Required parameters + //string name, // Required parameters Dictionary annotations= default, string url= default// Optional parameters ) : base()// BaseClass { // to ensure "name" is required (not null) - this.Name = name ?? throw new ArgumentNullException("name is a required property for License and cannot be null"); + //this.Name = name ?? throw new ArgumentNullException("name is a required property for License and cannot be null"); this.Annotations = annotations; this.Url = url; @@ -71,7 +71,7 @@ public License /// The license name used for the package. /// /// The license name used for the package. - [DataMember(Name = "name", IsRequired = true)] + [DataMember(Name = "name")] public string Name { get; set; } /// /// An optional dictionary to add annotations to inputs. These annotations will be used by the client side libraries. diff --git a/src/PollinationSDK/Model/LicenseMetaData.cs b/src/PollinationSDK/Model/LicenseMetaData.cs new file mode 100644 index 00000000..a1ffaa60 --- /dev/null +++ b/src/PollinationSDK/Model/LicenseMetaData.cs @@ -0,0 +1,252 @@ +/* + * pollination-server + * + * Pollination Server OpenAPI Definition + * + * Contact: info@pollination.cloud + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +using System; +using System.Linq; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System.ComponentModel.DataAnnotations; + + +namespace PollinationSDK +{ + /// + /// Metadata + /// + [DataContract(Name = "LicenseMetadata")] + public partial class LicenseMetadata : CryptlexBase, IEquatable, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected LicenseMetadata() + { + // Set non-required readonly properties with defaultValue + this.Type = "LicenseMetadata"; + } + + /// + /// Initializes a new instance of the class. + /// + /// key (required). + /// value (required). + /// id. + /// visible (default to false). + public LicenseMetadata + ( + string key, string value, // Required parameters + string id = default, bool visible = false // Optional parameters + ) : base()// BaseClass + { + // to ensure "key" is required (not null) + this.Key = key ?? throw new ArgumentNullException("key is a required property for Metadata and cannot be null"); + // to ensure "value" is required (not null) + this.Value = value ?? throw new ArgumentNullException("value is a required property for Metadata and cannot be null"); + this.Id = id; + this.Visible = visible; + + // Set non-required readonly properties with defaultValue + this.Type = "LicenseMetadata"; + } + + //============================================== is ReadOnly + /// + /// Gets or Sets Type + /// + [DataMember(Name = "type", EmitDefaultValue = true)] + public override string Type { get; protected set; } = "LicenseMetadata"; + + /// + /// Gets or Sets Key + /// + [DataMember(Name = "key", IsRequired = true, EmitDefaultValue = false)] + public string Key { get; set; } + /// + /// Gets or Sets Value + /// + [DataMember(Name = "value", IsRequired = true, EmitDefaultValue = false)] + public string Value { get; set; } + /// + /// Gets or Sets Id + /// + [DataMember(Name = "id", EmitDefaultValue = false)] + public string Id { get; set; } + /// + /// Gets or Sets Visible + /// + [DataMember(Name = "visible", EmitDefaultValue = true)] + public bool Visible { get; set; } = false; + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + return "LicenseMetadata"; + } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString(bool detailed) + { + if (!detailed) + return this.ToString(); + + var sb = new StringBuilder(); + sb.Append("LicenseMetadata:\n"); + sb.Append(" Type: ").Append(Type).Append("\n"); + sb.Append(" Key: ").Append(Key).Append("\n"); + sb.Append(" Value: ").Append(Value).Append("\n"); + sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" Visible: ").Append(Visible).Append("\n"); + return sb.ToString(); + } + + /// + /// Returns the object from JSON string + /// + /// Metadata object + public static LicenseMetadata FromJson(string json) + { + var obj = JsonConvert.DeserializeObject(json, JsonSetting.AnyOfConvertSetting); + if (obj == null) + return null; + return obj.Type.ToLower() == obj.GetType().Name.ToLower() ? obj : null; + } + + /// + /// Creates a new instance with the same properties. + /// + /// Metadata object + public virtual LicenseMetadata DuplicateMetadata() + { + return FromJson(this.ToJson()); + } + + /// + /// Creates a new instance with the same properties. + /// + /// OpenAPIGenBaseModel + public override OpenAPIGenBaseModel Duplicate() + { + return DuplicateMetadata(); + } + + /// + /// Creates a new instance with the same properties. + /// + /// OpenAPIGenBaseModel + public override CryptlexBase DuplicateCryptlexBase() + { + return DuplicateMetadata(); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + input = input is AnyOf anyOf ? anyOf.Obj : input; + return this.Equals(input as LicenseMetadata); + } + + /// + /// Returns true if Metadata instances are equal + /// + /// Instance of Metadata to be compared + /// Boolean + public bool Equals(LicenseMetadata input) + { + if (input == null) + return false; + return base.Equals(input) && + ( + this.Key == input.Key || + (this.Key != null && + this.Key.Equals(input.Key)) + ) && base.Equals(input) && + ( + this.Value == input.Value || + (this.Value != null && + this.Value.Equals(input.Value)) + ) && base.Equals(input) && + ( + this.Id == input.Id || + (this.Id != null && + this.Id.Equals(input.Id)) + ) && base.Equals(input) && + ( + this.Visible == input.Visible || + (this.Visible != null && + this.Visible.Equals(input.Visible)) + ) && base.Equals(input) && + ( + this.Type == input.Type || + (this.Type != null && + this.Type.Equals(input.Type)) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = base.GetHashCode(); + if (this.Key != null) + hashCode = hashCode * 59 + this.Key.GetHashCode(); + if (this.Value != null) + hashCode = hashCode * 59 + this.Value.GetHashCode(); + if (this.Id != null) + hashCode = hashCode * 59 + this.Id.GetHashCode(); + if (this.Visible != null) + hashCode = hashCode * 59 + this.Visible.GetHashCode(); + if (this.Type != null) + hashCode = hashCode * 59 + this.Type.GetHashCode(); + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + foreach (var x in base.BaseValidate(validationContext)) yield return x; + + + // Type (string) pattern + Regex regexType = new Regex(@"^LicenseMetadata", RegexOptions.CultureInvariant); + if (false == regexType.Match(this.Type).Success) + { + yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Type, must match a pattern of " + regexType, new[] { "Type" }); + } + + yield break; + } + } +} diff --git a/src/PollinationSDK/Model/LicensePublic.cs b/src/PollinationSDK/Model/LicensePublic.cs index b2e0b7ad..958071dd 100644 --- a/src/PollinationSDK/Model/LicensePublic.cs +++ b/src/PollinationSDK/Model/LicensePublic.cs @@ -32,8 +32,8 @@ public partial class LicensePublic : License, IEquatable, IValida /// /// Gets or Sets Type /// - [DataMember(Name="license_type")] - public LicenseType LicenseType { get; set; } + [DataMember(Name = "license_type")] + public LicenseType LicenseType { get; set; } = LicenseType.HostedFloating; /// /// Initializes a new instance of the class. /// @@ -68,9 +68,9 @@ protected LicensePublic() /// A URL to the license used for the package.. public LicensePublic ( - string name, string id, DateTime createdAt, DateTime updatedAt, string key, bool revoked, bool suspended, int totalActivations, int totalDeactivations, int validity, int allowedActivations, int serverSyncGracePeriod, int serverSyncInterval, int leaseDuration, string productId, List metadata, LicenseType type, // Required parameters + string id, DateTime createdAt, DateTime updatedAt, string key, bool revoked, bool suspended, int totalActivations, int totalDeactivations, int validity, int allowedActivations, int serverSyncGracePeriod, int serverSyncInterval, int leaseDuration, string productId, List metadata, LicenseType type, // Required parameters Dictionary annotations= default, string url= default, string notes= default// Optional parameters - ) : base(name: name, annotations: annotations, url: url )// BaseClass + ) : base( annotations: annotations, url: url )// BaseClass { // to ensure "id" is required (not null) this.Id = id ?? throw new ArgumentNullException("id is a required property for LicensePublic and cannot be null"); @@ -173,7 +173,7 @@ public LicensePublic /// Gets or Sets Metadata /// [DataMember(Name = "metadata", IsRequired = true)] - public List Metadata { get; set; } + public List Metadata { get; set; } /// /// Gets or Sets Notes /// @@ -232,7 +232,7 @@ public static LicensePublic FromJson(string json) var obj = JsonConvert.DeserializeObject(json, JsonSetting.AnyOfConvertSetting); if (obj == null) return null; - return obj.Type.ToLower() == obj.GetType().Name.ToLower() ? obj : null; + return obj; } ///