Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
test-it
Pydantic Schema Registry
Commits
064cc126
Commit
064cc126
authored
Nov 30, 2020
by
ozzeh
Browse files
Checkpoint commit
parent
1ab5eed9
Changes
3
Hide whitespace changes
Inline
Side-by-side
schema_registry/client.py
View file @
064cc126
...
...
@@ -105,7 +105,7 @@ class SchemaRegistry:
)
def
get_schema
(
self
,
name
)
->
Schema
:
return
self
.
_schemas
.
get
(
name
)
return
self
.
_schemas
[
name
]
def
register_model
(
...
...
schema_registry/reflection.py
View file @
064cc126
from
typing
import
Optional
,
List
from
pydantic
import
BaseModel
,
create_model
,
Field
from
pydantic
import
BaseModel
,
create_model
,
Field
,
PrivateAttr
from
devtools
import
debug
from
jsonpointer
import
resolve_pointer
...
...
@@ -20,10 +20,18 @@ def reflect_event(event_dict: dict) -> BaseModel:
class
_ReflectedModel
(
BaseModel
):
__detail_type__
:
str
=
PrivateAttr
()
@
property
def
detail_type
(
self
)
->
Optional
[
str
]:
return
self
.
__detail_type__
or
None
class
Config
:
alias_generator
=
lambda
x
:
"fields_"
if
x
==
"fields"
else
x
class
SchemaReflector
:
def
__init__
(
self
,
schema
,
registry
=
None
):
self
.
schema
=
schema
...
...
tests/test_both.py
View file @
064cc126
...
...
@@ -8,9 +8,4 @@ def test_loading_schemas():
registry
=
SchemaRegistry
(
"TAPI-TEST"
)
schema
:
Schema
=
registry
.
_schemas
[
"schema_registry.test.TestingModel"
]
debug
(
schema
.
get
())
reflector
:
SchemaReflector
=
schema
.
reflect
()
model
=
reflector
.
create_model_for_jsonschema
()
debug
(
model
.
__fields__
)
instance
=
model
(
name
=
"ozzeh"
,
description
=
"big willy johnston"
)
registry
.
register_model
(
"schema_registry.test"
,
model
)
registry
.
send_event
(
"auth-dev"
,
"com.pleaseignore.tvm.test"
,
instance
)
reflector
:
SchemaReflector
=
SchemaReflector
(
schema
.
get
().
content_dict
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment