codoc 0.1.0

Unified documentation parser for Ruby and TypeScript codebases
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
//! Schema types for the Codoc unified documentation format.
//!
//! These types match the JSON schema defined in `schema.json`.

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Root document structure for Codoc output.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Document {
    /// Schema version identifier.
    pub schema: String,

    /// Project metadata.
    pub metadata: Metadata,

    /// Top-level documented entities.
    pub entities: Vec<Entity>,

    /// Flat symbol table for quick lookups and linking.
    pub symbols: Vec<SymbolEntry>,

    /// Symbols referenced but not found in entities or external mappings.
    #[serde(
        rename = "unresolvedReferences",
        skip_serializing_if = "Vec::is_empty",
        default
    )]
    pub unresolved_references: Vec<UnresolvedReference>,
}

impl Document {
    /// Creates a new document with the current schema version.
    pub fn new(metadata: Metadata) -> Self {
        Self {
            schema: crate::SCHEMA_VERSION.to_string(),
            metadata,
            entities: Vec::new(),
            symbols: Vec::new(),
            unresolved_references: Vec::new(),
        }
    }
}

/// Project metadata.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Metadata {
    /// Project/package name.
    pub name: String,

    /// Project version.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,

    /// Source language.
    pub language: Language,

    /// Generation timestamp.
    #[serde(rename = "generatedAt")]
    pub generated_at: String,

    /// Root directory for source files.
    #[serde(rename = "sourceRoot", skip_serializing_if = "Option::is_none")]
    pub source_root: Option<String>,

    /// Prefix for all entity IDs.
    #[serde(rename = "idPrefix", skip_serializing_if = "Option::is_none")]
    pub id_prefix: Option<String>,

    /// List of parsed files.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub files: Vec<String>,

    /// External symbol link mappings by package/gem name.
    #[serde(
        rename = "externalLinks",
        skip_serializing_if = "HashMap::is_empty",
        default
    )]
    pub external_links: HashMap<String, ExternalLinkMapping>,
}

/// Source language.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Language {
    /// Ruby language.
    Ruby,
    /// TypeScript language.
    TypeScript,
}

/// Configuration for linking to external documentation.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ExternalLinkMapping {
    /// Base URL for documentation.
    #[serde(rename = "baseUrl", skip_serializing_if = "Option::is_none")]
    pub base_url: Option<String>,

    /// URL template with placeholders.
    #[serde(rename = "urlTemplate", skip_serializing_if = "Option::is_none")]
    pub url_template: Option<String>,

    /// Explicit URL overrides for specific symbols.
    #[serde(skip_serializing_if = "HashMap::is_empty", default)]
    pub symbols: HashMap<String, String>,

    /// Transform rules for symbol names.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transform: Option<TransformRules>,
}

/// Transform rules for symbol names in URLs.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct TransformRules {
    /// How to transform `::` or `.` in qualified names.
    #[serde(rename = "nameSeparator", skip_serializing_if = "Option::is_none")]
    pub name_separator: Option<String>,

    /// Prefix for instance method anchors.
    #[serde(rename = "methodPrefix", skip_serializing_if = "Option::is_none")]
    pub method_prefix: Option<String>,

    /// Prefix for class method anchors.
    #[serde(rename = "classMethodPrefix", skip_serializing_if = "Option::is_none")]
    pub class_method_prefix: Option<String>,

    /// Whether to lowercase the symbol name in URLs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lowercase: Option<bool>,
}

/// Entry in the symbol table for linking.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SymbolEntry {
    /// Unique identifier.
    pub id: String,

    /// Short name.
    pub name: String,

    /// Fully qualified name.
    #[serde(rename = "qualifiedName")]
    pub qualified_name: String,

    /// Entity kind.
    pub kind: String,

    /// Parent entity ID.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub parent: Option<String>,

    /// Source file path.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub file: Option<String>,

    /// Line number.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub line: Option<u32>,

    /// Short signature for methods.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub signature: Option<String>,
}

/// Unresolved reference.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnresolvedReference {
    /// Unresolved type/symbol name.
    pub name: String,

    /// Attempted qualified name.
    #[serde(rename = "qualifiedName", skip_serializing_if = "Option::is_none")]
    pub qualified_name: Option<String>,

    /// Package hint if available.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub package: Option<String>,

    /// Entity IDs that reference this unresolved symbol.
    #[serde(rename = "referencedFrom")]
    pub referenced_from: Vec<String>,
}

/// A documented entity.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "kind")]
pub enum Entity {
    /// A module (Ruby module or TypeScript namespace).
    #[serde(rename = "module")]
    Module(Module),

    /// A class.
    #[serde(rename = "class")]
    Class(Class),

    /// An interface (TypeScript).
    #[serde(rename = "interface")]
    Interface(Interface),

    /// A type alias (TypeScript).
    #[serde(rename = "type")]
    TypeAlias(TypeAlias),

    /// An enum (TypeScript).
    #[serde(rename = "enum")]
    Enum(Enum),

    /// A method.
    #[serde(rename = "method")]
    Method(Callable),

    /// A standalone function.
    #[serde(rename = "function")]
    Function(Callable),

    /// A constructor.
    #[serde(rename = "constructor")]
    Constructor(Callable),

    /// A property.
    #[serde(rename = "property")]
    Property(Property),

    /// A constant.
    #[serde(rename = "constant")]
    Constant(Constant),
}

impl Entity {
    /// Returns the entity's ID.
    pub fn id(&self) -> &str {
        match self {
            Entity::Module(m) => &m.base.id,
            Entity::Class(c) => &c.base.id,
            Entity::Interface(i) => &i.base.id,
            Entity::TypeAlias(t) => &t.base.id,
            Entity::Enum(e) => &e.base.id,
            Entity::Method(c) | Entity::Function(c) | Entity::Constructor(c) => &c.base.id,
            Entity::Property(p) => &p.base.id,
            Entity::Constant(c) => &c.base.id,
        }
    }

    /// Returns the entity's name.
    pub fn name(&self) -> &str {
        match self {
            Entity::Module(m) => &m.base.name,
            Entity::Class(c) => &c.base.name,
            Entity::Interface(i) => &i.base.name,
            Entity::TypeAlias(t) => &t.base.name,
            Entity::Enum(e) => &e.base.name,
            Entity::Method(c) | Entity::Function(c) | Entity::Constructor(c) => &c.base.name,
            Entity::Property(p) => &p.base.name,
            Entity::Constant(c) => &c.base.name,
        }
    }
}

/// Base properties shared by all documented entities.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct BaseEntity {
    /// Unique identifier for cross-referencing.
    pub id: String,

    /// Entity name.
    pub name: String,

    /// Source location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location: Option<SourceLocation>,

    /// Documentation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub docs: Option<Documentation>,

    /// Visibility/access level.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub visibility: Option<Visibility>,

    /// Marked with @private tag.
    #[serde(rename = "isPrivateApi", skip_serializing_if = "Option::is_none")]
    pub is_private_api: Option<bool>,
}

/// Location in source code.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SourceLocation {
    /// Relative file path.
    pub file: String,

    /// Line number (1-indexed).
    pub line: u32,

    /// Column number (0-indexed).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub column: Option<u32>,
}

/// Visibility/access level.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Visibility {
    /// Public access.
    Public,
    /// Protected access (subclasses only).
    Protected,
    /// Private access.
    Private,
    /// Internal access (package/module only).
    Internal,
}

/// Documentation fields.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Documentation {
    /// Brief one-line summary.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub summary: Option<String>,

    /// Full description (may contain markdown).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,

    /// Code examples.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub examples: Vec<Example>,

    /// Cross-references.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub see: Vec<SeeReference>,

    /// Important notes.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub notes: Vec<String>,

    /// TODO items.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub todos: Vec<String>,

    /// Deprecation notice.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deprecated: Option<Deprecation>,

    /// Version when introduced.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub since: Option<String>,

    /// Custom tags.
    #[serde(skip_serializing_if = "HashMap::is_empty", default)]
    pub tags: HashMap<String, String>,
}

/// A code example.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Example {
    /// Optional title.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,

    /// The example code.
    pub code: String,

    /// Language hint.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language: Option<String>,
}

/// Cross-reference to related documentation.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SeeReference {
    /// Display text.
    pub text: String,

    /// Reference ID or URL.
    #[serde(rename = "ref", skip_serializing_if = "Option::is_none")]
    pub reference: Option<String>,
}

/// Deprecation notice.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Deprecation {
    /// Deprecation message.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,

    /// Version when deprecated.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub since: Option<String>,

    /// Suggested replacement.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub replacement: Option<String>,
}

/// Reference to a type.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TypeReference {
    /// Type name.
    pub name: String,

    /// Kind of type reference.
    pub kind: TypeKind,

    /// Generic type arguments.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub args: Vec<TypeReference>,

    /// Union/intersection/tuple members.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub members: Vec<TypeReference>,

    /// Literal value for literal types.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value: Option<serde_json::Value>,

    /// Whether this type can be null/nil.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nullable: Option<bool>,

    /// Reference ID to a documented entity.
    #[serde(rename = "ref", skip_serializing_if = "Option::is_none")]
    pub reference: Option<String>,

    /// External package/gem name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub package: Option<String>,

    /// Fully qualified name for external symbol resolution.
    #[serde(rename = "qualifiedName", skip_serializing_if = "Option::is_none")]
    pub qualified_name: Option<String>,
}

impl TypeReference {
    /// Creates a simple type reference.
    pub fn simple(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            kind: TypeKind::Simple,
            args: Vec::new(),
            members: Vec::new(),
            value: None,
            nullable: None,
            reference: None,
            package: None,
            qualified_name: None,
        }
    }

    /// Creates a void type reference.
    pub fn void() -> Self {
        Self::simple("void")
    }

    /// Creates a union type reference.
    pub fn union(members: Vec<TypeReference>) -> Self {
        Self {
            name: String::new(),
            kind: TypeKind::Union,
            args: Vec::new(),
            members,
            value: None,
            nullable: None,
            reference: None,
            package: None,
            qualified_name: None,
        }
    }

    /// Creates a generic type reference.
    pub fn generic(name: impl Into<String>, args: Vec<TypeReference>) -> Self {
        Self {
            name: name.into(),
            kind: TypeKind::Generic,
            args,
            members: Vec::new(),
            value: None,
            nullable: None,
            reference: None,
            package: None,
            qualified_name: None,
        }
    }

    /// Makes this type nullable.
    pub fn nullable(mut self) -> Self {
        self.nullable = Some(true);
        self
    }

    /// Adds a reference to an internal entity.
    pub fn with_ref(mut self, reference: impl Into<String>) -> Self {
        self.reference = Some(reference.into());
        self
    }

    /// Adds an external package reference.
    pub fn external(
        mut self,
        package: impl Into<String>,
        qualified_name: impl Into<String>,
    ) -> Self {
        self.package = Some(package.into());
        self.qualified_name = Some(qualified_name.into());
        self
    }
}

/// Kind of type reference.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum TypeKind {
    /// Simple type (e.g., `String`, `number`).
    Simple,
    /// Generic type (e.g., `Array<T>`).
    Generic,
    /// Union type (e.g., `string | number`).
    Union,
    /// Intersection type (e.g., `A & B`).
    Intersection,
    /// Array type.
    Array,
    /// Tuple type.
    Tuple,
    /// Literal type (e.g., `"hello"`, `42`).
    Literal,
    /// Function type.
    Function,
    /// Unknown type.
    Unknown,
}

/// A function/method parameter.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Parameter {
    /// Parameter name.
    pub name: String,

    /// Parameter type.
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub param_type: Option<TypeReference>,

    /// Description.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,

    /// Default value.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub default: Option<String>,

    /// Whether optional.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub optional: Option<bool>,

    /// Whether this is a rest/splat parameter.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rest: Option<bool>,

    /// Hash/object options.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub options: Vec<OptionEntry>,
}

/// An entry in a Hash/object options parameter.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionEntry {
    /// Option key name.
    pub name: String,

    /// Option type.
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub option_type: Option<TypeReference>,

    /// Description.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,

    /// Whether required.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub required: Option<bool>,

    /// Default value.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub default: Option<String>,
}

/// An exception/error that can be thrown.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Throws {
    /// Exception type.
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub throw_type: Option<TypeReference>,

    /// Description.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
}

/// Block/callback parameter documentation.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct YieldBlock {
    /// Description.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,

    /// Block parameters.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub params: Vec<Parameter>,

    /// Return type.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub returns: Option<TypeReference>,
}

/// Generic type parameter.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TypeParameter {
    /// Parameter name.
    pub name: String,

    /// Constraint.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub constraint: Option<TypeReference>,

    /// Default type.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub default: Option<TypeReference>,

    /// Description.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
}

// =============================================================================
// Entity Types
// =============================================================================

/// A module/namespace.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Module {
    #[serde(flatten)]
    /// Base entity information.
    pub base: BaseEntity,

    /// Extended modules (Ruby).
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub extends: Vec<TypeReference>,

    /// Included modules (Ruby).
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub includes: Vec<TypeReference>,

    /// Functions.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub functions: Vec<Callable>,

    /// Properties.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub properties: Vec<Property>,

    /// Constants.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub constants: Vec<Constant>,

    /// Nested classes.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub classes: Vec<Class>,

    /// Nested modules.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub modules: Vec<Module>,

    /// Interfaces (TypeScript).
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub interfaces: Vec<Interface>,

    /// Type aliases (TypeScript).
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub types: Vec<TypeAlias>,

    /// Enums.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub enums: Vec<Enum>,

    /// Whether this is an ActiveSupport::Concern (Ruby).
    #[serde(rename = "isConcern", skip_serializing_if = "Option::is_none")]
    pub is_concern: Option<bool>,

    /// Instance methods (Ruby modules).
    #[serde(
        rename = "instanceMethods",
        skip_serializing_if = "Vec::is_empty",
        default
    )]
    pub instance_methods: Vec<Callable>,

    /// Class methods from ClassMethods module (Ruby concerns).
    #[serde(
        rename = "classMethods",
        skip_serializing_if = "Vec::is_empty",
        default
    )]
    pub class_methods: Vec<Callable>,
}

/// A class.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Class {
    #[serde(flatten)]
    /// Base entity information.
    pub base: BaseEntity,

    /// Parent class.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub extends: Option<TypeReference>,

    /// Implemented interfaces (TypeScript).
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub implements: Vec<TypeReference>,

    /// Included modules (Ruby).
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub includes: Vec<TypeReference>,

    /// Prepended modules (Ruby).
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub prepends: Vec<TypeReference>,

    /// Type parameters (TypeScript).
    #[serde(rename = "typeParams", skip_serializing_if = "Vec::is_empty", default)]
    pub type_params: Vec<TypeParameter>,

    /// Whether abstract.
    #[serde(rename = "abstract", skip_serializing_if = "Option::is_none")]
    pub is_abstract: Option<bool>,

    /// Constructor.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub constructor: Option<Box<Callable>>,

    /// Instance properties.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub properties: Vec<Property>,

    /// Instance methods.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub methods: Vec<Callable>,

    /// Static properties.
    #[serde(
        rename = "staticProperties",
        skip_serializing_if = "Vec::is_empty",
        default
    )]
    pub static_properties: Vec<Property>,

    /// Static methods.
    #[serde(
        rename = "staticMethods",
        skip_serializing_if = "Vec::is_empty",
        default
    )]
    pub static_methods: Vec<Callable>,

    /// Constants.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub constants: Vec<Constant>,

    /// Nested entities.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub nested: Vec<Entity>,
}

/// An interface (TypeScript).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Interface {
    #[serde(flatten)]
    /// Base entity information.
    pub base: BaseEntity,

    /// Extended interfaces.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub extends: Vec<TypeReference>,

    /// Type parameters.
    #[serde(rename = "typeParams", skip_serializing_if = "Vec::is_empty", default)]
    pub type_params: Vec<TypeParameter>,

    /// Properties.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub properties: Vec<Property>,

    /// Methods.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub methods: Vec<Callable>,

    /// Call signatures.
    #[serde(
        rename = "callSignatures",
        skip_serializing_if = "Vec::is_empty",
        default
    )]
    pub call_signatures: Vec<Callable>,

    /// Index signatures.
    #[serde(
        rename = "indexSignatures",
        skip_serializing_if = "Vec::is_empty",
        default
    )]
    pub index_signatures: Vec<IndexSignature>,
}

/// Index signature.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IndexSignature {
    /// Key type.
    #[serde(rename = "keyType", skip_serializing_if = "Option::is_none")]
    pub key_type: Option<TypeReference>,

    /// Value type.
    #[serde(rename = "valueType", skip_serializing_if = "Option::is_none")]
    pub value_type: Option<TypeReference>,

    /// Whether readonly.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub readonly: Option<bool>,
}

/// A type alias (TypeScript).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TypeAlias {
    #[serde(flatten)]
    /// Base entity information.
    pub base: BaseEntity,

    /// The aliased type.
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub aliased_type: Option<TypeReference>,

    /// Type parameters.
    #[serde(rename = "typeParams", skip_serializing_if = "Vec::is_empty", default)]
    pub type_params: Vec<TypeParameter>,
}

/// An enum.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Enum {
    #[serde(flatten)]
    /// Base entity information.
    pub base: BaseEntity,

    /// Enum members.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub members: Vec<EnumMember>,
}

/// An enum member.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnumMember {
    /// Member name.
    pub name: String,

    /// Member value.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value: Option<serde_json::Value>,

    /// Documentation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub docs: Option<Documentation>,
}

/// A callable (method, function, or constructor).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Callable {
    #[serde(flatten)]
    /// Base entity information.
    pub base: BaseEntity,

    /// Parameters.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub params: Vec<Parameter>,

    /// Return type.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub returns: Option<TypeReference>,

    /// Return description.
    #[serde(rename = "returnsDescription", skip_serializing_if = "Option::is_none")]
    pub returns_description: Option<String>,

    /// Exceptions that can be thrown.
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub throws: Vec<Throws>,

    /// Yield block.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub yields: Option<YieldBlock>,

    /// Whether async.
    #[serde(rename = "async", skip_serializing_if = "Option::is_none")]
    pub is_async: Option<bool>,

    /// Whether static.
    #[serde(rename = "static", skip_serializing_if = "Option::is_none")]
    pub is_static: Option<bool>,

    /// Whether abstract.
    #[serde(rename = "abstract", skip_serializing_if = "Option::is_none")]
    pub is_abstract: Option<bool>,

    /// Whether generator.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub generator: Option<bool>,

    /// Type parameters.
    #[serde(rename = "typeParams", skip_serializing_if = "Vec::is_empty", default)]
    pub type_params: Vec<TypeParameter>,

    /// Method overloads (TypeScript).
    #[serde(skip_serializing_if = "Vec::is_empty", default)]
    pub overloads: Vec<Callable>,
}

/// A property.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Property {
    #[serde(flatten)]
    /// Base entity information.
    pub base: BaseEntity,

    /// Property type.
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub prop_type: Option<TypeReference>,

    /// Default value.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub default: Option<String>,

    /// Whether readonly.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub readonly: Option<bool>,

    /// Whether static.
    #[serde(rename = "static", skip_serializing_if = "Option::is_none")]
    pub is_static: Option<bool>,

    /// Whether optional.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub optional: Option<bool>,

    /// Whether this property has a getter accessor.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub getter: Option<bool>,

    /// Whether this property has a setter accessor.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub setter: Option<bool>,
}

/// A constant.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Constant {
    #[serde(flatten)]
    /// Base entity information.
    pub base: BaseEntity,

    /// Constant type.
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub const_type: Option<TypeReference>,

    /// String representation of the value.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value: Option<String>,
}