Skip to content

Commit

Permalink
Improvements to Dart generation
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Aug 11, 2024
1 parent 03b351b commit ead1845
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,18 @@ object OpenAPIDartGenerator extends OpenAPIGenerator {
component.properties.map {
case (key, schema) =>
val `type` = schema match {
case c: OpenAPISchema.Component if c.`type` == "array" => c.`type` // TODO: Support
case c: OpenAPISchema.Component if c.`type` == "array" => c.items.get match {
case r: OpenAPISchema.Ref =>
val c = r.ref.substring(r.ref.lastIndexOf('/') + 1)
imports += c
val s = s"List<$c>"
if (r.nullable.contains(true)) {
s"$s?"
} else {
s
}
case s => throw new UnsupportedOperationException(s"Unsupported array schema: $s")
}
case c: OpenAPISchema.Component if c.nullable.contains(true) => s"${c.`type`.dartType}?"
case c: OpenAPISchema.Component => c.`type`.dartType
case r: OpenAPISchema.Ref =>
Expand All @@ -100,6 +111,7 @@ object OpenAPIDartGenerator extends OpenAPIGenerator {
} else {
c
}
case s => throw new RuntimeException(s"Unsupported schema: $s")
}
val k = key match {
case "_id" => "id"
Expand Down Expand Up @@ -174,7 +186,7 @@ object OpenAPIDartGenerator extends OpenAPIGenerator {
}
imports = imports + parentName.type2File
addParent(parentName)
field(s"List<$parentName>", fieldName, nullable.getOrElse(false))
field(s"List<$parentName>", fieldName, schema.nullable.getOrElse(false))
case _ => throw new UnsupportedOperationException(s"Unsupported array schema for items: ${schema.items}")
}
case (fieldName, schema: OpenAPISchema.Component) if schema.`type` != "object" =>
Expand All @@ -201,6 +213,7 @@ object OpenAPIDartGenerator extends OpenAPIGenerator {
val refType = r.ref.ref2Type
imports = imports + refType.type2File
val nullable = valueSchema.nullable.getOrElse(false)
scribe.info(s"4: $refType, $nullable")
s"List<$refType>${if (nullable) "?" else ""}"
case s => throw new UnsupportedOperationException(s"Unsupported item schema: $s")
}
Expand Down

0 comments on commit ead1845

Please sign in to comment.