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

docs(parser): add JSON string field extension example #1526

Merged
merged 5 commits into from
Sep 23, 2022
Merged
Changes from 1 commit
Commits
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
15 changes: 14 additions & 1 deletion docs/utilities/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Parser comes with the following built-in models:
| **KafkaSelfManagedEventModel** | Lambda Event Source payload for self managed Kafka payload |
| **KafkaMskEventModel** | Lambda Event Source payload for AWS MSK payload |

### extending built-in models
### Extending built-in models
heitorlessa marked this conversation as resolved.
Show resolved Hide resolved

You can extend them to include your own models, and yet have all other known fields parsed along the way.

Expand Down Expand Up @@ -236,6 +236,19 @@ for order_item in ret.detail.items:
3. Defined how part of our EventBridge event should look like by overriding `detail` key within our `OrderEventModel`
4. Parser parsed the original event against `OrderEventModel`

???+ tip
When extending a `string` field containing JSON, you need to wrap the field
with [Pydantic's Json Type](https://pydantic-docs.helpmanual.io/usage/types/#json-type):

```python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you create as a snippet file so it runs as-is?

I'd like to prevent us from getting into where we were before with typos, and customers copying/pasting code that doesn't run

from pydantic import Json

...

class OrderEventModel(APIGatewayProxyEventV2Model):
body: Json[Order]
```

## Envelopes

When trying to parse your payloads wrapped in a known structure, you might encounter the following situations:
Expand Down