diff --git a/NAMESPACE b/NAMESPACE index 3819355b..077018b4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,7 @@ export(resource) export(resource_names) export(resources) export(schema) +export(upgrade_package) export(version) export(write_package) import(rlang) diff --git a/NEWS.md b/NEWS.md index c12ae158..e9fdc4bf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ frictionless now supports Data Packages using the [v2](https://datapackage.org/) * frictionless no longer relies on v1 properties deprecated in v2, meaning all functions support both versions. They always return a package, resource and schema in the same version as provided. * `create_package()`, `add_resource()` and `create_schema()` create a v2 package, resource and schema respectively. **This can be a breaking change for some workflows!** Also note that this can lead to mixed versions (e.g. a v1 package with a v2 resource). -* `upgrade_package()` can be used to upgrade a package, its resources and verbose schemas from v1 to v2 (harmonizing mixed versions) (#357, #343, #363). +* `upgrade_package()` can be used to upgrade a package, its resources and verbose schemas from v1 to v2 (harmonizing mixed versions) (#376, #357, #343, #363). ## Changes for v2 diff --git a/R/example_package.R b/R/example_package.R index 5e38974a..a9830687 100644 --- a/R/example_package.R +++ b/R/example_package.R @@ -19,10 +19,10 @@ #' @family sample data #' @export #' @examples -#' # Version 2 (default) +#' # Load the v2 example Data Package (default) #' example_package() #' -#' # Version 1 +#' # Load the v1 example Data Package #' example_package(version = "1.0") example_package <- function(version = "2.0") { version_dir <- switch( diff --git a/R/upgrade_descriptor.R b/R/upgrade_descriptor.R index 25397542..48cf0819 100644 --- a/R/upgrade_descriptor.R +++ b/R/upgrade_descriptor.R @@ -1,6 +1,6 @@ #' Upgrade a package object from v1 to v2 #' -#' Upgrades the descriptor, not the associated resources, etc. +#' Upgrades the descriptor, not its resources, etc. #' #' @inheritParams read_resource #' @returns Upgraded `package`. @@ -22,7 +22,6 @@ upgrade_descriptor <- function(package) { ) # Set $schema to profile if URL (to custom profile) - # https://datapackage.org/standard/data-package/#dollar-schema profile <- package$profile %||% "undefined" if (is_url(profile)) { purrr::pluck(package, "$schema") <- profile @@ -38,7 +37,6 @@ upgrade_descriptor <- function(package) { package$profile <- NULL # Update contributor "role" = "value" to "roles" = ["value"] - # https://datapackage.org/overview/changelog/#packagecontributors-updated package$contributors <- purrr::modify_if( package$contributors, function(x) "role" %in% names(x), diff --git a/R/upgrade_package.R b/R/upgrade_package.R new file mode 100644 index 00000000..736a6d36 --- /dev/null +++ b/R/upgrade_package.R @@ -0,0 +1,90 @@ +#' Upgrade a Data Package to v2 +#' +#' Upgrades a Data Package, its Data Resources and Table Schemas to the +#' [v2](https://datapackage.org/) specification. +#' +#' @section Upgrade details: +#' +#' ### Data Package +#' +#' `upgrade_package()` upgrades a [v1]( +#' https://specs.frictionlessdata.io/data-package/) descriptor to [v2]( +#' https://datapackage.org/standard/data-package/) as follows: +#' +#' - Adds `$schema` as first property and sets it to the recommended v2 value +#' (`"https://datapackage.org/profiles/2.0/datapackage.json"`), except for +#' certain `profile` values. +#' - Removes `profile`, but retains its value in `$schema` if it is a URL to a +#' custom profile (see [backwards compatibility]( +#' https://datapackage.org/standard/data-package/#dollar-schema)). +#' - Converts `contributors` `"role": "value"` to `"roles": ["value"]` (see +#' [changelog]( +#' https://datapackage.org/overview/changelog/#packagecontributors-updated)). +#' +#' ### Data Resource +#' +#' `upgrade_package()` upgrades any [v1]( +#' https://specs.frictionlessdata.io/data-resource/) resource to [v2]( +#' https://datapackage.org/standard/data-resource/) as follows: +#' +#' - Adds `$schema` as first property and sets it to the recommended v2 value +#' (`"https://datapackage.org/profiles/2.0/dataresource.json"`). +#' - Removes `profile`, but converts `"profile" = "tabular-data-resource"` to +#' `"type" = "table"` (see [backwards compatibility]( +#' https://datapackage.org/standard/data-resource/#type)). +#' +#' ### Table Dialect +#' +#' `upgrade_package()` leaves the dialect as is for all resources. +#' +#' ### Table Schema +#' +#' `upgrade_package()` upgrades any verbose [v1]( +#' https://specs.frictionlessdata.io/table-schema/) schema to [v2]( +#' https://datapackage.org/standard/table-schema/) as follows: +#' +#' - Adds `$schema` as first property and sets it to the recommended v2 value +#' (`"https://datapackage.org/profiles/2.0/tableschema.json"`). +#' - Converts `primaryKey` single values to an array (see [changelog]( +#' https://datapackage.org/overview/changelog/#schemaprimarykey-updated)). +#' - Converts `foreignKeys` single values in `fields` to an array and removes +#' `reference$resource` if it is self-referential (see [changelog]( +#' https://datapackage.org/overview/changelog/#schemaforeignkeys-updated)). +#' +#' Schemas referenced by path or URL are left as is. +#' +#' @inheritParams read_resource +#' @returns Upgraded `package`. +#' @family versioning functions +#' @export +#' @examples +#' # Load the v1 example Data Package +#' (package <- example_package(version = "1.0")) +#' +#' # Upgrade +#' (package_upgraded <- upgrade_package(package)) +#' +#' # Check version of one of the resources +#' version(resource(package_upgraded, "deployments")) +upgrade_package <- function(package) { + check_package(package) + + # Upgrade descriptor + package <- upgrade_descriptor(package) + + # Upgrade resources + for (resource_name in resource_names(package)) { + resource <- upgrade_resource(resource(package, resource_name)) + + # Upgrade schema if verbosely included + schema_property <- resource$schema %||% "undefined" + if (is.list(schema_property)) { + schema <- schema(package, resource_name) + schema <- upgrade_schema(schema, resource_name) + resource$schema <- schema + } + resource(package, resource_name) <- resource + } + + return(package) +} diff --git a/R/upgrade_resource.R b/R/upgrade_resource.R index 0bb6ad31..501031b0 100644 --- a/R/upgrade_resource.R +++ b/R/upgrade_resource.R @@ -20,7 +20,6 @@ upgrade_resource <- function(resource) { ) # Set type to table if resource is tabular - # https://datapackage.org/standard/data-resource/#type profile <- resource$profile %||% "undefined" if (profile %in% c( "tabular-data-resource", diff --git a/R/upgrade_schema.R b/R/upgrade_schema.R index b7809df0..38a82f46 100644 --- a/R/upgrade_schema.R +++ b/R/upgrade_schema.R @@ -22,11 +22,9 @@ upgrade_schema <- function(schema, resource_name) { ) # Update primaryKey to array - # https://datapackage.org/overview/changelog/#schemaprimarykey-updated schema$primaryKey <- character_to_list(schema$primaryKey) # Update foreignKeys fields to array and remove self-referential resource - # https://datapackage.org/overview/changelog/#schemaforeignkeys-updated schema$foreignKeys <- purrr::modify_if( schema$foreignKeys, is.list, diff --git a/R/version.R b/R/version.R index 44972cae..20fa73ef 100644 --- a/R/version.R +++ b/R/version.R @@ -13,7 +13,7 @@ #' @param x A list describing either a Data Package, Data Resource, Table #' Dialect or Table Schema. #' @returns Data Package standard version number. -#' @family version functions +#' @family versioning functions #' @export #' @examples #' # Data Package diff --git a/R/write_package.R b/R/write_package.R index 602eb08c..fd9ee2cb 100644 --- a/R/write_package.R +++ b/R/write_package.R @@ -1,7 +1,7 @@ #' Write a Data Package to disk #' -#' Writes a Data Package and its related Data Resources to disk as a -#' `datapackage.json` and CSV files. +#' Writes a Data Package and its Data Resources to disk as a `datapackage.json` +#' and CSV files. #' #' @section Writing data to CSV files: #' diff --git a/_pkgdown.yml b/_pkgdown.yml index 963b7ca0..1e71ff3e 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -5,7 +5,9 @@ navbar: bg: dark articles: - title: Standard implementation - desc: These articles describe how frictionless implements the Data Package standard. + desc: > + These articles describe how frictionless implements the Data Package + standard. navbar: ~ contents: - data-package @@ -14,22 +16,36 @@ articles: - table-schema reference: - title: Read a Data Package - desc: Read a `datapackage.json` file and its associated Data Resources from path or URL. + desc: > + Read a `datapackage.json` file and its Data Resources from path or URL. contents: - has_concept("read functions") - title: Create and edit a Data Package - desc: Create and edit a Data Package, its associated Data Resources and Table Schemas. + desc: > + Create and edit a Data Package, its Data Resources and Table Schemas. contents: - has_concept("create functions") - has_concept("edit functions") - title: Write a Data Package - desc: Write a Data Package and its associated Data Resources to disk. + desc: > + Write a Data Package and its Data Resources to disk. contents: - has_concept("write functions") -- title: Miscellaneous +- title: Versioning + desc: > + Determine what version of the Data Package standard is used + ([v1](https://specs.frictionlessdata.io/) or [v2](https://datapackage.org/)) + and/or upgrade. frictionless uses the v2 specification when creating a + package, resource or schema. + contents: + - has_concept("versioning functions") +- title: Developing with frictionless + desc: > + Access, set and check Data Package properties. contents: - has_concept("accessor functions") - - has_concept("print functions") - has_concept("check functions") - - has_concept("version functions") +- title: Miscellaneous + contents: + - has_concept("print functions") - has_concept("sample data") diff --git a/man/example_package.Rd b/man/example_package.Rd index d37daa92..123802d5 100644 --- a/man/example_package.Rd +++ b/man/example_package.Rd @@ -33,10 +33,10 @@ specification. } } \examples{ -# Version 2 (default) +# Load the v2 example Data Package (default) example_package() -# Version 1 +# Load the v1 example Data Package example_package(version = "1.0") } \concept{sample data} diff --git a/man/upgrade_package.Rd b/man/upgrade_package.Rd new file mode 100644 index 00000000..07e5e679 --- /dev/null +++ b/man/upgrade_package.Rd @@ -0,0 +1,81 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/upgrade_package.R +\name{upgrade_package} +\alias{upgrade_package} +\title{Upgrade a Data Package to v2} +\usage{ +upgrade_package(package) +} +\arguments{ +\item{package}{Data Package object, as returned by \code{\link[=read_package]{read_package()}} or +\code{\link[=create_package]{create_package()}}.} +} +\value{ +Upgraded \code{package}. +} +\description{ +Upgrades a Data Package, its Data Resources and Table Schemas to the +\href{https://datapackage.org/}{v2} specification. +} +\section{Upgrade details}{ + +\subsection{Data Package}{ + +\code{upgrade_package()} upgrades a \href{https://specs.frictionlessdata.io/data-package/}{v1} descriptor to \href{https://datapackage.org/standard/data-package/}{v2} as follows: +\itemize{ +\item Adds \verb{$schema} as first property and sets it to the recommended v2 value +(\code{"https://datapackage.org/profiles/2.0/datapackage.json"}), except for +certain \code{profile} values. +\item Removes \code{profile}, but retains its value in \verb{$schema} if it is a URL to a +custom profile (see \href{https://datapackage.org/standard/data-package/#dollar-schema}{backwards compatibility}). +\item Converts \code{contributors} \code{"role": "value"} to \verb{"roles": ["value"]} (see +\href{https://datapackage.org/overview/changelog/#packagecontributors-updated}{changelog}). +} +} + +\subsection{Data Resource}{ + +\code{upgrade_package()} upgrades any \href{https://specs.frictionlessdata.io/data-resource/}{v1} resource to \href{https://datapackage.org/standard/data-resource/}{v2} as follows: +\itemize{ +\item Adds \verb{$schema} as first property and sets it to the recommended v2 value +(\code{"https://datapackage.org/profiles/2.0/dataresource.json"}). +\item Removes \code{profile}, but converts \code{"profile" = "tabular-data-resource"} to +\code{"type" = "table"} (see \href{https://datapackage.org/standard/data-resource/#type}{backwards compatibility}). +} +} + +\subsection{Table Dialect}{ + +\code{upgrade_package()} leaves the dialect as is for all resources. +} + +\subsection{Table Schema}{ + +\code{upgrade_package()} upgrades any verbose \href{https://specs.frictionlessdata.io/table-schema/}{v1} schema to \href{https://datapackage.org/standard/table-schema/}{v2} as follows: +\itemize{ +\item Adds \verb{$schema} as first property and sets it to the recommended v2 value +(\code{"https://datapackage.org/profiles/2.0/tableschema.json"}). +\item Converts \code{primaryKey} single values to an array (see \href{https://datapackage.org/overview/changelog/#schemaprimarykey-updated}{changelog}). +\item Converts \code{foreignKeys} single values in \code{fields} to an array and removes +\code{reference$resource} if it is self-referential (see \href{https://datapackage.org/overview/changelog/#schemaforeignkeys-updated}{changelog}). +} + +Schemas referenced by path or URL are left as is. +} +} + +\examples{ +# Load the v1 example Data Package +(package <- example_package(version = "1.0")) + +# Upgrade +(package_upgraded <- upgrade_package(package)) + +# Check version of one of the resources +version(resource(package_upgraded, "deployments")) +} +\seealso{ +Other versioning functions: +\code{\link[=version]{version()}} +} +\concept{versioning functions} diff --git a/man/version.Rd b/man/version.Rd index 6be46482..4b1290eb 100644 --- a/man/version.Rd +++ b/man/version.Rd @@ -40,4 +40,8 @@ version(resource$dialect) schema <- schema(package, "observations") version(schema) } -\concept{version functions} +\seealso{ +Other versioning functions: +\code{\link[=upgrade_package]{upgrade_package()}} +} +\concept{versioning functions} diff --git a/man/write_package.Rd b/man/write_package.Rd index 8fe051f2..3058fb63 100644 --- a/man/write_package.Rd +++ b/man/write_package.Rd @@ -19,8 +19,8 @@ before being written to disk (e.g. \code{deployments.csv.gz}).} \code{package} invisibly, as written to file. } \description{ -Writes a Data Package and its related Data Resources to disk as a -\code{datapackage.json} and CSV files. +Writes a Data Package and its Data Resources to disk as a \code{datapackage.json} +and CSV files. } \section{Writing data to CSV files}{ diff --git a/tests/testthat/test-create_package.R b/tests/testthat/test-create_package.R index 3eef51f2..c847443f 100644 --- a/tests/testthat/test-create_package.R +++ b/tests/testthat/test-create_package.R @@ -76,7 +76,7 @@ test_that("create_package() adds class 'datapackage'", { }) # Version support ---- -test_that("check_package() returns package in same version as provided", { +test_that("create_package() returns package in same version as provided", { p_v1 <- example_package(version = "1.0") p_v2 <- example_package(version = "2.0") expect_identical(version(create_package(p_v1)), "1.0") diff --git a/tests/testthat/test-upgrade_package.R b/tests/testthat/test-upgrade_package.R new file mode 100644 index 00000000..83ab7a9b --- /dev/null +++ b/tests/testthat/test-upgrade_package.R @@ -0,0 +1,78 @@ +test_that("upgrade_package() upgrades a package, its resources and schemas to + v2", { + p_v1 <- example_package(version = "1.0") + p_upgraded <- upgrade_package(p_v1) + + expect_identical(version(p_upgraded), "2.0") + expect_identical(version(resource(p_upgraded, "deployments")), "2.0") + expect_identical(version(resource(p_upgraded, "observations")), "2.0") + expect_identical(version(resource(p_upgraded, "media")), "2.0") + expect_identical(version(schema(p_upgraded, "deployments")), "2.0") + expect_identical(version(schema(p_upgraded, "observations")), "2.0") + expect_identical(version(schema(p_upgraded, "media")), "2.0") +}) + +test_that("upgrade_package() does not upgrade non-verbose schemas", { + skip_if_offline() + p_v1 <- example_package(version = "1.0") + p_v1 <- remove_resource(p_v1, "observations") + p_v1 <- remove_resource(p_v1, "media") + attr(p_v1, "directory") <- "." + + # Use a remote path, otherwise schema and path need to share same directory + p_v1$resources[[1]]$path <- file.path( + "https://raw.githubusercontent.com/frictionlessdata/frictionless-r", + "main/inst/extdata/v1/deployments.csv" + ) + + # Schema is local path + p_v1_local_schema <- p_v1 + p_v1_local_schema$resources[[1]]$schema <- + test_path("data/deployments_schema_v1.json") + expect_identical( + version(schema(upgrade_package(p_v1_local_schema), "deployments")), + "1.0" + ) + + # Schema is remote path + p_v1_remote_schema <- p_v1 + p_v1_remote_schema$resources[[1]]$schema <- file.path( + "https://raw.githubusercontent.com/frictionlessdata/frictionless-r", + "main/tests/testthat/data/deployments_schema_v1.json" + ) + expect_identical( + version(schema(upgrade_package(p_v1_remote_schema), "deployments")), + "1.0" + ) +}) + +test_that("upgrade_package() harmonizes mixed versions", { + p_v1 <- example_package(version = "1.0") + # Upgrade package, but not its resources + p_mixed <- frictionless:::upgrade_descriptor(p_v1) + # Add v2 schema to v1 resource + deployments <- read_resource(p_mixed, "deployments") + p_mixed$resources[[1]]$schema <- create_schema(deployments) + # Add v2 resource with v2 schema + df <- data.frame("col_1" = c(1, 2), "col_2" = c("a", "b")) + p_mixed <- add_resource(p_mixed, "new_df", df) + + # Package with mixed versions + expect_identical(version(p_mixed), "2.0") + expect_identical(version(resource(p_mixed, "deployments")), "1.0") + expect_identical(version(resource(p_mixed, "observations")), "1.0") + expect_identical(version(resource(p_mixed, "new_df")), "2.0") + expect_identical(version(schema(p_mixed, "deployments")), "2.0") + expect_identical(version(schema(p_mixed, "observations")), "1.0") + expect_identical(version(schema(p_mixed, "new_df")), "2.0") + + # Upgrade package has harmonized versions + p_upgraded <- upgrade_package(p_mixed) + expect_identical(version(p_upgraded), "2.0") + expect_identical(version(resource(p_upgraded, "deployments")), "2.0") + expect_identical(version(resource(p_upgraded, "observations")), "2.0") + expect_identical(version(resource(p_upgraded, "new_df")), "2.0") + expect_identical(version(schema(p_upgraded, "deployments")), "2.0") + expect_identical(version(schema(p_upgraded, "observations")), "2.0") + expect_identical(version(schema(p_upgraded, "new_df")), "2.0") +}) diff --git a/vignettes/data-package.Rmd b/vignettes/data-package.Rmd index ab13d592..c6c4ef8b 100644 --- a/vignettes/data-package.Rmd +++ b/vignettes/data-package.Rmd @@ -87,7 +87,7 @@ my_package ### Write -`write_package()` writes a package and its related resources to disk as a `datapackage.json` and CSV files. See the function documentation for details. +`write_package()` writes a package and its resources to disk as a `datapackage.json` and CSV files. See the function documentation for details. ## Properties implementation @@ -101,7 +101,7 @@ my_package ### profile -[`profile`](https://specs.frictionlessdata.io/data-package/#profile) (a deprecated v1 property) is ignored by `read_package()` and not set by `create_package()`. `upgrade_package()` removes `profile` (unless `$schema` is already set), but retains its value in `$schema` if it is a URL to a custom profile (for [backwards compatibility](https://datapackage.org/standard/data-package/#dollar-schema)). +[`profile`](https://specs.frictionlessdata.io/data-package/#profile) (a deprecated v1 property) is ignored by `read_package()` and not set by `create_package()`. `upgrade_package()` removes `profile` (unless `$schema` is already set), but retains its value in `$schema` if it is a URL to a custom profile (see [backwards compatibility](https://datapackage.org/standard/data-package/#dollar-schema)). ### resources @@ -155,7 +155,7 @@ package ### contributors -[`contributors`](https://datapackage.org/standard/data-package/#contributors) is ignored by `read_package()` and not set by `create_package()`. `upgrade_package()` converts `"role": "value"` to `"roles": ["value"]` for all contributors (for [backwards compatibility](https://datapackage.org/overview/changelog/#packagecontributors-updated)). +[`contributors`](https://datapackage.org/standard/data-package/#contributors) is ignored by `read_package()` and not set by `create_package()`. `upgrade_package()` converts `"role": "value"` to `"roles": ["value"]` for all contributors (see [changelog](https://datapackage.org/overview/changelog/#packagecontributors-updated)). ### sources diff --git a/vignettes/data-resource.Rmd b/vignettes/data-resource.Rmd index bbf5329c..6c714a81 100644 --- a/vignettes/data-resource.Rmd +++ b/vignettes/data-resource.Rmd @@ -93,7 +93,7 @@ You can pipe most functions (see `vignette("data-package")`). ### Write -`write_package()` writes a package and its related resources to disk as a `datapackage.json` and CSV files. See the function documentation for details. +`write_package()` writes a package and its resources to disk as a `datapackage.json` and CSV files. See the function documentation for details. ## Properties implementation @@ -107,7 +107,7 @@ You can pipe most functions (see `vignette("data-package")`). ### profile -[`profile`](https://specs.frictionlessdata.io/data-resource/#profile) (a deprecated v1 property) is ignored by `read_resource()` and not set by `add_resource()`. `upgrade_package()` removes `profile` (unless `$schema` is already set), but converts `"profile" = "tabular-data-resource"` to `"type" = "table"` (for [backwards compatibility](https://datapackage.org/standard/data-resource/#type)). +[`profile`](https://specs.frictionlessdata.io/data-resource/#profile) (a deprecated v1 property) is ignored by `read_resource()` and not set by `add_resource()`. `upgrade_package()` removes `profile` (unless `$schema` is already set), but converts `"profile" = "tabular-data-resource"` to `"type" = "table"` (see [backwards compatibility](https://datapackage.org/standard/data-resource/#type)). ### name diff --git a/vignettes/table-dialect.Rmd b/vignettes/table-dialect.Rmd index 9872a867..f68406da 100644 --- a/vignettes/table-dialect.Rmd +++ b/vignettes/table-dialect.Rmd @@ -52,7 +52,7 @@ frictionless does not support direct manipulation of the dialect. `add_resource( - `read_resource()` ignores it and does not upgrade a dialect, since it does not rely on v1 properties deprecated in v2. - `add_resource()` does _not_ set `$schema` to the recommended v2 value (`"https://datapackage.org/profiles/2.0/tabledialect.json"`), because it typically does not define a dialect and therefore `$schema`. It thus creates (default to) a v1 dialect. -- `upgrade_package()` leaves dialect as is for all resources. +- `upgrade_package()` leaves the dialect as is for all resources. ### header diff --git a/vignettes/table-schema.Rmd b/vignettes/table-schema.Rmd index 9b730d56..38a989e3 100644 --- a/vignettes/table-schema.Rmd +++ b/vignettes/table-schema.Rmd @@ -117,7 +117,7 @@ package <- add_resource( ### primaryKey -[`primaryKey`](https://datapackage.org/standard/table-schema/#primaryKey) is ignored by `read_resource()` and not set by `create_schema()`. `upgrade_package()` will convert single values to an array (for [backwards compatibility](https://datapackage.org/overview/changelog/#schemaprimarykey-updated)). +[`primaryKey`](https://datapackage.org/standard/table-schema/#primaryKey) is ignored by `read_resource()` and not set by `create_schema()`. `upgrade_package()` converts single values to an array (see [changelog](https://datapackage.org/overview/changelog/#schemaprimarykey-updated)). ### uniqueKeys @@ -125,7 +125,7 @@ package <- add_resource( ### foreignKeys -[`foreignKeys`](https://datapackage.org/standard/table-schema/#foreignKeys) is ignored by `read_resource()` and not set by `create_schema()`. `upgrade_package()` will convert single values in `fields` to an array and remove `reference.resource` if it is self-referential (for [backwards compatibility](https://datapackage.org/overview/changelog/#schemaprimarykey-updated)). +[`foreignKeys`](https://datapackage.org/standard/table-schema/#foreignKeys) is ignored by `read_resource()` and not set by `create_schema()`. `upgrade_package()` converts single values in `fields` to an array and removes `reference$resource` if it is self-referential (see [changelog](https://datapackage.org/overview/changelog/#schemaforeignkeys-updated)). ## Field properties implementation