synthra 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +4 -0
  3. data/.rubocop.yml +40 -0
  4. data/.yardopts +18 -0
  5. data/ACCESS_DOCS.md +116 -0
  6. data/ADVANCED_FEATURES_SUMMARY.md +245 -0
  7. data/CHANGELOG.md +498 -0
  8. data/CODE_OF_CONDUCT.md +122 -0
  9. data/CONTRIBUTING.md +307 -0
  10. data/DOCUMENTATION.md +204 -0
  11. data/DOCUMENTATION_GUIDE.md +194 -0
  12. data/LICENSE +22 -0
  13. data/README.md +1458 -0
  14. data/Rakefile +128 -0
  15. data/benchmark/README.md +591 -0
  16. data/benchmark/batch_generation.rb +63 -0
  17. data/benchmark/engine_comparison.rb +295 -0
  18. data/benchmark/single_record.rb +108 -0
  19. data/benchmark/streaming.rb +74 -0
  20. data/docs/ACTIVERECORD_INFERENCE.md +524 -0
  21. data/docs/API_SERVER.md +278 -0
  22. data/docs/CONFIG_FILE.md +315 -0
  23. data/docs/DATA_CONTRACTS.md +312 -0
  24. data/docs/ENHANCED_REPL.md +304 -0
  25. data/docs/FACTORY_BOT.md +271 -0
  26. data/docs/GITHUB_ACTION.md +420 -0
  27. data/docs/GRAPHQL_EXPORT.md +303 -0
  28. data/docs/GRAPHQL_FEDERATION.md +651 -0
  29. data/docs/HOW_TO_GENERATE_DOCS.md +252 -0
  30. data/docs/LSP.md +189 -0
  31. data/docs/MIGRATION_GENERATOR.md +547 -0
  32. data/docs/MOCK_SERVER.md +280 -0
  33. data/docs/NATIVE_ENGINE.md +298 -0
  34. data/docs/OPENAPI_EXPORT.md +252 -0
  35. data/docs/PERFORMANCE_MODE.md +228 -0
  36. data/docs/PERSONAS.md +547 -0
  37. data/docs/PROPERTY_TESTING.md +284 -0
  38. data/docs/PROTOBUF_EXPORT.md +276 -0
  39. data/docs/QUALITY_METRICS.md +555 -0
  40. data/docs/QUICK_REFERENCE.md +88 -0
  41. data/docs/RAILS_ENGINE.md +404 -0
  42. data/docs/RAILS_INTEGRATION.md +454 -0
  43. data/docs/README.md +175 -0
  44. data/docs/REPL_QUICK_REFERENCE.md +149 -0
  45. data/docs/RUST_INTEGRATION_GUIDE.md +1376 -0
  46. data/docs/SCENARIOS.md +576 -0
  47. data/docs/SECURITY_TESTING.md +318 -0
  48. data/docs/SNAPSHOT_TESTING.md +308 -0
  49. data/docs/STRING_TEXT_TYPES_REFERENCE.md +512 -0
  50. data/docs/TERRAFORM_EXPORT.md +447 -0
  51. data/docs/TIME_TRAVEL.md +507 -0
  52. data/docs/USAGE_GUIDE.md +980 -0
  53. data/docs/WEBHOOK_SIMULATOR.md +579 -0
  54. data/docs/advanced_features.md +183 -0
  55. data/docs/api_reference.md +153 -0
  56. data/docs/behaviors.md +138 -0
  57. data/docs/best_practices.md +191 -0
  58. data/docs/dsl_reference.md +172 -0
  59. data/docs/examples.md +162 -0
  60. data/docs/generation_modes.md +125 -0
  61. data/docs/getting_started.md +92 -0
  62. data/docs/index.html +177 -0
  63. data/docs/strategic/CLOUD_REGISTRY_ARCHITECTURE.md +268 -0
  64. data/docs/strategic/SIMD_OPTIMIZATION_STRATEGY.md +153 -0
  65. data/docs/troubleshooting.md +215 -0
  66. data/docs/type_reference.md +224 -0
  67. data/examples/hostile_mode_demo.rb +64 -0
  68. data/exe/synthra +6 -0
  69. data/ext/synthra_native/Cargo.lock +972 -0
  70. data/ext/synthra_native/Cargo.toml +46 -0
  71. data/ext/synthra_native/extconf.rb +41 -0
  72. data/ext/synthra_native/src/generator.rs +397 -0
  73. data/ext/synthra_native/src/lib.rs +229 -0
  74. data/ext/synthra_native/src/types.rs +1485 -0
  75. data/lib/generators/synthra/install_generator.rb +86 -0
  76. data/lib/generators/synthra/templates/api_response.dsl +15 -0
  77. data/lib/generators/synthra/templates/fake_data.rake +116 -0
  78. data/lib/generators/synthra/templates/synthra.yml +31 -0
  79. data/lib/generators/synthra/templates/synthra_support.rb +19 -0
  80. data/lib/generators/synthra/templates/user.dsl +11 -0
  81. data/lib/synthra/activerecord_inference.rb +394 -0
  82. data/lib/synthra/api.rb +381 -0
  83. data/lib/synthra/api_server.rb +718 -0
  84. data/lib/synthra/behaviors/applicator.rb +165 -0
  85. data/lib/synthra/behaviors/base.rb +155 -0
  86. data/lib/synthra/behaviors/close_connection.rb +60 -0
  87. data/lib/synthra/behaviors/deprecated.rb +100 -0
  88. data/lib/synthra/behaviors/failure.rb +69 -0
  89. data/lib/synthra/behaviors/latency.rb +103 -0
  90. data/lib/synthra/behaviors/partial_data.rb +83 -0
  91. data/lib/synthra/behaviors/randomize_order.rb +74 -0
  92. data/lib/synthra/behaviors/registry.rb +238 -0
  93. data/lib/synthra/behaviors/simulate_error.rb +79 -0
  94. data/lib/synthra/cli/commands/base.rb +105 -0
  95. data/lib/synthra/cli/commands/diff.rb +227 -0
  96. data/lib/synthra/cli/commands/docs.rb +67 -0
  97. data/lib/synthra/cli/commands/export.rb +150 -0
  98. data/lib/synthra/cli/commands/generate.rb +72 -0
  99. data/lib/synthra/cli/commands/import.rb +80 -0
  100. data/lib/synthra/cli/commands/lint.rb +53 -0
  101. data/lib/synthra/cli/commands/live.rb +57 -0
  102. data/lib/synthra/cli/commands/seed.rb +99 -0
  103. data/lib/synthra/cli/commands/validate.rb +28 -0
  104. data/lib/synthra/cli.rb +2471 -0
  105. data/lib/synthra/config_file.rb +129 -0
  106. data/lib/synthra/configuration.rb +281 -0
  107. data/lib/synthra/contracts_registry.rb +408 -0
  108. data/lib/synthra/database_seeder.rb +268 -0
  109. data/lib/synthra/deterministic_ids.rb +218 -0
  110. data/lib/synthra/documentation_generator.rb +414 -0
  111. data/lib/synthra/engine.rb +251 -0
  112. data/lib/synthra/errors.rb +1169 -0
  113. data/lib/synthra/export/base.rb +85 -0
  114. data/lib/synthra/export/csv.rb +101 -0
  115. data/lib/synthra/export/graphql.rb +266 -0
  116. data/lib/synthra/export/graphql_federation.rb +377 -0
  117. data/lib/synthra/export/graphviz.rb +258 -0
  118. data/lib/synthra/export/javascript.rb +327 -0
  119. data/lib/synthra/export/json_data.rb +61 -0
  120. data/lib/synthra/export/json_schema.rb +290 -0
  121. data/lib/synthra/export/openapi.rb +514 -0
  122. data/lib/synthra/export/protobuf.rb +483 -0
  123. data/lib/synthra/export/python.rb +560 -0
  124. data/lib/synthra/export/sql.rb +381 -0
  125. data/lib/synthra/export/sql_insert.rb +152 -0
  126. data/lib/synthra/export/terraform.rb +501 -0
  127. data/lib/synthra/export/type_mapping.rb +389 -0
  128. data/lib/synthra/export/typescript.rb +300 -0
  129. data/lib/synthra/export/xml_data.rb +104 -0
  130. data/lib/synthra/export/yaml_data.rb +56 -0
  131. data/lib/synthra/export.rb +404 -0
  132. data/lib/synthra/factory_bot_integration.rb +157 -0
  133. data/lib/synthra/field.rb +440 -0
  134. data/lib/synthra/functions/registry.rb +104 -0
  135. data/lib/synthra/generator/context.rb +372 -0
  136. data/lib/synthra/generator/engine.rb +336 -0
  137. data/lib/synthra/generator/faker_adapter.rb +425 -0
  138. data/lib/synthra/generator/modes.rb +444 -0
  139. data/lib/synthra/generator/resolver.rb +256 -0
  140. data/lib/synthra/generator/rng.rb +273 -0
  141. data/lib/synthra/generator/streamer.rb +63 -0
  142. data/lib/synthra/generator/uniqueness.rb +118 -0
  143. data/lib/synthra/initializer.rb +97 -0
  144. data/lib/synthra/limits.rb +279 -0
  145. data/lib/synthra/live_preview.rb +518 -0
  146. data/lib/synthra/loader_config.rb +78 -0
  147. data/lib/synthra/lsp/server.rb +689 -0
  148. data/lib/synthra/migration_generator.rb +301 -0
  149. data/lib/synthra/mixin.rb +174 -0
  150. data/lib/synthra/mock_server.rb +458 -0
  151. data/lib/synthra/native_engine.rb +304 -0
  152. data/lib/synthra/openapi_importer.rb +228 -0
  153. data/lib/synthra/output/json_formatter.rb +40 -0
  154. data/lib/synthra/output/ndjson_formatter.rb +55 -0
  155. data/lib/synthra/parser/ast.rb +1287 -0
  156. data/lib/synthra/parser/lexer.rb +1152 -0
  157. data/lib/synthra/parser/parser.rb +1664 -0
  158. data/lib/synthra/parser/tokens.rb +461 -0
  159. data/lib/synthra/performance_mode.rb +364 -0
  160. data/lib/synthra/personas.rb +397 -0
  161. data/lib/synthra/property_testing.rb +172 -0
  162. data/lib/synthra/quality_metrics.rb +405 -0
  163. data/lib/synthra/rails_test_helper.rb +248 -0
  164. data/lib/synthra/registry.rb +533 -0
  165. data/lib/synthra/relationships.rb +193 -0
  166. data/lib/synthra/repl/enhanced_repl.rb +607 -0
  167. data/lib/synthra/repl/formatter.rb +191 -0
  168. data/lib/synthra/scenarios.rb +423 -0
  169. data/lib/synthra/schema.rb +605 -0
  170. data/lib/synthra/schema_inheritance.rb +104 -0
  171. data/lib/synthra/schema_versioning.rb +212 -0
  172. data/lib/synthra/snapshot_testing.rb +199 -0
  173. data/lib/synthra/time_travel.rb +338 -0
  174. data/lib/synthra/type_definitions.rb +274 -0
  175. data/lib/synthra/types/address_location/addresses.rb +125 -0
  176. data/lib/synthra/types/address_location/airports.rb +200 -0
  177. data/lib/synthra/types/address_location/banks_hospitals.rb +207 -0
  178. data/lib/synthra/types/address_location/locations.rb +406 -0
  179. data/lib/synthra/types/base.rb +48 -0
  180. data/lib/synthra/types/commerce_products/commerce.rb +119 -0
  181. data/lib/synthra/types/commerce_products/companies.rb +71 -0
  182. data/lib/synthra/types/commerce_products/construction.rb +126 -0
  183. data/lib/synthra/types/commerce_products/products.rb +205 -0
  184. data/lib/synthra/types/core/collections.rb +513 -0
  185. data/lib/synthra/types/core/defaults.rb +76 -0
  186. data/lib/synthra/types/core/enums.rb +102 -0
  187. data/lib/synthra/types/core/identifiers.rb +445 -0
  188. data/lib/synthra/types/core/primitives.rb +586 -0
  189. data/lib/synthra/types/core/references.rb +466 -0
  190. data/lib/synthra/types/core/sequences.rb +304 -0
  191. data/lib/synthra/types/crypto/crypto.rb +162 -0
  192. data/lib/synthra/types/date_time/dates.rb +387 -0
  193. data/lib/synthra/types/finance_banking/banking.rb +424 -0
  194. data/lib/synthra/types/finance_banking/credit_cards.rb +24 -0
  195. data/lib/synthra/types/finance_banking/identifiers.rb +93 -0
  196. data/lib/synthra/types/formula.rb +184 -0
  197. data/lib/synthra/types/health_medical/medical.rb +150 -0
  198. data/lib/synthra/types/hostile_payloads.rb +122 -0
  199. data/lib/synthra/types/json_array.rb +51 -0
  200. data/lib/synthra/types/media_entertainment/media.rb +62 -0
  201. data/lib/synthra/types/naughty_string.rb +30 -0
  202. data/lib/synthra/types/personal_names/chinese.rb +41 -0
  203. data/lib/synthra/types/personal_names/identifiers.rb +187 -0
  204. data/lib/synthra/types/personal_names/names.rb +246 -0
  205. data/lib/synthra/types/personal_names/national_id.rb +89 -0
  206. data/lib/synthra/types/personal_names/titles_suffixes.rb +41 -0
  207. data/lib/synthra/types/regex.rb +248 -0
  208. data/lib/synthra/types/registry.rb +182 -0
  209. data/lib/synthra/types/repeating_element.rb +50 -0
  210. data/lib/synthra/types/scenario.rb +29 -0
  211. data/lib/synthra/types/technology_internet/apps.rb +67 -0
  212. data/lib/synthra/types/technology_internet/communication.rb +162 -0
  213. data/lib/synthra/types/technology_internet/devices.rb +80 -0
  214. data/lib/synthra/types/technology_internet/formats.rb +139 -0
  215. data/lib/synthra/types/technology_internet/networking.rb +143 -0
  216. data/lib/synthra/types/template.rb +92 -0
  217. data/lib/synthra/types/text_content/business.rb +128 -0
  218. data/lib/synthra/types/text_content/colors.rb +70 -0
  219. data/lib/synthra/types/text_content/misc.rb +237 -0
  220. data/lib/synthra/types/text_content/security.rb +130 -0
  221. data/lib/synthra/types/text_content/text_generation.rb +532 -0
  222. data/lib/synthra/types/travel/travel.rb +150 -0
  223. data/lib/synthra/utils/string_distance.rb +133 -0
  224. data/lib/synthra/validator/dsl_validator.rb +339 -0
  225. data/lib/synthra/validator/path_validator.rb +615 -0
  226. data/lib/synthra/version.rb +35 -0
  227. data/lib/synthra/webhook_simulator.rb +341 -0
  228. data/lib/synthra.rb +259 -0
  229. data/schemas/address.dsl +16 -0
  230. data/schemas/api_response.dsl +8 -0
  231. data/schemas/error_payload.dsl +9 -0
  232. data/schemas/order.dsl +10 -0
  233. data/schemas/order_item.dsl +8 -0
  234. data/schemas/payment.dsl +11 -0
  235. data/schemas/social_post.dsl +13 -0
  236. data/schemas/user.dsl +10 -0
  237. data/scripts/batch_fix_all.rb +96 -0
  238. data/scripts/delete_old_files.rb +32 -0
  239. data/scripts/fix_all_grouped_files.rb +137 -0
  240. data/scripts/fix_all_indentation.rb +48 -0
  241. data/scripts/fix_all_syntax.rb +124 -0
  242. data/scripts/fix_grouped_files.rb +184 -0
  243. data/scripts/fix_syntax_errors.rb +108 -0
  244. data/scripts/group_domain_types.rb +112 -0
  245. data/scripts/group_domain_types_fixed.rb +150 -0
  246. data/scripts/merge_domains_to_one_file.rb +68 -0
  247. data/scripts/move_existing_types.rb +130 -0
  248. data/scripts/split_grouped_types.rb +142 -0
  249. data/tech_docs/README.md +134 -0
  250. data/tech_docs/advanced/streaming.md +405 -0
  251. data/tech_docs/advanced/thread_safety.md +253 -0
  252. data/tech_docs/api/overview.md +485 -0
  253. data/tech_docs/appendices/type_chart.md +193 -0
  254. data/tech_docs/basic_concepts.md +383 -0
  255. data/tech_docs/behaviors/overview.md +346 -0
  256. data/tech_docs/dsl/complex_types.md +790 -0
  257. data/tech_docs/dsl/core_types.md +464 -0
  258. data/tech_docs/dsl/datetime_types.md +325 -0
  259. data/tech_docs/dsl/field_modifiers.md +414 -0
  260. data/tech_docs/dsl/grammar.md +431 -0
  261. data/tech_docs/dsl/schema_definition.md +399 -0
  262. data/tech_docs/export/README.md +276 -0
  263. data/tech_docs/installation.md +273 -0
  264. data/tech_docs/integration/ci_cd.md +707 -0
  265. data/tech_docs/integration/ci_cd_guide.md +579 -0
  266. data/tech_docs/integration/factory_bot.md +485 -0
  267. data/tech_docs/integration/rails.md +630 -0
  268. data/tech_docs/integration/rspec.md +449 -0
  269. data/tech_docs/modes/overview.md +350 -0
  270. data/tech_docs/performance/NATIVE_RUST_EXTENSION.md +1270 -0
  271. data/tech_docs/performance/OPTIMIZATION_GUIDE.md +901 -0
  272. data/tech_docs/quick_start.md +256 -0
  273. data/tech_docs/templates/README.md +805 -0
  274. data/tech_docs/tutorials/advanced.md +371 -0
  275. data/tech_docs/tutorials/getting_started.md +189 -0
  276. data/tech_docs/tutorials/intermediate.md +231 -0
  277. data/tech_docs/tutorials/template_gallery.md +569 -0
  278. data/tech_example/01_basic_usage.rb +238 -0
  279. data/tech_example/02_types_demo.rb +336 -0
  280. data/tech_example/04_cli_usage.md +429 -0
  281. data/tech_example/05_database_seeding.rb +283 -0
  282. data/tech_example/07_rspec_integration.rb +359 -0
  283. data/tech_example/10_custom_types.rb +387 -0
  284. data/tech_example/12_behaviors.rb +372 -0
  285. data/tech_example/13_twitter_dm_example.rb +120 -0
  286. data/tech_example/14_exact_json_structure.rb +253 -0
  287. data/tech_example/16_lsp_server.rb +56 -0
  288. data/tech_example/17_property_testing.rb +92 -0
  289. data/tech_example/18_enhanced_repl.rb +120 -0
  290. data/tech_example/19_security_fuzzing.rb +145 -0
  291. data/tech_example/NEW_FEATURES.md +169 -0
  292. data/tech_example/README.md +118 -0
  293. data/tech_example/schemas/api_response.dsl +123 -0
  294. data/tech_example/schemas/ecommerce.dsl +121 -0
  295. data/tech_example/schemas/twitter_dm.dsl +109 -0
  296. data/tech_example/schemas/user.dsl +36 -0
  297. data/vscode-extension/README.md +246 -0
  298. data/vscode-extension/language-configuration.json +31 -0
  299. data/vscode-extension/package.json +55 -0
  300. data/vscode-extension/snippets/fakedatadsl.json +198 -0
  301. data/vscode-extension/syntaxes/fakedatadsl.tmLanguage.json +128 -0
  302. metadata +478 -0
@@ -0,0 +1,271 @@
1
+ # Factory Bot Integration
2
+
3
+ FakeDataDSL integrates seamlessly with [Factory Bot](https://github.com/thoughtbot/factory_bot) to provide powerful test data generation with the simplicity of Factory Bot's DSL.
4
+
5
+ ## Quick Start
6
+
7
+ ### 1. Define a Factory
8
+
9
+ ```ruby
10
+ # spec/factories.rb or spec/support/fake_data_factories.rb
11
+ require 'fake_data_dsl'
12
+
13
+ FakeDataDSL.define_factory(:user, schema: "User") do
14
+ trait(:admin) do
15
+ role { "admin" }
16
+ end
17
+
18
+ trait(:inactive) do
19
+ active { false }
20
+ end
21
+
22
+ trait(:with_address) do
23
+ address { FakeDataDSL.generate("Address") }
24
+ end
25
+ end
26
+ ```
27
+
28
+ ### 2. Use in Tests
29
+
30
+ ```ruby
31
+ # spec/models/user_spec.rb
32
+ RSpec.describe User do
33
+ it "creates a valid user" do
34
+ user = create(:user)
35
+ expect(user).to be_valid
36
+ end
37
+
38
+ it "creates an admin user" do
39
+ admin = create(:user, :admin)
40
+ expect(admin.role).to eq("admin")
41
+ end
42
+
43
+ it "accepts field overrides" do
44
+ user = create(:user, name: "Custom Name", email: "custom@example.com")
45
+ expect(user.name).to eq("Custom Name")
46
+ end
47
+ end
48
+ ```
49
+
50
+ ## RSpec Helpers
51
+
52
+ ### Setup
53
+
54
+ ```ruby
55
+ # spec/spec_helper.rb
56
+ require 'fake_data_dsl'
57
+ require 'fake_data_dsl/factory_bot_integration'
58
+
59
+ RSpec.configure do |config|
60
+ config.include FakeDataDSL::FactoryBotIntegration::RSpec
61
+ end
62
+ ```
63
+
64
+ ### Available Helpers
65
+
66
+ ```ruby
67
+ # Build data without creating records
68
+ user_data = fake_data_build(:user)
69
+ user_data = build_fake_data(:user) # Alias
70
+
71
+ # With traits
72
+ admin_data = fake_data_build(:user, :admin)
73
+
74
+ # With overrides
75
+ custom_data = fake_data_build(:user, :admin, name: "Jane Doe")
76
+ ```
77
+
78
+ ## Defining Factories
79
+
80
+ ### Basic Factory
81
+
82
+ ```ruby
83
+ FakeDataDSL.define_factory(:user, schema: "User")
84
+ ```
85
+
86
+ ### Factory with Traits
87
+
88
+ ```ruby
89
+ FakeDataDSL.define_factory(:user, schema: "User") do
90
+ trait(:admin) do
91
+ role { "admin" }
92
+ permissions { ["read", "write", "delete"] }
93
+ end
94
+
95
+ trait(:guest) do
96
+ role { "guest" }
97
+ permissions { ["read"] }
98
+ end
99
+
100
+ trait(:verified) do
101
+ email_verified { true }
102
+ phone_verified { true }
103
+ end
104
+ end
105
+ ```
106
+
107
+ ### Combining Traits
108
+
109
+ ```ruby
110
+ # Traits can be combined
111
+ create(:user, :admin, :verified)
112
+ create(:user, :guest, name: "Anonymous")
113
+ ```
114
+
115
+ ## Schema Requirements
116
+
117
+ Your DSL schemas should be loaded before defining factories:
118
+
119
+ ```ruby
120
+ # Load schemas first
121
+ FakeDataDSL.load_schemas("schemas/")
122
+
123
+ # Then define factories
124
+ FakeDataDSL.define_factory(:user, schema: "User")
125
+ FakeDataDSL.define_factory(:order, schema: "Order")
126
+ ```
127
+
128
+ ### Example Schema
129
+
130
+ ```
131
+ # schemas/user.dsl
132
+ User:
133
+ id: uuid
134
+ name: name
135
+ email: email
136
+ role: enum(user, admin, moderator)
137
+ active: boolean(true:90%)
138
+ created_at: timestamp
139
+ ```
140
+
141
+ ## Advanced Usage
142
+
143
+ ### Custom Factory Logic
144
+
145
+ ```ruby
146
+ FakeDataDSL.define_factory(:user, schema: "User") do
147
+ trait(:with_orders) do
148
+ orders {
149
+ 3.times.map { FakeDataDSL::FactoryBotIntegration.build(:order) }
150
+ }
151
+ end
152
+ end
153
+ ```
154
+
155
+ ### Sequence Support
156
+
157
+ ```ruby
158
+ FakeDataDSL.define_factory(:user, schema: "User") do
159
+ trait(:numbered) do
160
+ # Use schema's built-in sequence type
161
+ # or override with custom sequence
162
+ id { |n| "user_#{n}" }
163
+ end
164
+ end
165
+ ```
166
+
167
+ ### Dependent Attributes
168
+
169
+ ```ruby
170
+ FakeDataDSL.define_factory(:user, schema: "User") do
171
+ trait(:consistent_name) do
172
+ first_name { "John" }
173
+ last_name { "Doe" }
174
+ email { "john.doe@example.com" }
175
+ end
176
+ end
177
+ ```
178
+
179
+ ## Integration with Factory Bot (Optional)
180
+
181
+ If Factory Bot is already installed, factories are automatically registered:
182
+
183
+ ```ruby
184
+ # This just works if Factory Bot is available
185
+ FactoryBot.create(:user)
186
+ FactoryBot.create(:user, :admin)
187
+ FactoryBot.build_list(:user, 10)
188
+ ```
189
+
190
+ ## Best Practices
191
+
192
+ ### 1. Organize Factories by Domain
193
+
194
+ ```ruby
195
+ # spec/support/factories/users.rb
196
+ FakeDataDSL.define_factory(:user, schema: "User") { ... }
197
+ FakeDataDSL.define_factory(:admin_user, schema: "AdminUser") { ... }
198
+
199
+ # spec/support/factories/orders.rb
200
+ FakeDataDSL.define_factory(:order, schema: "Order") { ... }
201
+ FakeDataDSL.define_factory(:order_item, schema: "OrderItem") { ... }
202
+ ```
203
+
204
+ ### 2. Use Traits for Common Scenarios
205
+
206
+ ```ruby
207
+ FakeDataDSL.define_factory(:user, schema: "User") do
208
+ # State traits
209
+ trait(:active) { active { true } }
210
+ trait(:inactive) { active { false } }
211
+
212
+ # Role traits
213
+ trait(:admin) { role { "admin" } }
214
+ trait(:guest) { role { "guest" } }
215
+
216
+ # Feature traits
217
+ trait(:with_2fa) { two_factor_enabled { true } }
218
+ trait(:premium) { subscription_tier { "premium" } }
219
+ end
220
+ ```
221
+
222
+ ### 3. Keep Factories DRY
223
+
224
+ ```ruby
225
+ # Base user factory
226
+ FakeDataDSL.define_factory(:user, schema: "User")
227
+
228
+ # Specialized factories inherit behavior
229
+ FakeDataDSL.define_factory(:admin, schema: "AdminUser") do
230
+ trait(:super_admin) { permissions { ["all"] } }
231
+ end
232
+ ```
233
+
234
+ ## Troubleshooting
235
+
236
+ ### Factory Not Found
237
+
238
+ ```ruby
239
+ # Error: Unknown factory: :user
240
+
241
+ # Solution: Ensure factory is defined before use
242
+ FakeDataDSL.define_factory(:user, schema: "User")
243
+ ```
244
+
245
+ ### Schema Not Found
246
+
247
+ ```ruby
248
+ # Error: Unknown schema: User
249
+
250
+ # Solution: Load schemas before defining factories
251
+ FakeDataDSL.load_schemas("schemas/")
252
+ FakeDataDSL.define_factory(:user, schema: "User")
253
+ ```
254
+
255
+ ### Trait Overrides Not Working
256
+
257
+ ```ruby
258
+ # Traits should return hashes or use block syntax
259
+ trait(:admin) do
260
+ role { "admin" } # Correct: block syntax
261
+ end
262
+
263
+ # Not: role: "admin" # This won't work as expected
264
+ ```
265
+
266
+ ## See Also
267
+
268
+ - [Quick Start Guide](../tech_docs/quick_start.md)
269
+ - [Schema Definition](../tech_docs/dsl/schema_definition.md)
270
+ - [Property-Based Testing](PROPERTY_TESTING.md)
271
+ - [RSpec Integration](../tech_example/07_rspec_integration.rb)
@@ -0,0 +1,420 @@
1
+ # GitHub Action
2
+
3
+ FakeDataDSL provides a **reusable GitHub Action** for CI/CD pipelines. Validate schemas, generate data, run diff checks, and more directly in your workflows.
4
+
5
+ ## Quick Start
6
+
7
+ ```yaml
8
+ # .github/workflows/schemas.yml
9
+ name: Schema Validation
10
+
11
+ on: [push, pull_request]
12
+
13
+ jobs:
14
+ validate:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - uses: fake-data-dsl/action@v1
20
+ with:
21
+ command: validate
22
+ schema_dir: schemas/
23
+ ```
24
+
25
+ ## Available Commands
26
+
27
+ ### validate
28
+
29
+ Validate all schemas for syntax errors:
30
+
31
+ ```yaml
32
+ - uses: fake-data-dsl/action@v1
33
+ with:
34
+ command: validate
35
+ schema_dir: schemas/
36
+ strict: true # Fail on warnings too
37
+ ```
38
+
39
+ ### lint
40
+
41
+ Run linter checks on schemas:
42
+
43
+ ```yaml
44
+ - uses: fake-data-dsl/action@v1
45
+ with:
46
+ command: lint
47
+ schema_dir: schemas/
48
+ config: .fake_data_dsl.yml
49
+ ```
50
+
51
+ ### diff
52
+
53
+ Check for breaking changes between schema versions:
54
+
55
+ ```yaml
56
+ - uses: fake-data-dsl/action@v1
57
+ with:
58
+ command: diff
59
+ base_ref: ${{ github.base_ref }}
60
+ head_ref: ${{ github.head_ref }}
61
+ schema_dir: schemas/
62
+ breaking_only: true
63
+ ```
64
+
65
+ ### generate
66
+
67
+ Generate sample data for testing:
68
+
69
+ ```yaml
70
+ - uses: fake-data-dsl/action@v1
71
+ with:
72
+ command: generate
73
+ schema: User
74
+ count: 100
75
+ output: test_data/users.json
76
+ seed: 42
77
+ ```
78
+
79
+ ### export
80
+
81
+ Export schemas to other formats:
82
+
83
+ ```yaml
84
+ - uses: fake-data-dsl/action@v1
85
+ with:
86
+ command: export
87
+ schema_dir: schemas/
88
+ format: openapi
89
+ output: docs/openapi.yaml
90
+ ```
91
+
92
+ ### test
93
+
94
+ Run schema-related tests:
95
+
96
+ ```yaml
97
+ - uses: fake-data-dsl/action@v1
98
+ with:
99
+ command: test
100
+ schema_dir: schemas/
101
+ test_dir: spec/schemas/
102
+ ```
103
+
104
+ ## Input Parameters
105
+
106
+ | Input | Description | Default |
107
+ |-------|-------------|---------|
108
+ | `command` | Command to run | `validate` |
109
+ | `schema_dir` | Schema directory | `schemas/` |
110
+ | `schema` | Specific schema name | - |
111
+ | `config` | Config file path | `.fake_data_dsl.yml` |
112
+ | `output` | Output file path | - |
113
+ | `format` | Export format | - |
114
+ | `count` | Number of records | `10` |
115
+ | `seed` | Random seed | - |
116
+ | `mode` | Generation mode | `random` |
117
+ | `strict` | Strict validation | `false` |
118
+ | `breaking_only` | Only report breaking changes | `false` |
119
+ | `base_ref` | Base Git ref for diff | - |
120
+ | `head_ref` | Head Git ref for diff | - |
121
+ | `ruby_version` | Ruby version | `3.2` |
122
+
123
+ ## Output Variables
124
+
125
+ | Output | Description |
126
+ |--------|-------------|
127
+ | `valid` | Whether schemas are valid |
128
+ | `warnings` | Number of warnings |
129
+ | `errors` | Number of errors |
130
+ | `breaking_changes` | Number of breaking changes |
131
+ | `generated_file` | Path to generated file |
132
+
133
+ ## Examples
134
+
135
+ ### Complete CI Workflow
136
+
137
+ ```yaml
138
+ name: Schema CI
139
+
140
+ on:
141
+ push:
142
+ branches: [main]
143
+ pull_request:
144
+ paths:
145
+ - 'schemas/**'
146
+ - '.github/workflows/schemas.yml'
147
+
148
+ jobs:
149
+ validate:
150
+ runs-on: ubuntu-latest
151
+ steps:
152
+ - uses: actions/checkout@v4
153
+
154
+ - name: Validate Schemas
155
+ uses: fake-data-dsl/action@v1
156
+ with:
157
+ command: validate
158
+ schema_dir: schemas/
159
+ strict: true
160
+
161
+ lint:
162
+ runs-on: ubuntu-latest
163
+ steps:
164
+ - uses: actions/checkout@v4
165
+
166
+ - name: Lint Schemas
167
+ uses: fake-data-dsl/action@v1
168
+ with:
169
+ command: lint
170
+ schema_dir: schemas/
171
+
172
+ breaking-changes:
173
+ runs-on: ubuntu-latest
174
+ if: github.event_name == 'pull_request'
175
+ steps:
176
+ - uses: actions/checkout@v4
177
+ with:
178
+ fetch-depth: 0
179
+
180
+ - name: Check Breaking Changes
181
+ id: diff
182
+ uses: fake-data-dsl/action@v1
183
+ with:
184
+ command: diff
185
+ schema_dir: schemas/
186
+ base_ref: ${{ github.base_ref }}
187
+ head_ref: ${{ github.head_ref }}
188
+ breaking_only: true
189
+
190
+ - name: Comment on PR
191
+ if: steps.diff.outputs.breaking_changes > 0
192
+ uses: actions/github-script@v6
193
+ with:
194
+ script: |
195
+ github.rest.issues.createComment({
196
+ issue_number: context.issue.number,
197
+ owner: context.repo.owner,
198
+ repo: context.repo.repo,
199
+ body: '⚠️ Breaking schema changes detected!'
200
+ })
201
+
202
+ generate-docs:
203
+ runs-on: ubuntu-latest
204
+ needs: [validate, lint]
205
+ if: github.ref == 'refs/heads/main'
206
+ steps:
207
+ - uses: actions/checkout@v4
208
+
209
+ - name: Generate OpenAPI
210
+ uses: fake-data-dsl/action@v1
211
+ with:
212
+ command: export
213
+ schema_dir: schemas/
214
+ format: openapi
215
+ output: docs/api/openapi.yaml
216
+
217
+ - name: Generate TypeScript Types
218
+ uses: fake-data-dsl/action@v1
219
+ with:
220
+ command: export
221
+ schema_dir: schemas/
222
+ format: typescript
223
+ output: frontend/src/types/schemas.ts
224
+
225
+ - name: Commit Generated Files
226
+ uses: stefanzweifel/git-auto-commit-action@v5
227
+ with:
228
+ commit_message: "chore: regenerate schema exports"
229
+ file_pattern: "docs/api/* frontend/src/types/*"
230
+ ```
231
+
232
+ ### Generate Test Data
233
+
234
+ ```yaml
235
+ name: Generate Test Data
236
+
237
+ on:
238
+ workflow_dispatch:
239
+ inputs:
240
+ schema:
241
+ description: 'Schema name'
242
+ required: true
243
+ count:
244
+ description: 'Number of records'
245
+ default: '1000'
246
+
247
+ jobs:
248
+ generate:
249
+ runs-on: ubuntu-latest
250
+ steps:
251
+ - uses: actions/checkout@v4
252
+
253
+ - name: Generate Data
254
+ uses: fake-data-dsl/action@v1
255
+ with:
256
+ command: generate
257
+ schema: ${{ inputs.schema }}
258
+ count: ${{ inputs.count }}
259
+ output: test_data/${{ inputs.schema }}.json
260
+ seed: 42
261
+
262
+ - name: Upload Artifact
263
+ uses: actions/upload-artifact@v4
264
+ with:
265
+ name: test-data
266
+ path: test_data/
267
+ ```
268
+
269
+ ### Schema Release
270
+
271
+ ```yaml
272
+ name: Schema Release
273
+
274
+ on:
275
+ push:
276
+ tags:
277
+ - 'schema-v*'
278
+
279
+ jobs:
280
+ release:
281
+ runs-on: ubuntu-latest
282
+ steps:
283
+ - uses: actions/checkout@v4
284
+
285
+ - name: Validate
286
+ uses: fake-data-dsl/action@v1
287
+ with:
288
+ command: validate
289
+ schema_dir: schemas/
290
+ strict: true
291
+
292
+ - name: Export All Formats
293
+ uses: fake-data-dsl/action@v1
294
+ with:
295
+ command: export
296
+ schema_dir: schemas/
297
+ format: all
298
+ output: dist/
299
+
300
+ - name: Create Release
301
+ uses: softprops/action-gh-release@v1
302
+ with:
303
+ files: |
304
+ dist/openapi.yaml
305
+ dist/schemas.ts
306
+ dist/schemas.proto
307
+ dist/schemas.json
308
+ ```
309
+
310
+ ## Configuration File
311
+
312
+ Create `.fake_data_dsl.yml` for action configuration:
313
+
314
+ ```yaml
315
+ # .fake_data_dsl.yml
316
+ schema_dir: schemas/
317
+ strict: true
318
+
319
+ validation:
320
+ require_descriptions: true
321
+ max_depth: 10
322
+
323
+ lint:
324
+ rules:
325
+ - naming_convention
326
+ - required_fields
327
+ - type_consistency
328
+
329
+ diff:
330
+ breaking_changes:
331
+ - field_removed
332
+ - type_changed
333
+ - required_added
334
+
335
+ warnings:
336
+ - field_added
337
+ - optional_to_required
338
+
339
+ export:
340
+ openapi:
341
+ version: "3.1.0"
342
+ info:
343
+ title: "My API"
344
+ version: "1.0.0"
345
+
346
+ typescript:
347
+ style: interface
348
+ export_style: named
349
+ ```
350
+
351
+ ## Self-Hosted Runner
352
+
353
+ For private schemas or faster builds:
354
+
355
+ ```yaml
356
+ jobs:
357
+ validate:
358
+ runs-on: self-hosted
359
+ container:
360
+ image: ruby:3.2
361
+ steps:
362
+ - uses: actions/checkout@v4
363
+
364
+ - name: Install FakeDataDSL
365
+ run: gem install fake_data_dsl
366
+
367
+ - name: Validate
368
+ run: fake_data_dsl validate schemas/
369
+ ```
370
+
371
+ ## Troubleshooting
372
+
373
+ ### Action Not Found
374
+
375
+ Make sure you're using the correct action reference:
376
+
377
+ ```yaml
378
+ # Correct
379
+ - uses: fake-data-dsl/action@v1
380
+
381
+ # Or from GitHub Marketplace
382
+ - uses: fake-data-dsl/fake-data-dsl-action@v1
383
+ ```
384
+
385
+ ### Schema Validation Errors
386
+
387
+ Check the action output for details:
388
+
389
+ ```yaml
390
+ - name: Validate
391
+ id: validate
392
+ uses: fake-data-dsl/action@v1
393
+ with:
394
+ command: validate
395
+ schema_dir: schemas/
396
+
397
+ - name: Show Errors
398
+ if: failure()
399
+ run: echo "${{ steps.validate.outputs.errors }}"
400
+ ```
401
+
402
+ ### Permission Issues
403
+
404
+ For actions that write files:
405
+
406
+ ```yaml
407
+ permissions:
408
+ contents: write # For committing generated files
409
+
410
+ jobs:
411
+ generate:
412
+ # ...
413
+ ```
414
+
415
+ ## See Also
416
+
417
+ - [CI/CD Integration](best_practices.md#cicd)
418
+ - [Data Contracts](DATA_CONTRACTS.md)
419
+ - [Breaking Changes Diff](DATA_CONTRACTS.md#breaking-changes)
420
+ - [Snapshot Testing](SNAPSHOT_TESTING.md)