Skip to content

Commit fccd54b

Browse files
committed
Improve Scaladocs (close #48)
1 parent 8b5072b commit fccd54b

File tree

21 files changed

+339
-209
lines changed

21 files changed

+339
-209
lines changed

iglu-core-circe/src/main/scala/com.snowplowanalytics.iglu.core.circe/CirceIgluCodecs.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import io.circe.syntax._
1919
import com.snowplowanalytics.iglu.core._
2020

2121
/**
22-
* Example of Circe codecs for Iglu entities
22+
* Circe codecs for Iglu entities,
23+
* such as self-describing schema and self-describing data.
2324
*/
2425
trait CirceIgluCodecs {
2526

iglu-core-json4s/src/main/scala/com.snowplowanalytics.iglu.core.json4s/Json4sIgluCodecs.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ import org.json4s._
1717
import org.json4s.JsonDSL._
1818

1919
/**
20-
* Example of serializers for JSON Schema
20+
* Json4s serializers for Iglu entities,
21+
* such as self-describing schema and self-describing data.
2122
*/
2223
object Json4sIgluCodecs {
2324

24-
// Public formats. Import it
25+
// Public formats. Import it.
2526
lazy val formats: Formats = schemaFormats + SchemaSerializer + DataSerializer
2627

2728
// Local formats
2829
implicit private val schemaFormats: Formats = DefaultFormats + SchemaVerSerializer
2930

3031
/**
31-
* Extract SchemaVer (*-*-*) from JValue
32+
* Extract `SchemaVer` (*-*-*) from `JValue`.
3233
*/
3334
object SchemaVerSerializer
3435
extends CustomSerializer[SchemaVer.Full](
@@ -48,7 +49,8 @@ object Json4sIgluCodecs {
4849
)
4950

5051
/**
51-
* Extract `SchemaKey` from `self` key and remaining as Schema body
52+
* Extract `SchemaKey` from the "self" property of a
53+
* self-describing schema, and the remaining properties as schema body.
5254
*/
5355
object SchemaSerializer
5456
extends CustomSerializer[SelfDescribingSchema[JValue]](
@@ -71,7 +73,8 @@ object Json4sIgluCodecs {
7173
)
7274

7375
/**
74-
* Extract `SchemaKey` from string and data from data key
76+
* Extract `SchemaKey` from the "schema" property,
77+
* and data from the "data" property.
7578
*/
7679
object DataSerializer
7780
extends CustomSerializer[SelfDescribingData[JValue]](

src/main/scala/com.snowplowanalytics.iglu/core/ParseError.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
*/
1313
package com.snowplowanalytics.iglu.core
1414

15-
/** Common error type for parsing core Iglu entities */
15+
/** A common error type for failures when parsing core Iglu entities,
16+
* such as self-describing schema and self-describing data.
17+
*/
1618
sealed trait ParseError extends Product with Serializable {
1719
def code: String
1820
def message(str: String): String
@@ -98,12 +100,12 @@ object ParseError {
98100
/**
99101
* The metaschema URI appears to be invalid.
100102
*
101-
* A valid Iglu schema must make use of the "$schema" keyword
103+
* A valid Iglu schema must make use of the \$schema keyword
102104
* to declare that it conforms to the 'com.snowplowanalytics.self-desc/schema'
103105
* metaschema.
104106
*
105107
* The valid format is:
106-
* {{{"$schema" : "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#"}}}.
108+
* {{{"\$schema" : "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#"}}}.
107109
*
108110
* It's likely this declaration is missing or malformed.
109111
*/
@@ -117,7 +119,7 @@ object ParseError {
117119
_.code == string
118120
}
119121

120-
/** List parse function to get an entity that failed parsing */
122+
/** Add an input that failed parsing to the error. */
121123
def liftParse[A, B](parser: A => Either[ParseError, B]): A => Either[(ParseError, A), B] =
122124
a => parser(a).left.map(e => (e, a))
123125
}

src/main/scala/com.snowplowanalytics.iglu/core/PartialSchemaKey.scala

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ package com.snowplowanalytics.iglu.core
1515
import scala.util.matching.Regex
1616

1717
/**
18-
* Entity describing schema of data, which **can** be unknown,
19-
* by known or unknown `SchemaVer`. Extracted from `schema` key.
18+
* Contains details about the schema of a piece of self-describing data.
19+
*
20+
* Unlike [[SchemaKey]], the schema version may not be fully known.
2021
*/
2122
final case class PartialSchemaKey(
2223
vendor: String,
@@ -25,15 +26,11 @@ final case class PartialSchemaKey(
2526
version: SchemaVer
2627
) {
2728

28-
/**
29-
* Converts the SchemaKey back to an Iglu-format schema URI
30-
*
31-
* @return the SchemaKey as a Iglu-format schema URI
32-
*/
29+
/** Convert this [[PartialSchemaKey]] to an Iglu schema URI. */
3330
def toSchemaUri: String =
3431
s"iglu:$vendor/$name/$format/${version.asString}"
3532

36-
/** Transform to fully known `SchemaKey` */
33+
/** Convert this [[PartialSchemaKey]] to a fully-known [[SchemaKey]]. */
3734
def toSchemaKey: Option[SchemaKey] =
3835
version match {
3936
case full: SchemaVer.Full =>
@@ -42,9 +39,10 @@ final case class PartialSchemaKey(
4239
}
4340
}
4441

42+
/** Companion object, which contains a custom constructor for [[PartialSchemaKey]]. */
4543
object PartialSchemaKey {
4644

47-
/** Canonical regular expression for SchemaKey */
45+
/** Canonical regular expression for a [[PartialSchemaKey]]. */
4846
val schemaUriRegex: Regex = ("^iglu:" + // Protocol
4947
"([a-zA-Z0-9-_.]+)/" + // Vendor
5048
"([a-zA-Z0-9-_]+)/" + // Name
@@ -54,14 +52,15 @@ object PartialSchemaKey {
5452
"((?:0|[1-9][0-9]*)|\\?)").r // ADDITION
5553

5654
/**
57-
* Custom constructor for an Iglu partial SchemaKey from
58-
* an Iglu-format schema URI, which looks like:
59-
* iglu:com.snowplowanalytics.snowplow/mobile_context/jsonschema/1-0-0 for full or
60-
* iglu:com.snowplowanalytics.snowplow/mobile_context/jsonschema/1-?-? for partial
61-
* Default for Schema reference
55+
* A custom constructor for a [[PartialSchemaKey]] from
56+
* an Iglu schema URI, which looks like:
57+
* "iglu:com.vendor/schema_name/jsonschema/1-0-0" for a fully known version or
58+
* "iglu:com.vendor/schema_name/jsonschema/1-?-?" for a partially known version.
59+
*
60+
* An Iglu schema URI is the default for schema lookup.
6261
*
63-
* @param schemaUri an Iglu-format Schema URI
64-
* @return some (possibly partial) schema key if `schemaUri` was valid
62+
* @param schemaUri An Iglu schema URI.
63+
* @return A [[PartialSchemaKey]] or an error.
6564
*/
6665
def fromUri(schemaUri: String): Either[ParseError, PartialSchemaKey] = schemaUri match {
6766
case schemaUriRegex(vnd, n, f, m, r, a) =>

src/main/scala/com.snowplowanalytics.iglu/core/Resolver.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@
1313
package com.snowplowanalytics.iglu.core
1414

1515
/**
16-
* Entity allowing to fetch and validate schemas for entities of `A`
17-
* Resolvers supposed to be implemented as separate artifacts
16+
* A [[Resolver]] allows fetching and validating self-describing schemas
17+
* for entities of type `A`.
1818
*
19-
* @tparam F effect, wrapping resolver's work (such as `Either[String, Option[A]]` or `IO[A]`
20-
* @tparam A AST for data and schema
19+
* Resolvers are meant to be implemented as separate artifacts.
20+
*
21+
* @tparam F An effect wrapping the [[Resolver]]'s work,
22+
* such as `Either[String, Option[A]]` or `IO[A]`.
23+
* @tparam A An AST for data or schema.
2124
*/
2225
trait Resolver[F[_], A] {
2326

24-
/** Lookup for a schema by its key */
27+
/** Look up a schema by its key. */
2528
def lookup(data: SchemaKey): F[SelfDescribingSchema[A]]
2629

27-
/** Validate self-describing data against some schema */
30+
/** Validate a piece of self-describing data against a schema. */
2831
def validate(
2932
data: SelfDescribingData[A],
3033
schema: SelfDescribingSchema[A]

src/main/scala/com.snowplowanalytics.iglu/core/SchemaCriterion.scala

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ package core
1515

1616
import typeclasses.ExtractSchemaKey
1717

18-
/**
19-
* Class to filter Schemas by [[SchemaKey]]
20-
*/
18+
/** Filter self-describing schemas by [[SchemaKey]]. */
2119
final case class SchemaCriterion(
2220
vendor: String,
2321
name: String,
@@ -28,33 +26,34 @@ final case class SchemaCriterion(
2826
) {
2927

3028
/**
31-
* Whether a SchemaKey is valid.
29+
* Check if a [[SchemaKey]] is valid.
3230
*
3331
* It's valid if the vendor, name, format, and model all match
34-
* and the supplied key's revision and addition do not exceed the
35-
* criterion's revision and addition.
32+
* and the supplied key's REVISION and ADDITION do not exceed the
33+
* criterion's REVISION and ADDITION.
3634
*
37-
* @param key The SchemaKey to validate
38-
* @return whether the SchemaKey is valid
35+
* @param key The [[SchemaKey]] to validate.
36+
* @return `true` if the [[SchemaKey]] is valid.
3937
*/
4038
def matches(key: SchemaKey): Boolean =
4139
prefixMatches(key) && verMatch(key.version)
4240

4341
/**
44-
* Filter sequence of entities by this [[SchemaCriterion]]
45-
* It can be applied for getting only right JSON instances
46-
* out of array with custom context
42+
* Filter a sequence of entities by this [[SchemaCriterion]].
43+
*
44+
* Can be used for getting only the `Right` JSON instances
45+
* out of an array of custom contexts.
4746
*
4847
* Usage:
4948
* {{{
50-
* // This will get best matching entity
49+
* // This will get the best match for an entity
5150
* criterion.takeFrom(_.schema)(entities).sort.getOption
5251
* }}}
5352
*
54-
* @param entities list of Self-describing instances (or Schemas)
55-
* @tparam E type of Self-describing entity, having
56-
* an `ExtractSchemaKey` instance in scope
57-
* @return list of matching entities
53+
* @param entities A list of self-describing data blobs.
54+
* @tparam E The base type of the self-describing data, having
55+
* an `ExtractSchemaKey` instance in scope.
56+
* @return A list of matching entities.
5857
*/
5958
def pickFrom[E: ExtractSchemaKey](entities: Seq[E]): Seq[E] =
6059
entities.foldLeft(Seq.empty[E]) { (acc, cur) =>
@@ -65,46 +64,45 @@ final case class SchemaCriterion(
6564
}
6665

6766
/**
68-
* Format as a schema URI, but the revision and addition
69-
* may be replaced with "*" wildcards.
67+
* Format this [[SchemaCriterion]] as an Iglu schema URI,
68+
* whereby the REVISION and ADDITION may be replaced with
69+
* "*" wildcards.
7070
*
71-
* @return the String representation of this criterion
71+
* @return The string representation of this criterion.
7272
*/
7373
def asString: String =
7474
s"iglu:$vendor/$name/$format/$versionString"
7575

76-
/**
77-
* Stringify version part of criterion
78-
*/
76+
/** Stringify the version of this [[SchemaCriterion]]. */
7977
def versionString: String =
8078
"%s-%s-%s".format(model.getOrElse("*"), revision.getOrElse("*"), addition.getOrElse("*"))
8179

8280
/**
83-
* Whether the vendor, name, and format are all correct.
81+
* Check if the vendor, name, and format are all valid.
8482
*
85-
* @param key The SchemaKey to validate
86-
* @return whether the first three fields are correct
83+
* @param key The [[SchemaKey]] to validate.
84+
* @return `true` if the first three fields are correct.
8785
*/
8886
private def prefixMatches(key: SchemaKey): Boolean =
8987
key.vendor == vendor && key.name == name && key.format == format
9088

9189
/**
92-
* Match only [[SchemaVer]]
90+
* Match only [[SchemaVer]].
9391
*
94-
* @param ver SchemaVer of some other [[SchemaKey]]
95-
* @return true if all specified groups matched
92+
* @param ver A [[SchemaVer]] of some other [[SchemaKey]].
93+
* @return `true` if all specified groups match.
9694
*/
9795
private[this] def verMatch(ver: SchemaVer): Boolean =
9896
groupMatch(ver.getModel, model) &&
9997
groupMatch(ver.getRevision, revision) &&
10098
groupMatch(ver.getAddition, addition)
10199

102100
/**
103-
* Helper function for [[verMatch]]. Compares two numbers for same group
101+
* Helper function for `verMatch`. Compares two numbers for the same group.
104102
*
105-
* @param other Schema's SchemaVer group (MODEL, REVISION, ADDITION)
106-
* @param crit this Criterion's corresponding group
107-
* @return true if groups match or criterion not specific about it
103+
* @param other The other schema's [[SchemaVer]] group (MODEL, REVISION, ADDITION).
104+
* @param crit This [[SchemaCriterion]]'s corresponding group.
105+
* @return `true` if the groups match or if either entities are unknown.
108106
*/
109107
private[this] def groupMatch(other: Option[Int], crit: Option[Int]): Boolean = crit match {
110108
case Some(c) if other == Some(c) => true
@@ -114,14 +112,10 @@ final case class SchemaCriterion(
114112
}
115113
}
116114

117-
/**
118-
* Companion object containing alternative constructor for a [[SchemaCriterion]]
119-
*/
115+
/** Companion object, which contains custom constructors for [[SchemaCriterion]]. */
120116
object SchemaCriterion {
121117

122-
/**
123-
* Canonical regex to extract Schema criterion
124-
*/
118+
/** Canonical regular expression to extract [[SchemaCriterion]]. */
125119
val criterionRegex = ("^iglu:" + // Protocol
126120
"([a-zA-Z0-9-_.]+)/" + // Vendor
127121
"([a-zA-Z0-9-_]+)/" + // Name
@@ -131,11 +125,14 @@ object SchemaCriterion {
131125
"((?:0|[1-9][0-9]*)|\\*)$").r // ADDITION
132126

133127
/**
134-
* Custom constructor for an SchemaCriterion from a string, like
135-
* iglu:com.snowplowanalytics.snowplow/mobile_context/jsonschema/1-*-*
128+
* A custom constructor for a [[SchemaCriterion]] from
129+
* a string like:
130+
* "iglu:com.vendor/schema_name/jsonschema/1-*-*".
131+
*
132+
* An Iglu schema URI is the default for schema lookup.
136133
*
137-
* @param criterion string supposed to be criterion
138-
* @return criterion object if string satisfies a format
134+
* @param criterion The string to convert to a [[SchemaCriterion]].
135+
* @return A [[SchemaCriterion]] if the string satisfies the format.
139136
*/
140137
def parse(criterion: String): Option[SchemaCriterion] =
141138
criterion match {
@@ -145,9 +142,9 @@ object SchemaCriterion {
145142
}
146143

147144
/**
148-
* Constructs an exhaustive SchemaCriterion.
145+
* Constructs a comprehensive [[SchemaCriterion]].
149146
*
150-
* @return our constructed SchemaCriterion
147+
* @return the constructed [[SchemaCriterion]].
151148
*/
152149
def apply(
153150
vendor: String,
@@ -160,10 +157,10 @@ object SchemaCriterion {
160157
SchemaCriterion(vendor, name, format, Some(model), Some(revision), Some(addition))
161158

162159
/**
163-
* Constructs a SchemaCriterion from everything
164-
* except the addition.
160+
* Constructs a [[SchemaCriterion]] with everything
161+
* except ADDITION.
165162
*
166-
* @return our constructed SchemaCriterion
163+
* @return the constructed [[SchemaCriterion]].
167164
*/
168165
def apply(
169166
vendor: String,
@@ -175,18 +172,17 @@ object SchemaCriterion {
175172
SchemaCriterion(vendor, name, format, Some(model), Some(revision))
176173

177174
/**
178-
* Constructs a SchemaCriterion which is agnostic
179-
* of addition and revision.
180-
* Restricts to model only.
175+
* Constructs a [[SchemaCriterion]], which is agnostic
176+
* about REVISION and ADDITION (restricted to MODEL only).
181177
*
182-
* @return our constructed SchemaCriterion
178+
* @return the constructed [[SchemaCriterion]].
183179
*/
184180
def apply(vendor: String, name: String, format: String, model: Int): SchemaCriterion =
185181
SchemaCriterion(vendor, name, format, Some(model), None, None)
186182

187183
/**
188-
* Try to parse string number
189-
* Helper method for [[parse]]
184+
* Try to parse a string as a number.
185+
* Helper method for [[parse]].
190186
*/
191187
private def parseInt(number: String): Option[Int] =
192188
try {

0 commit comments

Comments
 (0)