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

Remove unknown types from model generator #834

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 8 additions & 6 deletions examples/echo-bot-ts-cjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ const client = new messagingApi.MessagingApiClient(clientConfig);
// Create a new Express application.
const app: Application = express();

const isTextEvent = (event: any): event is webhook.MessageEvent & { message: webhook.TextMessageContent } => {
return event.type === 'message' && event.message && event.message.type === 'text';
};

// Function handler to receive the text.
const textEventHandler = async (event: webhook.Event): Promise<MessageAPIResponseBase | undefined> => {
// Process all variables here.
if (!isTextEvent(event)) {

// Check if for a text message
if (event.type !== 'message' || event.message.type !== 'text') {
return;
}

// Process all message related variables here.

// Check if message is repliable
if (!event.replyToken) return;

// Create a new message.
// Reply to the user.
await client.replyMessage({
replyToken: event.replyToken as string,
replyToken:event.replyToken,
messages: [{
type: 'text',
text: event.message.text,
Expand Down
13 changes: 8 additions & 5 deletions examples/echo-bot-ts-esm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,25 @@ const client = new messagingApi.MessagingApiClient(clientConfig);
// Create a new Express application.
const app: Application = express();

const isTextEvent = (event: any): event is webhook.MessageEvent & { message: webhook.TextMessageContent } => {
return event.type === 'message' && event.message && event.message.type === 'text';
};

// Function handler to receive the text.
const textEventHandler = async (event: webhook.Event): Promise<MessageAPIResponseBase | undefined> => {
// Process all variables here.
if (!isTextEvent(event)) {

// Check if for a text message
if (event.type !== 'message' || event.message.type !== 'text') {
return;
}

// Process all message related variables here.

// Check if message is repliable
if (!event.replyToken) return;

// Create a new message.
// Reply to the user.
await client.replyMessage({
replyToken: event.replyToken as string,
replyToken:event.replyToken,
messages: [{
type: 'text',
text: event.message.text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ export type {{classname}} =
{%- for model in model.model.discriminator.mappedModels %}
| {{model.modelName}} // {{model.mappingName}}
{%- endfor %}
| Unknown{{classname}}
;

export type Unknown{{classname}} = {{classname}}Base & {
[key: string]: unknown;
};
{% endif -%}

{% if model.model.description != null %}
Expand Down
7 changes: 1 addition & 6 deletions lib/messaging-api/model/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ export type Action =
| MessageAction // message
| PostbackAction // postback
| RichMenuSwitchAction // richmenuswitch
| URIAction // uri
| UnknownAction;

export type UnknownAction = ActionBase & {
[key: string]: unknown;
};
| URIAction; // uri

/**
* Action
Expand Down
7 changes: 1 addition & 6 deletions lib/messaging-api/model/demographicFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ export type DemographicFilter =
| AreaDemographicFilter // area
| GenderDemographicFilter // gender
| OperatorDemographicFilter // operator
| SubscriptionPeriodDemographicFilter // subscriptionPeriod
| UnknownDemographicFilter;

export type UnknownDemographicFilter = DemographicFilterBase & {
[key: string]: unknown;
};
| SubscriptionPeriodDemographicFilter; // subscriptionPeriod

/**
* Demographic filter
Expand Down
8 changes: 1 addition & 7 deletions lib/messaging-api/model/flexBoxBackground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@

import { FlexBoxLinearGradient } from "./models.js";

export type FlexBoxBackground =
| FlexBoxLinearGradient // linearGradient
| UnknownFlexBoxBackground;

export type UnknownFlexBoxBackground = FlexBoxBackgroundBase & {
[key: string]: unknown;
};
export type FlexBoxBackground = FlexBoxLinearGradient; // linearGradient

export type FlexBoxBackgroundBase = {
/**
Expand Down
7 changes: 1 addition & 6 deletions lib/messaging-api/model/flexComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ export type FlexComponent =
| FlexSeparator // separator
| FlexSpan // span
| FlexText // text
| FlexVideo // video
| UnknownFlexComponent;

export type UnknownFlexComponent = FlexComponentBase & {
[key: string]: unknown;
};
| FlexVideo; // video

export type FlexComponentBase = {
/**
Expand Down
7 changes: 1 addition & 6 deletions lib/messaging-api/model/flexContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import { FlexCarousel } from "./models.js";

export type FlexContainer =
| FlexBubble // bubble
| FlexCarousel // carousel
| UnknownFlexContainer;

export type UnknownFlexContainer = FlexContainerBase & {
[key: string]: unknown;
};
| FlexCarousel; // carousel

export type FlexContainerBase = {
/**
Expand Down
7 changes: 1 addition & 6 deletions lib/messaging-api/model/imagemapAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ import { URIImagemapAction } from "./models.js";
export type ImagemapAction =
| ClipboardImagemapAction // clipboard
| MessageImagemapAction // message
| URIImagemapAction // uri
| UnknownImagemapAction;

export type UnknownImagemapAction = ImagemapActionBase & {
[key: string]: unknown;
};
| URIImagemapAction; // uri

export type ImagemapActionBase = {
/**
Expand Down
7 changes: 1 addition & 6 deletions lib/messaging-api/model/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ export type Message =
| StickerMessage // sticker
| TemplateMessage // template
| TextMessage // text
| VideoMessage // video
| UnknownMessage;

export type UnknownMessage = MessageBase & {
[key: string]: unknown;
};
| VideoMessage; // video

export type MessageBase = {
/**
Expand Down
7 changes: 1 addition & 6 deletions lib/messaging-api/model/recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import { RedeliveryRecipient } from "./models.js";
export type Recipient =
| AudienceRecipient // audience
| OperatorRecipient // operator
| RedeliveryRecipient // redelivery
| UnknownRecipient;

export type UnknownRecipient = RecipientBase & {
[key: string]: unknown;
};
| RedeliveryRecipient; // redelivery

/**
* Recipient
Expand Down
7 changes: 1 addition & 6 deletions lib/messaging-api/model/richMenuBatchOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import { RichMenuBatchUnlinkAllOperation } from "./models.js";
export type RichMenuBatchOperation =
| RichMenuBatchLinkOperation // link
| RichMenuBatchUnlinkOperation // unlink
| RichMenuBatchUnlinkAllOperation // unlinkAll
| UnknownRichMenuBatchOperation;

export type UnknownRichMenuBatchOperation = RichMenuBatchOperationBase & {
[key: string]: unknown;
};
| RichMenuBatchUnlinkAllOperation; // unlinkAll

/**
* Rich menu operation object represents the batch operation to the rich menu linked to the user.
Expand Down
7 changes: 1 addition & 6 deletions lib/messaging-api/model/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ export type Template =
| ButtonsTemplate // buttons
| CarouselTemplate // carousel
| ConfirmTemplate // confirm
| ImageCarouselTemplate // image_carousel
| UnknownTemplate;

export type UnknownTemplate = TemplateBase & {
[key: string]: unknown;
};
| ImageCarouselTemplate; // image_carousel

export type TemplateBase = {
/**
Expand Down
7 changes: 1 addition & 6 deletions lib/webhook/model/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ export type Event =
| ThingsEvent // things
| UnfollowEvent // unfollow
| UnsendEvent // unsend
| VideoPlayCompleteEvent // videoPlayComplete
| UnknownEvent;

export type UnknownEvent = EventBase & {
[key: string]: unknown;
};
| VideoPlayCompleteEvent; // videoPlayComplete

/**
* Webhook event
Expand Down
7 changes: 1 addition & 6 deletions lib/webhook/model/mentionee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import { UserMentionee } from "./models.js";

export type Mentionee =
| AllMentionee // all
| UserMentionee // user
| UnknownMentionee;

export type UnknownMentionee = MentioneeBase & {
[key: string]: unknown;
};
| UserMentionee; // user

export type MentioneeBase = {
/**
Expand Down
7 changes: 1 addition & 6 deletions lib/webhook/model/messageContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ export type MessageContent =
| LocationMessageContent // location
| StickerMessageContent // sticker
| TextMessageContent // text
| VideoMessageContent // video
| UnknownMessageContent;

export type UnknownMessageContent = MessageContentBase & {
[key: string]: unknown;
};
| VideoMessageContent; // video

export type MessageContentBase = {
/**
Expand Down
7 changes: 1 addition & 6 deletions lib/webhook/model/moduleContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import { DetachedModuleContent } from "./models.js";

export type ModuleContent =
| AttachedModuleContent // attached
| DetachedModuleContent // detached
| UnknownModuleContent;

export type UnknownModuleContent = ModuleContentBase & {
[key: string]: unknown;
};
| DetachedModuleContent; // detached

export type ModuleContentBase = {
/**
Expand Down
7 changes: 1 addition & 6 deletions lib/webhook/model/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import { UserSource } from "./models.js";
export type Source =
| GroupSource // group
| RoomSource // room
| UserSource // user
| UnknownSource;

export type UnknownSource = SourceBase & {
[key: string]: unknown;
};
| UserSource; // user

/**
* the source of the event.
Expand Down
7 changes: 1 addition & 6 deletions lib/webhook/model/thingsContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import { UnlinkThingsContent } from "./models.js";
export type ThingsContent =
| LinkThingsContent // link
| ScenarioResultThingsContent // scenarioResult
| UnlinkThingsContent // unlink
| UnknownThingsContent;

export type UnknownThingsContent = ThingsContentBase & {
[key: string]: unknown;
};
| UnlinkThingsContent; // unlink

export type ThingsContentBase = {
/**
Expand Down