[WIP, lib v19] Source generators for Types and Requests with System.Text.Json support #1078
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces 2 source generators that generate the classes for Types and Requests folders. Also it brings an API parser app.
API parser
It produces a JSON file according to the following schema: https://github.com/TelegramBots/Telegram.Bot/blob/abdab6f0fdc5dcf9e84364dfc431abce766ddcf4/src/Telegram.Bot.ApiParser/schema.json
Types source generator
Scriban template that will be rendered for each Bot API type:
Telegram.Bot/src/Telegram.Bot.Generators/Templates.Types.cs
Lines 16 to 69 in abdab6f
where:
{{ type_namespace }}
is namespace (starts withTelegram.Bot.Types
but can additionally contain sub-namespace such asTelegram.Bot.Types.InlineQueryResults
){{ type_description }}
is type's multi-line description parsed from official Bot API page{{ type_name }}
is theclass
'es name, for example for Bot API typeChat
we will generateChat
class located in fileChat.generated.cs
{{ parameter.parameter_description }}
is property (parameter) multi-line description parsed from official Bot API page{{ parameter.parameter_name }}
is snake_case name of parameter parsed from official Bot API page{{ parameter_type_name }}
is fully qualified type name of property, including its namespace (if needed){{ pascal_case_name }}
is property name in PascalCaseThe main concepts of this generation are:
JsonIgnore
attribute as well as Newtonsoft's Required and DefaultValueHandling arguments are only added when necessaryAt the moment, the source generator looks for
class
types withpublic
and withoutstatic
modifiers, located insideTypes
folder and all sub-folders.TODO
Telegram.Bot.Types.InlineQueryResults
)ForceReply
->ForceReplyMarkup
)Requests source generator
TODO