Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inside oneof_schema not work default values for nested keys #611

Open
zygfrydos opened this issue Oct 31, 2023 · 0 comments
Open

Inside oneof_schema not work default values for nested keys #611

zygfrydos opened this issue Oct 31, 2023 · 0 comments

Comments

@zygfrydos
Copy link

oneof_schema in my case is for future use, to add new compression program, but now its only for 7zip. One of compression program must be set
Code:

YAML_SCHEMA={    
    'compression':{
        'type':'dict',
        'required':True,
        'oneof_schema':[
            {
                '7z':{
                    'type':'dict',
                    'required':True,
                    'schema':{
                        'cmd_path':{'type':'string', 'required':True},
                        'passwd':{'type':'string'},
                        'compress_level':{'type': 'string', 'default':5, 'coerce': int},
                        'attr':{
                            'type':'list',
                            'contains':'y', # must cotain don't ask else will be hang
                            'default':['mmt',   # enable multithreading
                                       'ms',    # solid archive (without appending files in feature)
                                       'y',     # don't ask, auto yes
                                       'mhe=on',# hide file name in archive
                                       ]},
                        'exlude_attr':{
                            'type':'list',
                            'default':['r!$RECYCLE.BIN',                # windows recycle.bin
                                       '!System*Volume*Information',    # some other fat garbage
                                       'r!*.mdf',                       # except database file from mssql
                                       'r!*.ldf',                       # except log file from mssql
                                       '!.__sync__*'                   # except sync file from owncloud
                                       ]
                            }
                        }
                    },
            },]
        }
    }
    import yaml
    from cerberus import Validator
    v = Validator(YAML_SCHEMA)
    doc={'compression':{
        '7z':{
            'cmd_path':'somewhere'
            }}}
    print(yaml.dump(v.normalized(doc), Dumper=yaml.Dumper))

Give me out:

compression:
  7z:
    cmd_path: somewhere

When I change schema to:

YAML_SCHEMA={    
    'compression':{
        'type':'dict',
        'required':True,
        'schema':{
            '7z':{
                'type':'dict',
                'required':True,
                'schema':{
                    'cmd_path':{'type':'string', 'required':True},
                    'passwd':{'type':'string'},
                    'compress_level':{'type': 'string', 'default':5, 'coerce': int},
                    'attr':{
                        'type':'list',
                        'contains':'y', # must cotain don't ask else will be hang
                        'default':['mmt',   # enable multithreading
                                   'ms',    # solid archive (without appending files in feature)
                                   'y',     # don't ask, auto yes
                                   'mhe=on',# hide file name in archive
                                   ]},
                    'exlude_attr':{
                        'type':'list',
                        'default':['r!$RECYCLE.BIN',                # windows recycle.bin
                                   '!System*Volume*Information',    # some other fat garbage
                                   'r!*.mdf',                       # except database file from mssql
                                   'r!*.ldf',                       # except log file from mssql
                                   '!.__sync__*'                   # except sync file from owncloud
                                   ]
                        }
                    }
                },
            }
        }
    }

Output is correct:

compression:
  7z:
    attr:
    - mmt
    - ms
    - y
    - mhe=on
    cmd_path: somewhere
    compress_level: 5
    exlude_attr:
    - r!$RECYCLE.BIN
    - '!System*Volume*Information'
    - r!*.mdf
    - r!*.ldf
    - '!.__sync__*'


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant