Skip to content

Commit

Permalink
Add schema for Antsibull changelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Dec 13, 2022
1 parent 6fd2268 commit cb1612f
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 0 deletions.
98 changes: 98 additions & 0 deletions src/ansiblelint/schemas/changelog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"$defs": {
"release": {
"additionalProperties": false,
"properties": {
"changes": {
"additionalProperties": false,
"properties": {
"bugfixes": {
"items": {
"type": "string"
},
"type": "array"
},
"deprecated_features": {
"items": {
"type": "string"
},
"type": "array"
},
"minor_changes": {
"items": {
"type": "string"
},
"type": "array"
},
"release_summary": {
"type": "string"
}
},
"type": "object"
},
"codename": {
"type": "string"
},
"modules": {
"items": {
"properties": {
"description": {
"markdownDescription": "Value of `short_description from plugin `DOCUMENTATION`.",
"title": "Description",
"type": "string"
},
"name": {
"markdownDescription": " It must not be the FQCN, but the name inside the collection.",
"pattern": "[a-zA-Z0-9_]+",
"title": "Short module name",
"type": "string"
},
"namespace": {
"markdownDescription": "Must be `null` for plugin and objects. For modules it must be either empty string. The namespace is used to group new modules by their namespace inside the collection.",
"title": "Namespace",
"type": ["string", "null"]
}
},
"type": "object"
},
"type": "array"
},
"release_date": {
"format": "date",
"markdownDescription": "Use ISO-8601 date format, like 2020-12-31",
"pattern": "\\d\\d\\d\\d-\\d\\d-\\d\\d",
"title": "Date of the release.",
"type": "string"
}
},
"type": "object"
},
"semver": {
"pattern": "\\d+.\\d+.\\d+.*",
"title": "Version string following SemVer specification.",
"type": "string"
}
},
"$id": "https://raw.githubusercontent.com/ansible-lint/main/src/ansiblelint/schemas/changelog.json",
"$schema": "http://json-schema.org/draft-07/schema",
"additionalProperties": false,
"description": "Antsibull Changelog Schema",
"examples": ["changelog.yml"],
"markdownDescription": "See [Changelog YAML Format](https://github.com/ansible-community/antsibull-changelog/blob/main/docs/changelog.yaml-format.md)",
"properties": {
"ancestor": {
"$ref": "#/$defs/semver"
},
"releases": {
"patternProperties": {
"\\d+.\\d+.\\d+.*": {
"$ref": "#/$defs/release",
"type": "object"
}
},
"type": "object"
}
},
"title": "Antsibull Changelog Schema",
"type": "object"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
releases:
1.0.0:
release_date: 01-01-2020 # invalid date format, must be ISO-8601 !
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ajv errors

```json
[
{
"instancePath": "/releases/1.0.0/release_date",
"keyword": "pattern",
"message": "must match pattern \"\\d\\d\\d\\d-\\d\\d-\\d\\d\"",
"params": {
"pattern": "\\d\\d\\d\\d-\\d\\d-\\d\\d"
},
"schemaPath": "#/$defs/release/properties/release_date/pattern"
}
]
```

# check-jsonschema

stdout:

```json
{
"status": "fail",
"errors": [
{
"filename": "negative_test/changelogs/invalid-date/changelog.yml",
"path": "$.releases.1.0.0.release_date",
"message": "'01-01-2020' is not a 'date'",
"has_sub_errors": false
},
{
"filename": "negative_test/changelogs/invalid-date/changelog.yml",
"path": "$.releases.1.0.0.release_date",
"message": "'01-01-2020' does not match '\\\\d\\\\d\\\\d\\\\d-\\\\d\\\\d-\\\\d\\\\d'",
"has_sub_errors": false
}
],
"parse_errors": []
}
```
4 changes: 4 additions & 0 deletions test/schemas/negative_test/changelogs/list/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- this is invalid
- as changelog must be object (mapping)
- not an array (sequence)
34 changes: 34 additions & 0 deletions test/schemas/negative_test/changelogs/list/changelog.yml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ajv errors

```json
[
{
"instancePath": "",
"keyword": "type",
"message": "must be object",
"params": {
"type": "object"
},
"schemaPath": "#/type"
}
]
```

# check-jsonschema

stdout:

```json
{
"status": "fail",
"errors": [
{
"filename": "negative_test/changelogs/list/changelog.yml",
"path": "$",
"message": "['this is invalid', 'as changelog must be object (mapping)', 'not an array (sequence)'] is not of type 'object'",
"has_sub_errors": false
}
],
"parse_errors": []
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
releases: foo # <-- not a semver
34 changes: 34 additions & 0 deletions test/schemas/negative_test/changelogs/no-semver/changelog.yml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ajv errors

```json
[
{
"instancePath": "/releases",
"keyword": "type",
"message": "must be object",
"params": {
"type": "object"
},
"schemaPath": "#/properties/releases/type"
}
]
```

# check-jsonschema

stdout:

```json
{
"status": "fail",
"errors": [
{
"filename": "negative_test/changelogs/no-semver/changelog.yml",
"path": "$.releases",
"message": "'foo' is not of type 'object'",
"has_sub_errors": false
}
],
"parse_errors": []
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
release: {} # <- unknown key, correct would be releases
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ajv errors

```json
[
{
"instancePath": "",
"keyword": "additionalProperties",
"message": "must NOT have additional properties",
"params": {
"additionalProperty": "release"
},
"schemaPath": "#/additionalProperties"
}
]
```

# check-jsonschema

stdout:

```json
{
"status": "fail",
"errors": [
{
"filename": "negative_test/changelogs/unknown-keys/changelog.yml",
"path": "$",
"message": "Additional properties are not allowed ('release' was unexpected)",
"has_sub_errors": false
}
],
"parse_errors": []
}
```
17 changes: 17 additions & 0 deletions test/schemas/test/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ancestor: 0.5.4
releases:
1.0.0-alpha:
release_date: "2020-01-01"
codename: "The first public one"
changes:
release_summary: A bit o markdown text
bugfixes:
- Fixed bug `#1 <https://example.com>`
deprecated_features:
- Free form text mentioning a deprecation
minor_changes:
- Free form text mentioning a minor change
modules:
- description: foo
name: short_module_name
namespace: foo
3 changes: 3 additions & 0 deletions test/schemas/test/changelogs/minimal/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Example of minimal changelog.yml that is considered valid
releases: {}

0 comments on commit cb1612f

Please sign in to comment.