Skip to content

Commit

Permalink
Implement v2 Spec JSON Schema
Browse files Browse the repository at this point in the history
Based on pgxn/rfcs#3. As with the v1 schemas, use JSON Schema v2020 for
the v2 schemas.

Fix a few minor issues with the v1 schema, as well. Add full test suite
in Rust; move code shared between the v1 and v2 tests to
`tests/common/mod.rs`. This includes custom format functions not
required for v1, including spdx version expression validation with the
`spdx` crate, and path validation to ensure no `..` is included in
paths.
  • Loading branch information
theory committed Jul 24, 2024
1 parent e32058b commit fbd591d
Show file tree
Hide file tree
Showing 48 changed files with 5,037 additions and 324 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
- id: fmt
- id: check
- id: clippy
- id: test
# - id: test

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
Expand Down
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ serde_json = "1.0"

[dependencies]
serde = { version = "1", features = ["derive"] }
spdx = "0.10.6"
6 changes: 1 addition & 5 deletions schema/v1/bugtracker.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
}
},
"anyOf": [{ "required": ["web"] }, { "required": ["mailto"] }],
"patternProperties": {
"^[xX]_.": {
"description": "Custom key"
}
},
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false,
"examples": [
{
Expand Down
6 changes: 1 addition & 5 deletions schema/v1/distribution.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@
},
"resources": { "$ref": "resources.schema.json" }
},
"patternProperties": {
"^[xX]_.": {
"description": "Custom key"
}
},
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false,
"required": [
"name",
Expand Down
6 changes: 1 addition & 5 deletions schema/v1/extension.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
}
},
"required": ["file", "version"],
"patternProperties": {
"^[xX]_.": {
"description": "Custom key"
}
},
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false,
"examples": [
{
Expand Down
1 change: 1 addition & 0 deletions schema/v1/license.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"items": { "$ref": "#/$defs/validLicense" },
"description": "A list of shortcuts to identify well-known licenses for the distribution.",
"minItems": 1,
"uniqueItems": true,
"examples": [["apache_2_0", "postgresql"], ["mit"]]
},
{
Expand Down
1 change: 1 addition & 0 deletions schema/v1/maintainer.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"type": "string",
"minLength": 1
},
"uniqueItems": true,
"minItems": 1
}
],
Expand Down
6 changes: 1 addition & 5 deletions schema/v1/meta-spec.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
}
},
"required": ["version"],
"patternProperties": {
"^[xX]_.": {
"description": "Custom key"
}
},
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false,
"examples": [
{ "version": "1.0.0" },
Expand Down
7 changes: 2 additions & 5 deletions schema/v1/no_index.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
}
},
"anyOf": [{ "required": ["file"] }, { "required": ["directory"] }],
"patternProperties": {
"^[xX]_.": {
"description": "Custom key"
}
},
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false,
"examples": [
{
Expand All @@ -33,6 +29,7 @@
{
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "string",
"description": "Relative path in unix convention to a file to ignore.",
Expand Down
6 changes: 1 addition & 5 deletions schema/v1/prereq_phase.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
"description": "These dependencies cannot be installed when the phase is in operation. This is a very rare situation, and the conflicts relationship should be used with great caution, or not at all."
}
},
"patternProperties": {
"^[xX]_.": {
"description": "Custom key"
}
},
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false,
"anyOf": [
{ "required": ["requires"] },
Expand Down
6 changes: 1 addition & 5 deletions schema/v1/prereqs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@
{ "required": ["runtime"] },
{ "required": ["develop"] }
],
"patternProperties": {
"^[xX]_.": {
"description": "Custom key"
}
},
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false,
"examples": [
{
Expand Down
6 changes: 1 addition & 5 deletions schema/v1/repository.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
}
},
"anyOf": [{ "required": ["url", "type"] }, { "required": ["web"] }],
"patternProperties": {
"^[xX]_.": {
"description": "Custom key"
}
},
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false,
"examples": [
{
Expand Down
10 changes: 3 additions & 7 deletions schema/v1/resources.schema.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://pgxn.org/meta/v1/resources.schema.json",
"title": "Source Control Repository",
"description": "An Extension is provided by a distribution.",
"title": "Resources",
"description": "Resources related to this distribution.",
"type": "object",
"properties": {
"homepage": {
Expand All @@ -13,11 +13,7 @@
"bugtracker": { "$ref": "bugtracker.schema.json" },
"repository": { "$ref": "repository.schema.json" }
},
"patternProperties": {
"^[xX]_.": {
"description": "Custom key"
}
},
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false,
"anyOf": [
{ "required": ["homepage"] },
Expand Down
1 change: 1 addition & 0 deletions schema/v1/tags.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "A list of keywords that describe the distribution.",
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"title": "Tag",
"description": "A Tag is a subtype of String that must be fewer than 256 characters long contain no slash (/), backslash (\\), or control characters.",
Expand Down
2 changes: 1 addition & 1 deletion schema/v1/version_range.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"type": "string",
"pattern": "^(([=!]=|[<>]=?)\\s*)?((0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?|0)(,\\s*((([=!]=|[<>]=?)\\s*)?)(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)*$",
"$comment": "https://regex101.com/r/Uy7XWK/1"
"$comment": "https://regex101.com/r/Uy7XWK"
},
{
"const": 0
Expand Down
62 changes: 62 additions & 0 deletions schema/v2/app.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://pgxn.org/meta/v2/app.schema.json",
"title": "App",
"description": "An App represents an applications, command-line or otherwise.",
"type": "object",
"properties": {
"lang": {
"$ref": "term.schema.json",
"description": "A short string representing the implementation language. Required for apps that need the `'#!{cmd}` shebang line modified before installing."
},
"bin": {
"$ref": "path.schema.json",
"description": "A path pointing to the app binary, which may be generated by the build process."
},
"doc": {
"$ref": "path.schema.json",
"description": "A path pointing to the documentation file for the app, which **SHOULD** be more than a README."
},
"abstract": {
"type": "string",
"description": "A short String value describing the extension.",
"minLength": 1
},
"lib": {
"$ref": "path.schema.json",
"description": "A path pointing a directory of additional files to install, such as support libraries or modules."
},
"man": {
"$ref": "path.schema.json",
"description": "A path pointing to a man page or directory of man pages created by the build process."
},
"html": {
"$ref": "path.schema.json",
"description": "A path pointing to an HTML file or directory of HTML files created by the build process."
}
},
"required": ["bin"],
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false,
"examples": [
{
"lang": "perl",
"bin": "blib/script/app",
"lib": "blib/lib",
"man": "blib/libdoc",
"html": "blib/libhtml",
"doc": "doc/app.md",
"abstract": "blah blah blah"
},
{
"lang": "python",
"bin": "bin/common/check_unique_constraint.py",
"abstract": "Check that all rows in a partition set are unique for the given columns"
},
{
"bin": "pg_top",
"man": "pg_top.1",
"abstract": "pg_top is 'top' for PostgreSQL"
}
]
}
63 changes: 63 additions & 0 deletions schema/v2/artifacts.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://pgxn.org/meta/v2/artifacts.schema.json",
"title": "Artifacts",
"description": "*Artifacts* describes non-PGXN links and checksums for downloading the distribution in one or more formats, including source code, binaries, system packages, etc. Consumers **MAY** use this information to determine the best option for installing an extension on a particular system. Useful for projects that publish their own binaries, such as in GitHub releases.",
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"url": {
"type": "string",
"format": "uri",
"description": "The URL to download the artifact."
},
"type": {
"type": "string",
"minLength": 2,
"pattern": "^[a-z0-9]{2,}$",
"description": "The type of artifact. **MUST** be a single lowercase word describing the artifact, such as none of `binary`, `source`, `rpm`, `homebrew`, etc."
},
"platform": {
"$ref": "platform.schema.json",
"description": "Identifies the platform the artifact was built for. **RECOMMENDED** for packages compiled for a specific platform, such as a C extension compiled for `linux-arm64`."
},
"sha256": {
"type": "string",
"pattern": "^[0-9a-fA-F]{64}$",
"description": "The SHA-256 checksum for the artifact in hex format."
},
"sha512": {
"type": "string",
"pattern": "^[0-9a-fA-F]{128}$",
"description": "The SHA-512 checksum for the artifact in hex format."
}
},
"anyOf": [
{ "required": ["url", "type", "sha256"] },
{ "required": ["url", "type", "sha512"] }
],
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false
},
"examples": [
[
{
"type": "source",
"url": "https://github.com/theory/pg-pair/releases/download/v1.1.0/pair-1.1.0.zip",
"sha256": "2b9d2416096d2930be51e5332b70bcd97846947777a93e4a3d65fe1b5fd7b004"
},
{
"type": "binary",
"url": "https://github.com/theory/pg-pair/releases/download/v1.1.0/pair-1.1.0-linux-amd64.tar.gz",
"sha256": "ec33656ba693c01be2b2b500c639846fb0ede7f7f8ee1f4c157bc9cab53c8500"
},
{
"type": "binary",
"url": "https://github.com/theory/pg-pair/releases/download/v1.1.0/pair-1.1.0-linux-arm64.tar.gz",
"sha512": "612ad0a8b7e292daf0c723bd0ac8029a838357b2d3abbada7cd7445f7690191abd6593a1336742e705314df81fc1c0063423f62e4abd846f350c251ef6a6a24f"
}
]
]
}
40 changes: 40 additions & 0 deletions schema/v2/badges.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://pgxn.org/meta/v2/badges.schema.json",
"title": "Badges",
"description": "*Badges* represents links to a [Shields](https://github.com/badges/shields/blob/master/spec/SPECIFICATION.md \"Shields badge specification\")-conformant badges.",
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"src": {
"type": "string",
"format": "uri",
"description": "The URI for the badge."
},
"alt": {
"type": "string",
"minLength": 4,
"maxLength": 4048,
"description": "Alternate text for accessability."
},
"url": {
"type": "string",
"format": "uri",
"description": "The URL the badge links to."
}
},
"required": ["src", "alt"],
"patternProperties": { "^[xX]_.": { "description": "Custom key" } },
"additionalProperties": false
},
"examples": [
[
{
"alt": "Test Status",
"src": "https://test.packages.postgresql.org/github.com/example/pair.svg"
}
]
]
}
Loading

0 comments on commit fbd591d

Please sign in to comment.