Skip to content

Commit

Permalink
FacadeGeneratorPlugin: skip props of type "unsupportedProp"
Browse files Browse the repository at this point in the history
  • Loading branch information
nafg committed Jun 15, 2020
1 parent a2a265a commit 28c528a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 35 deletions.
37 changes: 19 additions & 18 deletions project/PropInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,26 @@ object PropInfo {
obj
.toSeq
.sortBy(_._1)
.map { case (name, spec) =>
val ident =
if (name == "type" || name.contains('-'))
"`" + name + "`"
else
name
.flatMap { case (name, spec) =>
PropType.read(spec("type").obj)
.map { propType =>
val ident =
if (name == "type" || name.contains('-'))
"`" + name + "`"
else
name

val propType = PropType.read(spec("type").obj)
val (imports, propTypeCode) = PropType.importsAndCode(propType)

val (imports, propTypeCode) = PropType.importsAndCode(propType)

PropInfo(
name = name,
ident = ident,
description = spec("description").str,
required = spec("required").bool,
propType = propType,
propTypeCode = propTypeCode,
imports = imports
)
PropInfo(
name = name,
ident = ident,
description = spec("description").str,
required = spec("required").bool,
propType = propType,
propTypeCode = propTypeCode,
imports = imports
)
}
}
}
41 changes: 24 additions & 17 deletions project/PropType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,34 @@ object PropType {
case class ArrayOf(param: PropType) extends PropType
case class Union(types: Seq[PropType]) extends PropType

def read(obj: scala.collection.Map[String, ujson.Value]): PropType = obj("name").str match {
case "any" => Any
case "array" => ArrayOf(Any)
case "bool" => Bool
case "element" => Element
case "elementType" => ElementType
case "func" => Func
case "node" => Node
case "number" => Number
case "shape" | "custom" | "instanceOf" | "object" => Object
case "string" => String
case "arrayOf" => ArrayOf(read(obj("value").obj))
case "union" => Union(obj("value").arr.map(o => read(o.obj)))
case "enum" =>
def read(obj: scala.collection.Map[String, ujson.Value]): Option[PropType] = obj("name").str match {
case "any" => Some(Any)
case "array" => Some(ArrayOf(Any))
case "bool" => Some(Bool)
case "element" => Some(Element)
case "elementType" => Some(ElementType)
case "func" => Some(Func)
case "node" => Some(Node)
case "number" => Some(Number)
case "string" => Some(String)
case "arrayOf" => read(obj("value").obj).map(ArrayOf)
case "shape" | "instanceOf" | "object" => Some(Object)
case "custom" =>
if (obj.get("raw").flatMap(_.strOpt).contains("unsupportedProp"))
None
else
Some(Object)
case "union" =>
Some(Union(obj("value").arr.flatMap(o => read(o.obj))))
.filter(_.types.nonEmpty)
case "enum" =>
val values = obj("value").arr.map(_.obj("value").str)
if (values.forall(_.matches("\\d+")))
Number
Some(Number)
else if (values.forall(s => s.matches("'.*'") | s.matches("\".*\"")))
String
Some(String)
else
Any
Some(Any)
}

def importsAndCode(propType: PropType): (Set[String], String) = {
Expand Down

0 comments on commit 28c528a

Please sign in to comment.