model_driven_api 3.2.0 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40a387e4cb1fccde214f680920f4ea2c0f69e9afa948ecad67670613b6306b24
4
- data.tar.gz: 72849e5f1f4ef21dde1aef3974fa98375cdae76207ac09c38d3ecb6406b3ff2b
3
+ metadata.gz: 4282b6de5aa1f0692ad907c6e711b69c5c300ca41562311f49c33113b0c2c002
4
+ data.tar.gz: 5b103be64cfedc3dca3688aedcfe4d3e0d53d5476821debc6e3a6cae96ec7d65
5
5
  SHA512:
6
- metadata.gz: d7e790ae561684ef9ac0a0be51dc6dc6f9d3b1f9e6b6069f550f8f4d124bfe943243bf98c07dabbc07cf257c309025ff3b402e06cafd2fe0b18d9aed6e5e0101
7
- data.tar.gz: 5ba4463d54423d0260e17fda9c06de588c98c92d0fbae78b8adb1c6f0448d1d0055c426504cb90d04e982976fff3cb99dd73d1bb9f51e0c641b5aafbbf99de81
6
+ metadata.gz: 50fbc04a16be3c132b3b1afbb95a5730f766c6b51310d49cc49b76a139138cd42eeb45a1359ac855d69d8bab8df7eddff8c8093610c961c42376bcc1a5e52832
7
+ data.tar.gz: a77ade2a13edb03093a425c0e01c3d6c1ffb526557463a1b02f2b8d63a8e99776b7d2ce21b94481520fc832a2e7b899103f687cb659323f1506fa04fb6e7860a
@@ -163,6 +163,7 @@ class Api::V2::ApplicationController < ActionController::API
163
163
  # 2. As a module instance method in the model, like Track::Endpoints.inventory
164
164
  # Example:
165
165
  # Endpoints::TestApi.new(:test, {request_verb: "POST", is_connected: "Uhhhh"}).result
166
+ Rails.logger.debug("Checking for custom action #{custom_action} in #{@model}")
166
167
  if @model.respond_to?("custom_action_#{custom_action}")
167
168
  body, status = @model.send("custom_action_#{custom_action}", params)
168
169
  elsif ("Endpoints::#{@model}".constantize rescue false) && "Endpoints::#{@model}".constantize.instance_methods.include?(custom_action.to_sym)
@@ -516,9 +516,9 @@ class Api::V2::InfoController < Api::V2::ApplicationController
516
516
  }
517
517
  # Non CRUD or Search, but custom, usually bulk operations endpoints
518
518
  new_custom_actions = ("Endpoints::#{d.model_name.name}".constantize.instance_methods(false) rescue [])
519
- # Rails.logger.debug "New Custom Actions (#{d.model_name.name}): #{new_custom_actions}"
519
+ Rails.logger.debug "New Custom Actions (#{d.model_name.name}): #{new_custom_actions}"
520
520
  new_custom_actions.each do |action|
521
- openapi_definition = "Endpoints::#{d.model_name.name}".constantize.definitions[action.to_sym] rescue false
521
+ openapi_definition = "Endpoints::#{d.model_name.name}".constantize.definitions[d.model_name.name][action.to_sym] rescue []
522
522
 
523
523
  # Add the tag to the openapi definition
524
524
  openapi_definition.each do |k, v|
@@ -1,5 +1,5 @@
1
1
  class Endpoints::TestApi < NonCrudEndpoints
2
- self.desc :test, {
2
+ self.desc 'TestApi', :test, {
3
3
  # Define the action name using openapi swagger format
4
4
  get: {
5
5
  summary: "Test API Custom Action",
@@ -1,3 +1,3 @@
1
1
  module ModelDrivenApi
2
- VERSION = "3.2.0".freeze
2
+ VERSION = "3.2.2".freeze
3
3
  end
@@ -4,9 +4,16 @@ class NonCrudEndpoints
4
4
  self.definitions = {}
5
5
  # Add a validation method which will be inherited by all the instances, and automatically run before any method call
6
6
  def initialize(m, params)
7
- # Check if self hase the m method, if not, raise a NoMethodError
7
+ # Rails.logger.debug "Initializing NonCrudEndpoints"
8
+ # Showing the class name of the instance, and also, if there's a class inheriting from this one, the name of the child class
9
+ # Rails.logger.debug "Class: #{self.class.name} - Child Class: #{self.class.superclass.name if self.class.superclass != Object}"
10
+ # Check if self has the m method, if not, raise a NoMethodError
8
11
  raise NoMethodError, "The method #{m} does not exist in #{self.class.name}" unless self.respond_to? m
9
- @definition = self.definitions[m.to_sym].with_indifferent_access
12
+ # To avoid having conflicting keys from different classes, we will use a two levels object to store the definitions
13
+ # the first level is the class name, and the second level is the method name
14
+ self.definitions[self.class.name] ||= {}
15
+ self.definitions[self.class.name][m.to_sym] ||= {}
16
+ @definition = self.definitions[self.class.name][m.to_sym].with_indifferent_access
10
17
 
11
18
  # self.send(m, { explain: true }) rescue []
12
19
  validate_request(params)
@@ -25,8 +32,9 @@ class NonCrudEndpoints
25
32
 
26
33
  private
27
34
 
28
- def self.desc(key, definition)
29
- self.definitions[key] = definition
35
+ def self.desc(endpoint, key, definition)
36
+ self.definitions[endpoint] ||= {}
37
+ self.definitions[endpoint][key] = definition
30
38
  end
31
39
 
32
40
  def get_type(type)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_driven_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-10 00:00:00.000000000 Z
11
+ date: 2024-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thecore_backend_commons