Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Schema builder skipping nested typing types when generating object types #18

Closed
stephen-bunn opened this issue Jan 9, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@stephen-bunn
Copy link
Owner

Expected Behavior

I would expect the built schema of this config class...

from typing import Dict, List
from file_config import config, var, build_schema

@config
class Config(object):
  hooks = var(Dict[str, List[str]])

build_schema(Config)

to return

{ '$id': 'Config.json',
  '$schema': 'http://json-schema.org/draft-07/schema#',
  'properties': { 'hooks': { '$id': '#/properties/hooks',
                             'patternProperties': { '^(.*)$': { 'items': { '$id': '#/properties/hooks/items',
                                                                           'type': 'string'},
                                                                'type': 'array'}},
                             'type': 'object'}},
  'required': ['hooks'],
  'type': 'object'}

Current Behavior

Currently the generated schema comes out looking like this...

{ '$id': 'Config.json',
  '$schema': 'http://json-schema.org/draft-07/schema#',
  'properties': { 'hooks': { '$id': '#/properties/hooks',
                             'patternProperties': { '^(.*)$': {},
                             'type': 'object'}},
  'required': ['hooks'],
  'type': 'object'}

Possible Solution

This is due to the fact that schema_builder@_build is not handling typing types any differently than bulitin types. So when it tries to build the nested typing type (typing.List[str]) it is instead (somewhat silently) failing and returning an empty schema ({})

Solution would be to have a special handler in _build which deals with nested typings. This may also require some changes in the other _build_{type}_type handlers with out modifiers are built (they currently expect config vars if the given type is not a builtin).

Steps to Reproduce (for bugs)

  1. Try and run the code show in "Expected Behavior"

Your Environment

  • File Config Version: 0.3.1
  • Python Version: 3.7
  • Operating System and Version: Ubuntu 18.04

❤️ Thank you!

stephen-bunn added a commit that referenced this issue Jan 9, 2019
- Throwing in some docstrings for private functions in schema_builder

Signed-off-by: Stephen Bunn <stephen@bunn.io>
@stephen-bunn
Copy link
Owner Author

Fixed in commit d8c02c8, published in v0.3.2

@stephen-bunn stephen-bunn added the bug Something isn't working label Jan 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant