Skip to content
Discussion options

You must be logged in to vote

I just found a better solution as per Pydantic doc:

By default, the output may contain non-JSON-serializable Python objects. The mode argument can be specified as 'json' to ensure that the output only contains JSON serializable types.

Code:

class PrefixListAdd(BaseModel):
    name: str
    entries: List[PrefixListEntry]

    model_config = {
        'json_schema_extra': {
            'examples': [
                {
                    'name': 'my-prefixlist',
                    'entries': [
                        PrefixListEntry(prefix='10.0.1.1').model_dump(mode="json"),
                        PrefixListEntry(prefix='10.0.2.0/24', ge=26, le=31).model_dump(mode="json")
              …

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@angely-dev
Comment options

@sinisaos
Comment options

@angely-dev
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by angely-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants