From 4529ebb0961cc765e89da5fb7585b75994732326 Mon Sep 17 00:00:00 2001 From: archanaserver Date: Wed, 18 Oct 2023 16:03:13 +0530 Subject: [PATCH] Fixes #36575 - Use apipie-dsl default model descriptions --- Gemfile | 2 +- app/models/domain.rb | 2 +- app/models/hostgroup.rb | 2 +- app/models/operatingsystem.rb | 2 +- app/models/realm.rb | 2 +- app/models/smart_proxy.rb | 2 +- app/models/ssh_key.rb | 2 +- app/models/subnet.rb | 2 +- app/models/taxonomy.rb | 2 +- app/models/template.rb | 2 +- app/models/user.rb | 2 +- config/initializers/apipie.rb | 2 ++ 12 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 84aedd473c25..57f124acb06d 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ gem 'ancestry', '~> 4.0' gem 'scoped_search', '>= 4.1.10', '< 5' gem 'ldap_fluff', '>= 0.5.0', '< 1.0' gem 'apipie-rails', '>= 0.8.0', '< 2' -gem 'apipie-dsl', '>= 2.2.6' +gem 'apipie-dsl', '>= 2.6.0' # Pin rdoc to prevent updating bundled psych (https://github.com/ruby/rdoc/commit/ebe185c8775b2afe844eb3da6fa78adaa79e29a4) # Rails 6.0 is incompatible with Psych 4, Rails 6.1 should work gem 'rdoc', '< 6.4' diff --git a/app/models/domain.rb b/app/models/domain.rb index 63e0e0b4b626..c892410d1e4a 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -51,7 +51,7 @@ class Domain < ApplicationRecord set_crud_hooks :domain - apipie :class, desc: "A class representing #{model_name.human} object" do + apipie :class do sections only: %w[all additional] prop_group :basic_model_props, ApplicationRecord, meta: { example: 'example.com' } property :fullname, String, desc: 'User name for this domain, e.g. "Primary domain for our company"' diff --git a/app/models/hostgroup.rb b/app/models/hostgroup.rb index 794264019ba4..4301c70baa07 100644 --- a/app/models/hostgroup.rb +++ b/app/models/hostgroup.rb @@ -83,7 +83,7 @@ class Hostgroup < ApplicationRecord where(conditions) } - apipie :class, "A class representing #{model_name.human} object" do + apipie :class do prop_group :basic_model_props, ApplicationRecord, meta: { friendly_name: 'host group' } property :architecture, 'Architecture', desc: 'Returns architecture to be used on hosts within this host group' property :arch, 'Architecture', desc: 'Returns architecture to be used on hosts within this host group' diff --git a/app/models/operatingsystem.rb b/app/models/operatingsystem.rb index 0d97e87e2907..c8e898db0aaf 100644 --- a/app/models/operatingsystem.rb +++ b/app/models/operatingsystem.rb @@ -79,7 +79,7 @@ class Operatingsystem < ApplicationRecord graphql_type '::Types::Operatingsystem' - apipie :class, desc: "A class representing #{model_name.human} object" do + apipie :class do sections only: %w[all additional] prop_group :basic_model_props, ApplicationRecord, meta: { friendly_name: 'operating system consisting', example: 'RedHat, Fedora, Debian' } property :major, String, desc: 'Major version of the operating system' diff --git a/app/models/realm.rb b/app/models/realm.rb index 214149c03777..2a6f3756da1a 100644 --- a/app/models/realm.rb +++ b/app/models/realm.rb @@ -35,7 +35,7 @@ class Realm < ApplicationRecord end } - apipie :class, desc: "A class representing #{model_name.human} object" do + apipie :class do sections only: %w[all additional] prop_group :basic_model_props, ApplicationRecord, meta: { example: 'EXAMPLE.COM' } property :realm_type, String, desc: 'Realm type, e.g. FreeIPA or Active Directory' diff --git a/app/models/smart_proxy.rb b/app/models/smart_proxy.rb index 1d1ae8077b06..f13b111d69dc 100644 --- a/app/models/smart_proxy.rb +++ b/app/models/smart_proxy.rb @@ -196,7 +196,7 @@ def get_features end end - apipie :class, desc: "A class representing #{model_name.human} object" do + apipie :class do name 'Smart Proxy' refs 'SmartProxy' sections only: %w[all additional] diff --git a/app/models/ssh_key.rb b/app/models/ssh_key.rb index 13dc8293cadd..51b0a3cedb7e 100644 --- a/app/models/ssh_key.rb +++ b/app/models/ssh_key.rb @@ -35,7 +35,7 @@ class SshKey < ApplicationRecord delegate :login, to: :user, prefix: true - apipie :class, desc: "A class representing #{model_name.human} object" do + apipie :class do sections only: %w[all additional] prop_group :basic_model_props, ApplicationRecord, meta: { friendly_name: 'SSH key' } property :user, 'User', desc: 'Returns the user object which is linked to the SSH key' diff --git a/app/models/subnet.rb b/app/models/subnet.rb index 0f53cb2dade3..a82dbccf69ab 100644 --- a/app/models/subnet.rb +++ b/app/models/subnet.rb @@ -124,7 +124,7 @@ def model_name set_crud_hooks :subnet - apipie :class, "A class representing #{model_name.human} object" do + apipie :class do sections only: %w[all additional] refs 'Subnet::Ipv4', 'Subnet::Ipv6' prop_group :basic_model_props, ApplicationRecord diff --git a/app/models/taxonomy.rb b/app/models/taxonomy.rb index 855c667b70a6..30c4d634f324 100644 --- a/app/models/taxonomy.rb +++ b/app/models/taxonomy.rb @@ -37,7 +37,7 @@ def self.inherited(child) scoped_search :on => :description, :complete_enabled => :false, :only_explicit => true scoped_search :on => :id, :validator => ScopedSearch::Validators::INTEGER - apipie :class, desc: "A class representing #{model_name.human} object" do + apipie :class do sections only: %w[all additional] name_exl, title_exl = class_scope.model_name.human == 'Location' ? ['Europe', 'Europe/Prague'] : ['Red Hat', 'Red Hat/Engineering'] prop_group :basic_model_props, ApplicationRecord, meta: { example: name_exl } diff --git a/app/models/template.rb b/app/models/template.rb index e845635df9a7..ceba4cd2abb4 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -25,7 +25,7 @@ class Template < ApplicationRecord attr_exportable :name, :description, :snippet, :template_inputs, :model => ->(template) { template.class.to_s } - apipie :class, desc: "A class representing #{model_name.human} object" do + apipie :class do sections only: %w[all additional] prop_group :basic_model_props, ApplicationRecord end diff --git a/app/models/user.rb b/app/models/user.rb index f6f174f1699e..b067fb046432 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -149,7 +149,7 @@ def as_json(options = {}) set_crud_hooks :user - apipie :class, desc: "A class representing #{model_name.human} object" do + apipie :class do sections only: %w[all additional] property :id, Integer, desc: 'Numerical ID of the User' property :firstname, String, desc: 'Returns the user first name' diff --git a/config/initializers/apipie.rb b/config/initializers/apipie.rb index b089ddbefca2..9bd9daf32c33 100644 --- a/config/initializers/apipie.rb +++ b/config/initializers/apipie.rb @@ -27,6 +27,8 @@ trans end config.help_layout = 'apipie_dsl/apipie_dsls/help.html.erb' + config.default_class_description = ->(model) { _("A class representing %s object") % model.human } + config.reload_dsl = false end Apipie.configure do |config|