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

Replace APISchema with Pydantic2 #85

Merged
merged 30 commits into from
Aug 31, 2023
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
df0d471
switched Support to Pydantic2 (intermediate breaking change)
gilesknap Jul 11, 2023
05879b0
first pydantic pass: ioc.py
gilesknap Jul 11, 2023
4112595
ioc.py pydantic working except objects
gilesknap Jul 11, 2023
d5dde2d
partially working id tracking
gilesknap Jul 12, 2023
c2cca52
add TODO comments on existing issues
gilesknap Jul 12, 2023
8285b3c
pydantiic test_ioc_build test working but test_ioc_schema is not
gilesknap Jul 13, 2023
5b5b7a5
great progress
gilesknap Jul 13, 2023
1edcea8
values expansion working
gilesknap Jul 14, 2023
c66c237
id lookup working!
gilesknap Jul 14, 2023
0ba40e0
utils in values render fixed
gilesknap Jul 14, 2023
3ab0625
fix some tests
gilesknap Jul 14, 2023
f34b4d6
fix more tests
gilesknap Jul 14, 2023
995783b
all tests working
gilesknap Jul 14, 2023
31647ea
update ibek-defs
gilesknap Jul 14, 2023
c406526
update TODOs
gilesknap Jul 14, 2023
899f7fe
fix dependencies
gilesknap Jul 14, 2023
e21035c
add check of defaults to pydantic tests
gilesknap Jul 14, 2023
ab4e25c
fix lint
gilesknap Jul 14, 2023
a8f88dc
remove back quotes in docstrings
gilesknap Jul 14, 2023
72188cf
try to fix docs
gilesknap Jul 14, 2023
69d050e
remove apischema sphinx plugin
gilesknap Jul 14, 2023
1a727d5
fix sphinx
gilesknap Jul 17, 2023
fd14fb4
add comment re schema error messages
gilesknap Jul 17, 2023
90ee451
add simple references example
gilesknap Jul 17, 2023
003f6b2
add example of object ref with createmodel
gilesknap Jul 17, 2023
479c330
another example of refs - more like ioc.py
gilesknap Jul 17, 2023
b44b119
fix pydantic test broken yaml file
gilesknap Jul 17, 2023
9b9891f
update examples with more info
gilesknap Jul 18, 2023
99b5ab8
add test example that is identical to ibek?
gilesknap Jul 18, 2023
dd3c950
updated examples to demo issue
gilesknap Jul 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix pydantic test broken yaml file
  • Loading branch information
gilesknap committed Jul 17, 2023

Unverified

This user has not yet uploaded their public signing key.
commit b44b119618f582ac84eb72f4663f77289a563f00
38 changes: 26 additions & 12 deletions examples/test_refs3.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@


class Entity(BaseModel):
type: Literal["e"]
type: str = Field(description="The type of this entity")
name: str = Field(..., description="The name of this entity")
value: str = Field(..., description="The value of this entity")
ref: Optional[str] = Field(
@@ -31,6 +31,14 @@ def add_ibek_attributes(cls, entity: Entity):
return entity


class Entity1(Entity):
type: Literal["e1"] = Field(description="The type of this entity")


class Entity2(Entity):
type: Literal["e2"] = Field(description="The type of this entity")


@field_validator("ref", mode="after")
def lookup_instance(cls, id):
try:
@@ -41,32 +49,38 @@ def lookup_instance(cls, id):

validators = {"Entity": lookup_instance}

# add validator to the Entity class using create model
Entity2 = create_model(
"Entity",
# add validator to the Entity classes using create model
EntityOne = create_model(
"EntityOne",
__validators__=validators,
__base__=Entity1,
) # type: ignore

EntityTwo = create_model(
"EntityTwo",
__validators__=validators,
__base__=Entity,
__base__=Entity2,
) # type: ignore

entity_models = [Entity2, Entity2]
entity_models = (EntityOne, EntityTwo)


class EntityModel(RootModel):
root: Union[tuple(entity_models)] = Field(discriminator="type") # type: ignore
root: Union[entity_models] = Field(discriminator="type") # type: ignore


class Entities(BaseModel):
model_config = ConfigDict(extra="forbid")
entities: Sequence[EntityModel] = Field( # type: ignore
description="List of entities this IOC instantiates"
description="List of entities classes we want to create"
)


model1 = Entities(
**{
"entities": [
{"type": "e", "name": "one", "value": "OneValue"},
{"type": "e", "name": "two", "value": "TwoValue", "ref": "one"},
{"type": "e1", "name": "one", "value": "OneValue"},
{"type": "e2", "name": "two", "value": "TwoValue", "ref": "one"},
]
}
)
@@ -78,13 +92,13 @@ class Entities(BaseModel):
model2 = Entities(
**{
"entities": [
{"type": "e2", "name": "two", "value": "TwoValue", "ref": "one"},
{
"type": "e",
"type": "e1",
"name": "one",
"value": "OneValue",
"illegal": "bad argument",
},
{"type": "e", "name": "two", "value": "TwoValue", "ref": "one"},
]
}
)
2 changes: 1 addition & 1 deletion tests/samples/pydantic/test.ibek.ioc.yaml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ entities:

- type: pydantic_test.AnAsynPort
name: AsynPort2
IPpp: 10.0.0.2
IP: 10.0.0.2

- type: pydantic_test.Consumer
name: A Consumer