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

feat: Add routePath to Resource and blueprint.events #141

Merged
merged 17 commits into from
Dec 20, 2024

Conversation

andrii-balitskyi
Copy link
Contributor

@andrii-balitskyi andrii-balitskyi commented Dec 18, 2024

Closes #74

  • Add events
  • Add test fixture event schema

@andrii-balitskyi andrii-balitskyi requested a review from a team as a code owner December 18, 2024 16:53
Copy link

vercel bot commented Dec 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blueprint ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 5:16pm

src/lib/blueprint.ts Outdated Show resolved Hide resolved
src/lib/blueprint.ts Outdated Show resolved Hide resolved
@andrii-balitskyi
Copy link
Contributor Author

@razor-x The resources.event isn't being generated because createResources only supports regular schemas, not oneOf schemas. I think oneOf schemas are currently event and action_attempt. Should we come up with some sort of union resource definition for such schemas?

@razor-x
Copy link
Collaborator

razor-x commented Dec 18, 2024

@razor-x The resources.event isn't being generated because createResources only supports regular schemas, not oneOf schemas. I think oneOf schemas are currently event and action_attempt. Should we come up with some sort of union resource definition for such schemas?

Yes, but events and action attempts are different: events have one level of union and action attempts have two. Because blueprint defines the EventResouce, it can make some assumptions about the event resource type union. Let's only solve the event case now and leave action attempts for later.

For events, we can just find all properties that are common to all events and drop the rest. I realize this might create some false positives, e.g., we may see connected_account_id as a common property when it's really not, but let's give it a try and see what happens. Alternatively we can annotate the common properties in the yaml, e.g., is_common_property.

@razor-x razor-x changed the title Add events feat: Add routePath to Resource and blueprint.events Dec 19, 2024
(result, propKey) => {
const propValue = firstSchema.properties?.[propKey]
if (propValue != null) {
result[propKey] = propValue
Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally, mixing imperative mutation patterns with functional reduce patterns is confusing and unexpected. Prefer either a for loop with assignment, or

Suggested change
result[propKey] = propValue
return { ...result, [propKey]: propValue }

This is why result is not generally used as the arg name in reduce, because it's actually the intermediate accumulator at each step for the final result

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I realized that enum values should be merged because with current implementation event_type would have only first single enum value. Implementation: dffc672

src/utils/find-common-openapi-schema-properties.test.ts Outdated Show resolved Hide resolved
@andrii-balitskyi andrii-balitskyi merged commit 8e09da6 into main Dec 20, 2024
21 checks passed
@andrii-balitskyi andrii-balitskyi deleted the event-resource branch December 20, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate /events and event resource
3 participants