Skip to content

Commit

Permalink
feat: generate python class with inner classes
Browse files Browse the repository at this point in the history
  • Loading branch information
krvital committed Aug 25, 2024
1 parent f022119 commit 54305f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/aidbox_sdk/generator/python.clj
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,17 @@
base-class-name (when-not (str/blank? base-class)
(uppercase-first-letter base-class))]
(str
(str/join "\n\n" (map #(->> % str/split-lines (map u/add-indent) (str/join "\n")) inner-classes))
(when (and inner-classes
(seq inner-classes))
(str
(str/join "\n\n" inner-classes)
"\n\n"))

"class " class-name' "(" base-class-name "):"
(when-not (str/blank? properties)
"\n")
properties
(when (and inner-classes
(seq inner-classes))
"\n\n"))))
)))

(defn generate-module
[& {:keys [deps classes]
Expand Down
9 changes: 8 additions & 1 deletion test/aidbox_sdk/generator/python_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@
(deftest test-generate-class
(testing "base"
(is (= (gen.python/generate-class fixtures/patient-ir-schema)
"class Patient(DomainResource):\n active: Optional[bool] = None\n address: Optional[List[Address]] = None\n birth_date: Optional[str] = None\n communication: Optional[List[BackboneElement]] = None\n contact: Optional[List[BackboneElement]] = None\n \n deceased_boolean: Optional[bool] = None\n deceased_date_time: Optional[str] = None\n gender: Optional[str] = None\n general_practitioner: Optional[List[Reference]] = None\n identifier: Optional[List[Identifier]] = None\n link: Optional[List[BackboneElement]] = None\n managing_organization: Optional[Reference] = None\n marital_status: Optional[CodeableConcept] = None\n \n multiple_birth_boolean: Optional[bool] = None\n multiple_birth_integer: Optional[integer] = None\n name: Optional[List[HumanName]] = None\n photo: Optional[List[Attachment]] = None\n telecom: Optional[List[ContactPoint]] = None"))))
"class Patient(DomainResource):\n active: Optional[bool] = None\n address: Optional[List[Address]] = None\n birth_date: Optional[str] = None\n communication: Optional[List[BackboneElement]] = None\n contact: Optional[List[BackboneElement]] = None\n \n deceased_boolean: Optional[bool] = None\n deceased_date_time: Optional[str] = None\n gender: Optional[str] = None\n general_practitioner: Optional[List[Reference]] = None\n identifier: Optional[List[Identifier]] = None\n link: Optional[List[BackboneElement]] = None\n managing_organization: Optional[Reference] = None\n marital_status: Optional[CodeableConcept] = None\n \n multiple_birth_boolean: Optional[bool] = None\n multiple_birth_integer: Optional[integer] = None\n name: Optional[List[HumanName]] = None\n photo: Optional[List[Attachment]] = None\n telecom: Optional[List[ContactPoint]] = None")))

(testing "with inner classes"
(is (= (gen.python/generate-class fixtures/patient-ir-schema
["class Patient_Link(BackboneElement):\n other: Reference\n type: str"
"class Patient_Communication(BackboneElement):\n language: CodeableConcept\n preferred: Optional[bool] = None"
"class Patient_Contact(BackboneElement):\n address: Optional[Address] = None\n gender: Optional[str] = None\n name: Optional[HumanName] = None\n organization: Optional[Reference] = None\n period: Optional[Period] = None\n relationship: Optional[List[CodeableConcept]] = None\n telecom: Optional[List[ContactPoint]] = None"])
"class Patient_Link(BackboneElement):\n other: Reference\n type: str\n\nclass Patient_Communication(BackboneElement):\n language: CodeableConcept\n preferred: Optional[bool] = None\n\nclass Patient_Contact(BackboneElement):\n address: Optional[Address] = None\n gender: Optional[str] = None\n name: Optional[HumanName] = None\n organization: Optional[Reference] = None\n period: Optional[Period] = None\n relationship: Optional[List[CodeableConcept]] = None\n telecom: Optional[List[ContactPoint]] = None\n\nclass Patient(DomainResource):\n active: Optional[bool] = None\n address: Optional[List[Address]] = None\n birth_date: Optional[str] = None\n communication: Optional[List[BackboneElement]] = None\n contact: Optional[List[BackboneElement]] = None\n \n deceased_boolean: Optional[bool] = None\n deceased_date_time: Optional[str] = None\n gender: Optional[str] = None\n general_practitioner: Optional[List[Reference]] = None\n identifier: Optional[List[Identifier]] = None\n link: Optional[List[BackboneElement]] = None\n managing_organization: Optional[Reference] = None\n marital_status: Optional[CodeableConcept] = None\n \n multiple_birth_boolean: Optional[bool] = None\n multiple_birth_integer: Optional[integer] = None\n name: Optional[List[HumanName]] = None\n photo: Optional[List[Attachment]] = None\n telecom: Optional[List[ContactPoint]] = None"))))

#_(deftest generate-datatypes
(is
Expand Down

0 comments on commit 54305f9

Please sign in to comment.