You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: handle empty events without compile errors in mobile clients [SCH-1641] (segmentio#56)
This PR fixes the way that empty events are handled by our mobile Typewriter clients. Previously, iOS and Android clients generated compile-time errors because they expected top-level definitions to be available for empty events, but they were not being generated (since they were `ObjectType` not `ClassType` in QuickType).
This PR fixes this by removing the property parameter when an event has no properties declared. If you had a JSON Schema like so:
```
{
"description": "This is an empty event.",
"name": "Empty Event",
"rules": {
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"context": {},
"properties": { "type": "object" },
"traits": {}
},
"required": ["properties"],
"type": "object"
}
}
```
Then methods like these would be generated:
```objectivec
// iOS Objective C
- (void)emptyEvent
{
[self emptyEvent:@{}];
}
- (void)emptyEvent:(NSDictionary<NSString *, id> *_Nullable)options
{
[self.analytics track:@"Empty Event" properties:@{} options:addTypewriterContextFields(options)];
}
```
```java
// Android Java
/**
* @see <a href="https://segment.com/docs/spec/track/">Track Documentation</a>
*/
public void emptyEvent() {
this.analytics.track("Empty Event", new Properties());
}
/**
* @see <a href="https://segment.com/docs/spec/track/">Track Documentation</a>
*/
public void emptyEvent(final @nullable Options options) {
this.analytics.track("Empty Event", new Properties(), options);
}
```
```js
// TS client
emptyEvent(
props?: {},
options?: SegmentOptions,
callback?: AnalyticsJSCallback
): void;
```
-----
This PR also makes a handful of small refactoring changes:
- Updates `quicktype` to pull in the `useList` flag for Android
- Refactors the `src/lib` folder to split utils by concept, rather than use a bulk utility folder
- Fixes a bug with how event names are generated, where quotes were not properly sanitized. This affected all clients.
0 commit comments