@@ -39,9 +39,7 @@ SerialName() {
3939
4040# join the list values with serial names and enum names and prepare enum
4141options () {
42- values=" $( list) "
43- serialNames=" $( echo " $values " | SerialName) "
44- options=" $( echo " $values " | CamelCase | suffix ' ,' ) "
42+ options=" $( echo " $listed " | CamelCase | suffix ' ,' ) "
4543 cat << END
4644package $package .$endpoint
4745
5856}
5957
6058units () {
61- values=" $( list) "
62- serialNames=" $( echo " $values " | SerialName) "
63- units=" $( echo " $values " | camelCase | prefix " val " | suffix ' : Unit? = null,' ) "
59+ units=" $( echo " $listed " | camelCase | prefix " val " | suffix ' : Unit? = null,' ) "
6460 cat << END
6561package $package .$endpoint
6662
7975 echo " ) : Response${name^} .Units"
8076}
8177
78+ values () {
79+ values=" $( echo " $listed " | camelCase | prefix " val " | suffix ' : Array<Float?>? = null,' ) "
80+ cat << END
81+ package $package .$endpoint
82+
83+ import $package .common.response.Response${name^}
84+ import $package .common.time.TimeFormat
85+ import $package .common.units.Unit
86+ import kotlinx.serialization.SerialName
87+ import kotlinx.serialization.Serializable
88+
89+ @Serializable
90+ class ${name^} Units(
91+ override val time: TimeFormat,
92+ END
93+ paste -d $' \n ' <( echo " $serialNames " ) <( echo " $units " ) \
94+ | prefix " "
95+ echo " ) : Response${name^} .Units"
96+ }
97+
98+ group () {
99+ listed=" $( list) "
100+ serialNames=" $( echo " $listed " | SerialName) "
101+ options < " tmp/$endpoint .html" > " $endpoint /${name^} Options.kt"
102+ units < " tmp/$endpoint .html" > " $endpoint /${name^} Units.kt"
103+ if [ " $name " == " daily" ]; then
104+ sed -i -r ' s/(sunrise|sunset): Unit/\1: TimeFormat/' " $endpoint /DailyUnits.kt"
105+ fi
106+ }
107+
82108declare -A docs=(
83109 [airquality]=" https://open-meteo.com/en/docs/air-quality-api"
84110 [ecmwf]=" https://open-meteo.com/en/docs/ecmwf-api"
@@ -90,22 +116,20 @@ declare -A docs=(
90116# should run in project root
91117cd " lib/src/main/kotlin/$( echo " $package " | tr ' .' ' /' ) " || exit 1
92118
93- # fetch only once html
119+ # fetch html only once
94120mkdir tmp
95121for endpoint in " ${! docs[@]} " ; do
96122 curl -s " ${docs[$endpoint]} " > " tmp/$endpoint .html"
97123done
98124
99125name=" hourly"
100126for endpoint in airquality ecmwf forecast historical marine; do
101- options < " tmp/$endpoint .html" > " $endpoint /HourlyOptions.kt"
102- units < " tmp/$endpoint .html" > " $endpoint /HourlyUnits.kt"
127+ group < " tmp/$endpoint .html"
103128done
104129
105130name=" daily"
106131for endpoint in forecast historical marine; do
107- options < " tmp/$endpoint .html" > " $endpoint /DailyOptions.kt"
108- units < " tmp/$endpoint .html" > " $endpoint /DailyUnits.kt"
132+ group < " tmp/$endpoint .html"
109133done
110134
111135# delete html
0 commit comments