Class: Api::V2::InfoController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/api/v2/info_controller.rb

Overview

require ‘model_driven_api/version’

Instance Method Summary collapse

Instance Method Details

#compute_type(model, key) ⇒ Object



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
# File 'app/controllers/api/v2/info_controller.rb', line 60

def compute_type(model, key)
  # if it's a file, a date or a text, then return string
  instance = model.new
  # If it's a method, it is a peculiar case, in which we have to return "object" and additionalProperties: true
  return "method" if model.methods.include?(:json_attrs) && model.json_attrs && model.json_attrs.include?(:methods) && model.json_attrs[:methods].include?(key.to_sym)
  # If it's not the case of a method, then it's a field
  method_class = instance.send(key).class.to_s
  method_key = model.columns_hash[key]
  
  # Not columns
  return "object" if method_class == "ActiveStorage::Attached::One"
  return "array" if method_class == "ActiveStorage::Attached::Many" || method_class == "Array" || method_class.ends_with?("Array") || method_class.ends_with?("Collection") || method_class.ends_with?("Relation") || method_class.ends_with?("Set") || method_class.ends_with?("List") || method_class.ends_with?("Queue") || method_class.ends_with?("Stack") || method_class.ends_with?("ActiveRecord_Associations_CollectionProxy")
  
  # Columns
  case method_key.type
  when :json, :jsonb
    return "object"
  when :enum
    return "array"
  when :text, :hstore
    return "string"
  when :decimal, :float, :bigint
    return "number"
  end
  method_key.type.to_s
end

#create_properties_from_model(model, dsl, remove_reserved = false) ⇒ Object



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
# File 'app/controllers/api/v2/info_controller.rb', line 99

def create_properties_from_model(model, dsl, remove_reserved = false)
  parsed_json = JSON.parse(model.new.to_json(dsl))
  parsed_json.keys.map do |k|
    type = compute_type(model, k)
    
    # Remove fields that cannot be created or updated
    if remove_reserved && %w( id created_at updated_at lock_version).include?(k.to_s)
      nil
    elsif type == "method" && (parsed_json[k].is_a?(FalseClass) || parsed_json[k].is_a?(TrueClass))
      [k, { "type": "boolean" }]
    elsif type == "method" && parsed_json[k].is_a?(String) && number?(parsed_json[k])
      [k, { "type": "number" }]
    elsif type == "method" && parsed_json[k].is_a?(String) && integer?(parsed_json[k])
      [k, { "type": "integer" }]
    elsif type == "method" && parsed_json[k].is_a?(String) && datetime?(parsed_json[k])
      [k, { "type": "string", "format": "date-time" }]
    elsif type == "method"
      # Unknown or complex format returned
      [k, { "type": "object", "additionalProperties": true }]
    elsif type == "date"
      [k, { "type": "string", "format": "date" }]
    elsif type == "datetime"
      [k, { "type": "string", "format": "date-time" }]
    elsif type == "object" && (k.classify.constantize rescue false)
      sub_model = k.classify.constantize
      properties = dsl[:include].present? && dsl[:include].include?(k) ? create_properties_from_model(sub_model, dsl[:include][k.to_sym]) : create_properties_from_model(sub_model, {})
      [k, { "type": "object", "properties": properties }] rescue nil
    elsif type == "array" && (k.classify.constantize rescue false)
      sub_model = k.classify.constantize
      properties = dsl[:include].present? && dsl[:include].include?(k) ? create_properties_from_model(sub_model, dsl[:include][k.to_sym]) : create_properties_from_model(sub_model, {})
      [k, { "type": "array", "items": { "type": "object", "properties": properties } }] rescue nil
    else
      [k, { "type": type }]
    end
  end.compact.to_h
end

#datetime?(str) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/controllers/api/v2/info_controller.rb', line 95

def datetime?(str)
  true if DateTime.parse(str) rescue false
end

#dslObject

GET ‘/api/v2/info/dsl’



838
839
840
841
842
843
844
845
846
847
848
# File 'app/controllers/api/v2/info_controller.rb', line 838

def dsl
  pivot = {}
  ApplicationRecord.subclasses.each do |d|
    # Only if current user can read the model
    if can? :read, d
      model = d.to_s.underscore.tableize
      pivot[model] = (d.instance_methods(false).include?(:json_attrs) && !d.json_attrs.blank?) ? d.json_attrs : nil
    end
  end
  render json: pivot.to_json, status: 200
end

#generate_pathsObject



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
# File 'app/controllers/api/v2/info_controller.rb', line 136

def generate_paths
  pivot = {
    "/authenticate": {
      "post": {
        "summary": "Authenticate",
        "tags": ["Authentication"],
        "description": "Authenticate the user and return a JWT token in the header and the current user as body",
        "security": [
          "basicAuth": []
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "auth": {
                    "type": "object",
                    "properties": {
                      "email": {
                        "type": "string",
                        "format": "email"
                      },
                      "password": {
                        "type": "string",
                        "format": "password"
                      }
                    }
                  }
                },
                "required": ["email", "password"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User authenticated",
            "headers": {
              "token": {
                "description": "JWT",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  # ["id", "email", "created_at", "admin", "locked", "supplier_id", "location_id", "roles"]
                  "properties": create_properties_from_model(User, User.json_attrs)
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/info/version": {
      "get": {
        "summary": "Version",
        "description": "Just prints the APPVERSION",
        "tags": ["Info"],
        "responses": {
          "200": {
            "description": "APPVERSION",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/info/heartbeat": {
      "get": {
        "summary": "Heartbeat",
        "description": "Just keeps the session alive by returning a new token",
        "tags": ["Info"],
        "security": [
          "bearerAuth": []
        ],
        "responses": {
          "200": {
            "description": "Session alive",
            "headers": {
              "token": {
                "description": "JWT",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/info/roles": {
      "get": {
        "summary": "Roles",
        "description": "Returns the roles list",
        "tags": ["Info"],
        "security": [
          "bearerAuth": []
        ],
        "responses": {
          "200": {
            "description": "Roles list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "name": {
                        "type": "string"
                      },
                      "description": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/info/schema": {
      "get": {
        "summary": "Schema",
        "description": "Returns the schema of the models",
        "tags": ["Info"],
        "security": [
          "bearerAuth": []
        ],
        "responses": {
          "200": {
            "description": "Schema of the models",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "created_at": {
                        "type": "string",
                        "format": "date-time"
                      },
                      "updated_at": {
                        "type": "string",
                        "format": "date-time"
                      },
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/info/dsl": {
      "get": {
        "summary": "DSL",
        "description": "Returns the DSL of the models",
        "tags": ["Info"],
        "security": [
          "bearerAuth": []
        ],
        "responses": {
          "200": {
            "description": "DSL of the models",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer"
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/info/translations": {
      "get": {
        "summary": "Translations",
        "description": "Returns the translations of the entire App",
        "tags": ["Info"],
        "security": [
          "bearerAuth": []
        ],
        "responses": {
          "200": {
            "description": "Translations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/info/settings": {
      "get": {
        "summary": "Settings",
        "description": "Returns the settings of the App",
        "tags": ["Info"],
        "security": [
          "bearerAuth": []
        ],
        "responses": {
          "200": {
            "description": "Settings",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ns": {
                      "type": "object",
                      "properties": {
                        "key": {
                          "type": "string"
                        },
                        "value": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/info/swagger": {
      "get": {
        "summary": "Swagger",
        "description": "Returns the Swagger",
        "tags": ["Info"],
        "responses": {
          "200": {
            "description": "Swagger",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer"
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  ApplicationRecord.subclasses.sort_by { |d| d.to_s }.each do |d|
    # Only if current user can read the model
    if true # can? :read, d
      model = d.to_s.underscore.tableize
      # CRUD and Search endpoints
      pivot["/#{model}"] = {
        "get": {
          "summary": "Index",
          "description": "Returns the list of #{model}",
          "tags": [model.classify],
          "security": [
            "bearerAuth": []
          ],
          "responses": {
            "200": {
              "description": "List of #{model}",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": create_properties_from_model(d, (d.json_attrs rescue {}))
                    }
                  }
                }
              }
            },
            "404": {
              "description": "No #{model} found"
            }
          }
        },
        "post": {
          "summary": "Create",
          "description": "Creates a new #{model}",
          "tags": [model.classify],
          "security": [
            "bearerAuth": []
          ],
          "requestBody": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "#{model.singularize}": {
                      "type": "object",
                      "properties": create_properties_from_model(d, {}, true)
                    }
                  }
                }
              }
            }
          },
          "responses": {
            "200": {
              "description": "#{model} Created",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "object",
                    "properties": create_properties_from_model(d, (d.json_attrs rescue {}))
                  }
                }
              }
            }
          }
        }
      }
      # Non CRUD or Search, but custom, usually bulk operations endpoints
      custom_actions = d.methods(false).select do |m| m.to_s.starts_with?("custom_action_") end
      # Add also custom actions created using th enew Endpoints Interface
      custom_actions += "Endpoints::#{d.model_name.name}".constantize.methods(false) rescue []
      custom_actions.each do |action|
        custom_action_name = action.to_s.gsub("custom_action_", "")
        pivot["/#{model}/custom_action/#{custom_action_name}"] = {
          "post": {
            "summary": "Custom Action #{custom_action_name.titleize}",
            "description": "This is just an example of a custom action, they can accept a wide range of payloads and response with a wide range of responses, also all verbs are valid. Please refer to the documentation for more information.",
            "tags": [model.classify],
            "security": [
              "bearerAuth": []
            ],
            "responses": {
              "200": {
                "description": "Custom Action",
                "content": {
                  "application/json": {
                    "schema": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "integer"
                        },
                        "created_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "updated_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              },
              "404": {
                "description": "No #{model} found"
              }
            }
          }
        }
      end
      pivot["/#{model}/search"] = {
        # Complex queries are made using ranskac search via a post endpoint
        "post": {
          "summary": "Search",
          "description": "Searches the #{model} using complex queries. Please refer to the [documentation](https://activerecord-hackery.github.io/ransack/) for the query syntax. In this swagger are presented only some examples, please refer to the complete documentation for more complex queries.\nThe primary method of searching in Ransack is by using what is known as predicates.\nPredicates are used within Ransack search queries to determine what information to match. For instance, the cont predicate will check to see if an attribute called 'name' or 'description' contains a value using a wildcard query.",
          "tags": [model.classify],
          "security": [
            "bearerAuth": []
          ],
          "requestBody": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "q": {
                      "type": "object",
                      "properties": {
                        "name_or_description_cont": {
                          "type": "string"
                        },
                        "first_name_eq": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "responses": {
            "200": {
              "description": "List of #{model}",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": create_properties_from_model(d, (d.json_attrs rescue {}))
                    }
                  }
                }
              }
            },
            "404": {
              "description": "No #{model} found"
            }
          }
        }
      }
      pivot["/#{model}/{id}"] = {
        "put": {
          "summary": "Update",
          "description": "Updates the complete #{model}",
          "parameters": [
            {
              "name": "id",
              "in": "path",
              "required": true,
              "schema": {
                "type": "integer"
              }
            }
          ],
          "tags": [model.classify],
          "security": [
            "bearerAuth": []
          ],
          "requestBody": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "#{model.singularize}": {
                      "type": "object",
                      "properties": create_properties_from_model(d, {}, true)
                    }
                  }
                }
              }
            }
          },
          "responses": {
            "200": {
              "description": "#{model} Updated",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "object",
                    "properties": create_properties_from_model(d, (d.json_attrs rescue {}))
                  }
                }
              }
            },
            "404": {
              "description": "No #{model} found"
            }
          }
        },
        "patch": {
          "summary": "Patch",
          "description": "Updates the partial #{model}",
          "parameters": [
            {
              "name": "id",
              "in": "path",
              "required": true,
              "schema": {
                "type": "integer"
              }
            }
          ],
          "tags": [model.classify],
          "security": [
            "bearerAuth": []
          ],
          "requestBody": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "#{model.singularize}": {
                      "type": "object",
                      "properties": create_properties_from_model(d, {}, true)
                    }
                  }
                }
              }
            }
          },
          "responses": {
            "200": {
              "description": "#{model} Patched",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "object",
                    "properties": create_properties_from_model(d, (d.json_attrs rescue {}))
                  }
                }
              }
            },
            "404": {
              "description": "No #{model} found"
            }
          }
        },
        "delete": {
          "summary": "Delete",
          "description": "Deletes the #{model}",
          "parameters": [
            {
              "name": "id",
              "in": "path",
              "required": true,
              "schema": {
                "type": "integer"
              }
            }
          ],
          "tags": [model.classify],
          "security": [
            "bearerAuth": []
          ],
          "responses": {
            "200": {
              "description": "#{model} Deleted"
            },
            "404": {
              "description": "No #{model} found"
            }
          }
        },
        "get": {
          "summary": "Show",
          "description": "Shows the #{model}",
          "parameters": [
            {
              "name": "id",
              "in": "path",
              "required": true,
              "schema": {
                "type": "integer"
              }
            }
          ],
          "tags": [model.classify],
          "security": [
            "bearerAuth": []
          ],
          "responses": {
            "200": {
              "description": "Show #{model}",
              "content": {
                "application/json": {
                  "schema": {
                    "type": "object",
                    "properties": create_properties_from_model(d, (d.json_attrs rescue {}))
                  }
                }
              }
            },
            "404": {
              "description": "No #{model} found"
            }
          }
        }
      }
      # d.columns_hash.each_pair do |key, val| 
      #   pivot[model][key] = val.type unless key.ends_with? "_id"
      # end
      # # Only application record descendants in order to have a clean schema
      # pivot[model][:associations] ||= {
      #   has_many: d.reflect_on_all_associations(:has_many).map { |a| 
      #     a.name if (((a.options[:class_name].presence || a.name).to_s.classify.constantize.new.is_a? ApplicationRecord) rescue false)
      #   }.compact, 
      #   belongs_to: d.reflect_on_all_associations(:belongs_to).map { |a| 
      #     a.name if (((a.options[:class_name].presence || a.name).to_s.classify.constantize.new.is_a? ApplicationRecord) rescue false)
      #   }.compact
      # }
      # pivot[model][:methods] ||= (d.instance_methods(false).include?(:json_attrs) && !d.json_attrs.blank?) ? d.json_attrs[:methods] : nil
    end
  end
  pivot
end

#heartbeatObject

api :GET, ‘/api/v2/info/heartbeat’ Just keeps the session alive by returning a new token



21
22
23
# File 'app/controllers/api/v2/info_controller.rb', line 21

def heartbeat
  head :ok
end

#integer?(str) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/controllers/api/v2/info_controller.rb', line 87

def integer?(str)
  true if Integer(str) rescue false
end

#number?(str) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/controllers/api/v2/info_controller.rb', line 91

def number?(str)
  true if Float(str) rescue false
end

#openapiObject Also known as: swagger

GET ‘/api/v2/info/schema’



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
# File 'app/controllers/api/v2/info_controller.rb', line 793

def openapi
  uri = URI(request.url)
  pivot = {
    "openapi": "3.0.0",
    "info": {
      "title": "#{Settings.ns(:main).app_name} API",
      "description": "Model Driven Backend [API](https://github.com/gabrieletassoni/thecore/blob/master/docs/04_REST_API.md) created to reflect the actual Active Record Models present in the project in a dynamic way",
      "version": "v2"
    },
    "servers": [
      {
        # i.e. "http://localhost:3001/api/v2"
        "url": "#{uri.scheme}://#{uri.host}#{":#{uri.port}" if uri.port.present?}/api/v2",
        "description": "The URL at which this API responds."
      }
    ],
    # 1) Define the security scheme type (HTTP bearer)
    "components":{
      "securitySchemes": {
        "basicAuth": {
          "type": "http",
          "scheme": "basic"
        },
        "bearerAuth": { # arbitrary name for the security scheme
          "type": "http",
          "scheme": "bearer",
          "bearerFormat": "JWT" # optional, arbitrary value for documentation purposes
        }
      }
    },
    # 2) Apply the security globally to all operations
    "security": [
      {
        "bearerAuth": [] # use the same name as above
      }
    ],
    "paths": generate_paths
  }
  
  render json: pivot.to_json, status: 200
end

#rolesObject

api :GET, ‘/api/v2/info/roles’ it returns the roles list



14
15
16
# File 'app/controllers/api/v2/info_controller.rb', line 14

def roles
  render json: ::Role.all.to_json, status: 200
end

#schemaObject

GET ‘/api/v2/info/schema’



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
# File 'app/controllers/api/v2/info_controller.rb', line 31

def schema
  pivot = {}
  # if Rails.env.development?
  #   Rails.configuration.eager_load_namespaces.each(&:eager_load!) if Rails.version.to_i == 5 #Rails 5
  #   Zeitwerk::Loader.eager_load_all if Rails.version.to_i >= 6 #Rails 6
  # end
  ApplicationRecord.subclasses.each do |d|
    # Only if current user can read the model
    if can? :read, d
      model = d.to_s.underscore.tableize
      pivot[model] ||= {}
      d.columns_hash.each_pair do |key, val| 
        pivot[model][key] = val.type unless key.ends_with? "_id"
      end
      # Only application record descendants to have a clean schema
      pivot[model][:associations] ||= {
        has_many: d.reflect_on_all_associations(:has_many).map { |a| 
          a.name if (((a.options[:class_name].presence || a.name).to_s.classify.constantize.new.is_a? ApplicationRecord) rescue false)
        }.compact, 
        belongs_to: d.reflect_on_all_associations(:belongs_to).map { |a| 
          a.name if (((a.options[:class_name].presence || a.name).to_s.classify.constantize.new.is_a? ApplicationRecord) rescue false)
        }.compact
      }
      pivot[model][:methods] ||= (d.instance_methods(false).include?(:json_attrs) && !d.json_attrs.blank?) ? d.json_attrs[:methods] : nil
    end
  end
  render json: pivot.to_json, status: 200
end

#settingsObject



850
851
852
# File 'app/controllers/api/v2/info_controller.rb', line 850

def settings
  render json: ThecoreSettings::Setting.pluck(:ns, :key, :raw).inject({}){|result, array| (result[array.first] ||= {})[array.second] = array.third; result }.to_json, status: 200
end

#translationsObject

GET ‘/api/v2/info/translations’



26
27
28
# File 'app/controllers/api/v2/info_controller.rb', line 26

def translations
  render json: I18n.t(".", locale: (params[:locale].presence || :it)).to_json, status: 200
end

#versionObject

api :GET, ‘/api/v2/info/version’, “Just prints the APPVERSION.”



8
9
10
# File 'app/controllers/api/v2/info_controller.rb', line 8

def version
  render json: { version: "TODO: Find a Way to Dynamically Obtain It" }.to_json, status: 200
end