-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from AVSystem/adt-metadata
ADT metadata & OpenAPI generation for REST
- Loading branch information
Showing
68 changed files
with
4,426 additions
and
1,321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
commons-akka/src/main/scala/com/avsystem/commons/rpc/akka/MonixRPCFramework.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...otations/src/main/scala/com/avsystem/commons/annotation/NotInheritedFromSealedTypes.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.avsystem.commons | ||
package annotation | ||
|
||
import scala.annotation.StaticAnnotation | ||
|
||
/** | ||
* Marker trait for annotations which don't want to be inherited by subtypes | ||
* of a sealed trait or class that has this annotation applied. Intended for annotations that should apply | ||
* only to the sealed trait itself. | ||
*/ | ||
trait NotInheritedFromSealedTypes extends StaticAnnotation |
16 changes: 16 additions & 0 deletions
16
commons-annotations/src/main/scala/com/avsystem/commons/annotation/positioned.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.avsystem.commons | ||
package annotation | ||
|
||
import scala.annotation.StaticAnnotation | ||
|
||
/** | ||
* Annotate a symbol (i.e. class, method, parameter, etc.) with `@positioned(positioned.here)` to retain source | ||
* position information for that symbol to be available in macro implementations which inspect that symbol. | ||
* This is necessary e.g. for determining declaration order of subtypes of sealed hierarchies in macro implementations. | ||
* This annotation is only needed when macro is invoked in a different source file than the source file of inspected | ||
* symbol. If macro is invoked in the same file, source position is always available. | ||
*/ | ||
class positioned(val point: Int) extends StaticAnnotation | ||
object positioned { | ||
def here: Int = macro macros.misc.MiscMacros.posPoint | ||
} |
261 changes: 261 additions & 0 deletions
261
commons-annotations/src/main/scala/com/avsystem/commons/meta/metaAnnotations.scala
Large diffs are not rendered by default.
Oops, something went wrong.
273 changes: 27 additions & 246 deletions
273
commons-annotations/src/main/scala/com/avsystem/commons/rpc/rpcAnnotations.scala
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
commons-core/src/main/scala/com/avsystem/commons/meta/AdtMetadataCompanion.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.avsystem.commons | ||
package meta | ||
|
||
import com.avsystem.commons.macros.meta.AdtMetadataMacros | ||
import com.avsystem.commons.misc.MacroGenerated | ||
|
||
trait AdtMetadataCompanion[M[_]] extends MetadataCompanion[M] { | ||
def materialize[T]: M[T] = macro AdtMetadataMacros.materialize[T] | ||
|
||
implicit def materializeMacroGenerated[T]: MacroGenerated[M[T]] = macro AdtMetadataMacros.materializeMacroGenerated[T] | ||
} |
44 changes: 26 additions & 18 deletions
44
...om/avsystem/commons/rpc/NamedParams.scala → ...a/com/avsystem/commons/meta/Mapping.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,63 @@ | ||
package com.avsystem.commons | ||
package rpc | ||
package meta | ||
|
||
import com.avsystem.commons.rpc.NamedParams.ConcatIterable | ||
import com.avsystem.commons.meta.Mapping.ConcatIterable | ||
import com.avsystem.commons.serialization.GenCodec | ||
|
||
import scala.collection.generic.CanBuildFrom | ||
import scala.collection.mutable | ||
|
||
/** | ||
* Simple immutable structure to collect named RPC parameters while retaining their order and | ||
* providing fast, hashed lookup by parameter name when necessary. | ||
* Simple immutable structure to collect named values while retaining their order and | ||
* providing fast, hashed lookup by name when necessary. | ||
* Intended to be used for [[multi]] raw parameters. | ||
*/ | ||
final class NamedParams[+V](private val wrapped: IIterable[(String, V)]) | ||
final class Mapping[+V](private val wrapped: IIterable[(String, V)]) | ||
extends IIterable[(String, V)] with PartialFunction[String, V] { | ||
|
||
private[this] lazy val hashMap = new MLinkedHashMap[String, V].setup(_ ++= wrapped) | ||
|
||
def iterator: Iterator[(String, V)] = | ||
hashMap.iterator | ||
def valuesIterator: Iterator[V] = | ||
hashMap.valuesIterator | ||
def keys: Iterable[String] = | ||
hashMap.keys | ||
def contains(key: String): Boolean = | ||
hashMap.contains(key) | ||
def isDefinedAt(key: String): Boolean = | ||
hashMap.isDefinedAt(key) | ||
override def applyOrElse[A1 <: String, B1 >: V](key: A1, default: A1 => B1): B1 = | ||
hashMap.applyOrElse(key, default) | ||
override def apply(key: String): V = | ||
hashMap.apply(key) | ||
def get(key: String): Opt[V] = | ||
hashMap.getOpt(key) | ||
|
||
def ++[V0 >: V](other: NamedParams[V0]): NamedParams[V0] = | ||
def ++[V0 >: V](other: Mapping[V0]): Mapping[V0] = | ||
if (wrapped.isEmpty) other | ||
else if (other.wrapped.isEmpty) this | ||
else new NamedParams(ConcatIterable(wrapped, other.wrapped)) | ||
else new Mapping(ConcatIterable(wrapped, other.wrapped)) | ||
} | ||
object NamedParams { | ||
def empty[V]: NamedParams[V] = new NamedParams(Nil) | ||
def newBuilder[V]: mutable.Builder[(String, V), NamedParams[V]] = | ||
new MListBuffer[(String, V)].mapResult(new NamedParams(_)) | ||
object Mapping { | ||
def empty[V]: Mapping[V] = new Mapping(Nil) | ||
def newBuilder[V]: mutable.Builder[(String, V), Mapping[V]] = | ||
new MListBuffer[(String, V)].mapResult(new Mapping(_)) | ||
|
||
private case class ConcatIterable[+V](first: IIterable[V], second: IIterable[V]) extends IIterable[V] { | ||
def iterator: Iterator[V] = first.iterator ++ second.iterator | ||
} | ||
|
||
private val reusableCBF = new CanBuildFrom[Nothing, (String, Any), NamedParams[Any]] { | ||
def apply(from: Nothing): mutable.Builder[(String, Any), NamedParams[Any]] = newBuilder[Any] | ||
def apply(): mutable.Builder[(String, Any), NamedParams[Any]] = newBuilder[Any] | ||
private val reusableCBF = new CanBuildFrom[Nothing, (String, Any), Mapping[Any]] { | ||
def apply(from: Nothing): mutable.Builder[(String, Any), Mapping[Any]] = newBuilder[Any] | ||
def apply(): mutable.Builder[(String, Any), Mapping[Any]] = newBuilder[Any] | ||
} | ||
|
||
implicit def canBuildFrom[V]: CanBuildFrom[Nothing, (String, V), NamedParams[V]] = | ||
reusableCBF.asInstanceOf[CanBuildFrom[Nothing, (String, V), NamedParams[V]]] | ||
implicit def canBuildFrom[V]: CanBuildFrom[Nothing, (String, V), Mapping[V]] = | ||
reusableCBF.asInstanceOf[CanBuildFrom[Nothing, (String, V), Mapping[V]]] | ||
|
||
implicit def genCodec[V: GenCodec]: GenCodec[NamedParams[V]] = GenCodec.createNullableObject( | ||
oi => new NamedParams(oi.iterator(GenCodec.read[V]).toList), | ||
implicit def genCodec[V: GenCodec]: GenCodec[Mapping[V]] = GenCodec.createNullableObject( | ||
oi => new Mapping(oi.iterator(GenCodec.read[V]).toList), | ||
(oo, np) => np.foreach({ case (k, v) => GenCodec.write[V](oo.writeField(k), v) }) | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
commons-core/src/main/scala/com/avsystem/commons/meta/MetadataCompanion.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.avsystem.commons | ||
package meta | ||
|
||
import com.avsystem.commons.macros.misc.MiscMacros | ||
import com.avsystem.commons.rpc.Fallback | ||
|
||
trait MetadataCompanion[M[_]] { | ||
final def apply[Real](implicit metadata: M[Real]): M[Real] = metadata | ||
|
||
implicit final def fromFallback[Real](implicit fallback: Fallback[M[Real]]): M[Real] = fallback.value | ||
|
||
final class Lazy[Real](metadata: => M[Real]) { | ||
lazy val value: M[Real] = metadata | ||
} | ||
object Lazy { | ||
def apply[Real](metadata: => M[Real]): Lazy[Real] = new Lazy(metadata) | ||
|
||
// macro effectively turns `metadata` param into by-name param (implicit params by themselves cannot be by-name) | ||
implicit def lazyMetadata[Real](implicit metadata: M[Real]): Lazy[Real] = macro MiscMacros.lazyMetadata | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...com/avsystem/commons/rpc/OptionLike.scala → ...om/avsystem/commons/meta/OptionLike.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.avsystem.commons | ||
package rpc | ||
package meta | ||
|
||
sealed trait OptionLike[O] { | ||
type Value | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
commons-core/src/main/scala/com/avsystem/commons/misc/ValueOf.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.avsystem.commons | ||
package misc | ||
|
||
import com.avsystem.commons.macros.misc.MiscMacros | ||
|
||
class ValueOf[T](val value: T) extends AnyVal | ||
object ValueOf { | ||
def apply[T](implicit vof: ValueOf[T]): T = vof.value | ||
|
||
implicit def mkValueOf[T]: ValueOf[T] = macro MiscMacros.mkValueOf[T] | ||
} |
Oops, something went wrong.