Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Forest JSON schema duplicate fields #542

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Jan 13, 2022

  1. Ensure ForestLiana.models holds unique models

    Given the following model hierarchy
    
    ```
    module Screen
      class ApplicationRecord < ActiveRecord::Base
        self.abstract_class = true
      end
    end
    
    module Screen
      class Remediation < Screen::ApplicationRecord
        self.abstract_class = true
      end
    end
    
    module Screen
      class SctInRemediation < Screen::Remediation
        self.table_name = "remediations"
      end
    end
    
    module Screen
      class SctOutRemediation < Screen::Remediation
        self.table_name = "remediations"
      end
    end
    ```
    
    `ForestLiana.models` will include these child models twice, which will cause Forest
    to generate a JSON schema with duplicated fields for the duplicated models.
    
    ```ruby
    ForestLiana.models.group_by{ |e| e }.select { |k, v| v.size > 1 }.map(&:first)
    => [Screen::SctInRemediation (call 'Screen::SctInRemediation.connection' to establish a connection),
     Screen::SctOutRemediation (call 'Screen::SctOutRemediation.connection' to establish a connection),
     Screen::SddInRemediation (call 'Screen::SddInRemediation.connection' to establish a connection)]
    ```
    
    ```bash
    ❯ cat .forestadmin-schema.json | jq '.collections[24].name'
    "Screen__SctInRemediation"
    
    ❯ cat .forestadmin-schema.json | jq '.collections[24].fields[] | .field ' | sort
    comment"
    "created_at"
    "created_at"
    "id"
    "id"
    "status"
    "status"
    "updated_at"
    "updated_at"
    ```
    Mario Oprea committed Jan 13, 2022
    Configuration menu
    Copy the full SHA
    021afdf View commit details
    Browse the repository at this point in the history