From 54dbeafa382c6a5c84d86fb368ce04f40ed10a80 Mon Sep 17 00:00:00 2001 From: Vitaly Kravtsov Date: Fri, 27 Sep 2024 02:03:07 +0600 Subject: [PATCH] fix: dotnet property names --- src/aidbox_sdk/generator/dotnet.clj | 42 +++++++++++------------ test/aidbox_sdk/generator/dotnet_test.clj | 2 -- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/aidbox_sdk/generator/dotnet.clj b/src/aidbox_sdk/generator/dotnet.clj index 7c89242..528731a 100644 --- a/src/aidbox_sdk/generator/dotnet.clj +++ b/src/aidbox_sdk/generator/dotnet.clj @@ -119,8 +119,8 @@ (defn generate-property "Generates class property from schema element." [{:keys [name array required value type choices] :as element}] - (let [name (uppercase-first-letter name) - lang-type (str/replace (or value type "") #"_" "") + (let [name' (->pascal-case name) + lang-type (str/replace (or value type "") #"[_-]" "") type (str (when required "required ") lang-type @@ -133,11 +133,11 @@ (= (:type element) "Meta") (if (:profile element) - (format "public new Meta Meta { get; } = new() { Profile = [\"%s\"] };" (:profile element)) - (format "public %s Meta { get; set; }" name)) + (format "public new Meta Meta { get; } = new() { Profile = [\"%s\"] };" (:profile element)) + (format "public %s Meta { get; set; }" name')) :else - (str "public " type " " name " { get; set; }" + (str "public " type " " name' " { get; set; }" (when (and (:required element) (:codeable-concept-pattern element)) " = new()") (:meta element))))) @@ -267,25 +267,25 @@ (generate-search-params [_ ir-schemas] (map (fn [ir-schema] - {:path (io/file "search" (str (:name ir-schema) "SearchParameters.cs")) - :content - (generate-module - :name "Aidbox.FHIR.Search" - :classes (generate-class - {:name (str (:name ir-schema) "SearchParameters") - :resource-name (str (:name ir-schema) "SearchParameters") - :base (when (:base ir-schema) - (str (:base ir-schema) "SearchParameters")) - :elements (map (fn [el] (update el :name ->pascal-case)) - (:elements ir-schema))}))}) - ir-schemas)) + {:path (io/file "search" (str (:name ir-schema) "SearchParameters.cs")) + :content + (generate-module + :name "Aidbox.FHIR.Search" + :classes (generate-class + {:name (str (:name ir-schema) "SearchParameters") + :resource-name (str (:name ir-schema) "SearchParameters") + :base (when (:base ir-schema) + (str (:base ir-schema) "SearchParameters")) + :elements (map (fn [el] (update el :name ->pascal-case)) + (:elements ir-schema))}))}) + ir-schemas)) (generate-constraints [_ constraint-ir-schemas] (mapv (fn [[name' schema]] - {:path (constraint-file-path schema name') - :content (generate-constraint-module - (assoc schema :url name'))}) - constraint-ir-schemas)) + {:path (constraint-file-path schema name') + :content (generate-constraint-module + (assoc schema :url name'))}) + constraint-ir-schemas)) (generate-sdk-files [_] (generator/prepare-sdk-files :dotnet))) diff --git a/test/aidbox_sdk/generator/dotnet_test.clj b/test/aidbox_sdk/generator/dotnet_test.clj index 63239db..7d25e5b 100644 --- a/test/aidbox_sdk/generator/dotnet_test.clj +++ b/test/aidbox_sdk/generator/dotnet_test.clj @@ -130,8 +130,6 @@ :content "using Aidbox.FHIR.Base;\nusing Aidbox.FHIR.Utils;\n\nnamespace Aidbox.FHIR.R4.Core;\n\npublic class Patient : DomainResource\n{\n public bool? MultipleBirthBoolean { get; set; }\n public Base.Address[]? Address { get; set; }\n public string? DeceasedDateTime { get; set; }\n public Base.ResourceReference? ManagingOrganization { get; set; }\n public bool? DeceasedBoolean { get; set; }\n public Base.HumanName[]? Name { get; set; }\n public string? BirthDate { get; set; }\n public int? MultipleBirthInteger { get; set; }\n public object? MultipleBirth \n {\n get\n {\n if (MultipleBirthBoolean is not null)\n {\n return MultipleBirthBoolean;\n }\n \n if (MultipleBirthInteger is not null)\n {\n return MultipleBirthInteger;\n }\n \n return null;\n }\n \n set\n {\n if (value?.GetType() == typeof(bool))\n {\n MultipleBirthBoolean = (bool)value;\n return;\n }\n \n if (value?.GetType() == typeof(int))\n {\n MultipleBirthInteger = (int)value;\n return;\n }\n \n throw new ArgumentException(\"Invalid type provided\");\n }\n }\n public object? Deceased \n {\n get\n {\n if (DeceasedDateTime is not null)\n {\n return DeceasedDateTime;\n }\n \n if (DeceasedBoolean is not null)\n {\n return DeceasedBoolean;\n }\n \n return null;\n }\n \n set\n {\n if (value?.GetType() == typeof(string))\n {\n DeceasedDateTime = (string)value;\n return;\n }\n \n if (value?.GetType() == typeof(bool))\n {\n DeceasedBoolean = (bool)value;\n return;\n }\n \n throw new ArgumentException(\"Invalid type provided\");\n }\n }\n public Base.Attachment[]? Photo { get; set; }\n public PatientLink[]? Link { get; set; }\n public bool? Active { get; set; }\n public PatientCommunication[]? Communication { get; set; }\n public Base.Identifier[]? Identifier { get; set; }\n public Base.ContactPoint[]? Telecom { get; set; }\n public Base.ResourceReference[]? GeneralPractitioner { get; set; }\n public string? Gender { get; set; }\n public Base.CodeableConcept? MaritalStatus { get; set; }\n public PatientContact[]? Contact { get; set; }\n\n public class PatientLink : BackboneElement\n {\n public required string Type { get; set; }\n public required Base.ResourceReference Other { get; set; }\n }\n\n public class PatientCommunication : BackboneElement\n {\n public required Base.CodeableConcept Language { get; set; }\n public bool? Preferred { get; set; }\n }\n\n public class PatientContact : BackboneElement\n {\n public Base.HumanName? Name { get; set; }\n public string? Gender { get; set; }\n public Base.Period? Period { get; set; }\n public Base.Address? Address { get; set; }\n public Base.ContactPoint[]? Telecom { get; set; }\n public Base.ResourceReference? Organization { get; set; }\n public Base.CodeableConcept[]? Relationship { get; set; }\n }\n}"}))) - - (deftest test-generate-search-params (is (= (sut/generate-search-params generator fixtures/patient-search-params-ir-schemas)