Skip to content

Commit

Permalink
Merge branch 'bugfix/support_boolean_require' into 'main'
Browse files Browse the repository at this point in the history
fix: support boolean type for require field

Closes PACMAN-791

See merge request espressif/idf-component-manager!353
  • Loading branch information
kumekay committed Feb 23, 2024
2 parents cfb2d97 + a749a59 commit 6ae82df
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
19 changes: 18 additions & 1 deletion idf_component_tools/manifest/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,25 @@ def process_json_schema(
json_schema['properties']['targets']['items']['type'] = 'string'
_anyof[1]['properties']['pre_release']['type'] = 'boolean'
_anyof[1]['properties']['public']['type'] = 'boolean'
_anyof[1]['properties']['require']['type'] = 'string'

# Require field might be a boolean or enum string
_anyof[1]['properties']['require'] = {
'type': 'object',
'anyOf': [
{
'enum': [
'public',
'private',
'no',
],
'type': 'string',
},
{
'type': 'boolean',
'enum': [False], # Require can be only public, private or no/False
},
],
}
# normalize the final json schema
json_schema = process_json_schema(json_schema)

Expand Down
23 changes: 22 additions & 1 deletion tests/manifest/test_validator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import os
import re
Expand Down Expand Up @@ -351,6 +351,27 @@ def test_validate_require_public_fields(self, valid_manifest):
assert len(errors) == 1
assert 'require' in errors[0]

def test_validate_require_field_support_boolean_string(self, valid_manifest):
valid_manifest['dependencies']['test']['require'] = 'public'
validator = ManifestValidator(valid_manifest)
errors = validator.validate_normalize()

assert not errors

valid_manifest['dependencies']['test']['require'] = False
validator = ManifestValidator(valid_manifest)
errors = validator.validate_normalize()

assert not errors

def test_validate_require_field_true_error(self, valid_manifest):
valid_manifest['dependencies']['test']['require'] = True
validator = ManifestValidator(valid_manifest)
errors = validator.validate_normalize()

assert len(errors) == 4
assert 'require' in errors[-1]

def test_validate_links_wrong_url(self, valid_manifest):
valid_manifest['issues'] = 'test.com/tracker'

Expand Down

0 comments on commit 6ae82df

Please sign in to comment.