@@ -4,7 +4,7 @@ import { type Field, getCustomSchema } from "@gramio/schema-parser";
44import prettier from "prettier" ;
55import { OUTPUT_PATH , PRETTIER_OPTIONS } from "./config" ;
66import { APIMethods , Objects , Params } from "./entities" ;
7- import { CodeGenerator , generateHeader } from "./helpers" ;
7+ import { CodeGenerator , assertMethodFields , generateHeader } from "./helpers" ;
88
99export interface IGeneratedFile {
1010 name : string ;
@@ -31,37 +31,12 @@ const schema = await getCustomSchema();
3131}
3232
3333const { methods } = schema ;
34- const objects = schema . objects
34+ const objects = schema . objects ;
3535
36- // Telegram added the same stop controls to both draft methods in Bot API 10.3.
37- // The upstream HTML briefly exposed them on sendMessageDraft only, which made a
38- // successful regeneration silently remove the rich-draft fields. Keep this
39- // assertion next to the schema boundary so no release can regress either
40- // declaration even if the source page or parser changes again.
41- {
42- const requiredDraftFields = [ "can_stop" , "keep_on_stop" ] ;
43- const draftMethods = [ "sendMessageDraft" , "sendRichMessageDraft" ] ;
44- const problems : string [ ] = [ ] ;
45-
46- for ( const methodName of draftMethods ) {
47- const method = methods . find ( ( candidate ) => candidate . name === methodName ) ;
48- if ( ! method ) {
49- problems . push ( `${ methodName } is missing` ) ;
50- continue ;
51- }
52-
53- for ( const field of requiredDraftFields )
54- if ( ! method . parameters . some ( ( parameter ) => parameter . key === field ) )
55- problems . push ( `${ methodName } .${ field } is missing` ) ;
56- }
57-
58- if ( problems . length )
59- throw new Error (
60- `Bot API draft controls are incomplete in the parsed schema:\n ${ problems . join (
61- "\n " ,
62- ) } `,
63- ) ;
64- }
36+ assertMethodFields ( methods , {
37+ sendMessageDraft : [ "can_stop" , "keep_on_stop" ] ,
38+ sendRichMessageDraft : [ "can_stop" , "keep_on_stop" ] ,
39+ } ) ;
6540
6641// Guard against silently losing FormattableString support. Telegram documents a
6742// `parse_mode` sibling for exactly those text fields that accept formatting
@@ -135,9 +110,7 @@ const objects = schema.objects
135110// We derive the set once so generators can emit `| { toJSON(): T }` unions.
136111
137112const markupTypes = new Set (
138- objects
139- . filter ( ( o ) => o . semanticType === "markup" )
140- . map ( ( o ) => o . name ) ,
113+ objects . filter ( ( o ) => o . semanticType === "markup" ) . map ( ( o ) => o . name ) ,
141114) ;
142115
143116// ─── File generation ──────────────────────────────────────────────────────────
0 commit comments