From 65f2a01f57329f2ec4a2e3a6d16a32f51437b1a5 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 | 5 +++++ 12 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 84aedd473c2..5c22c12a5ca 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.1' # 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 63e0e0b4b62..c892410d1e4 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 794264019ba..4301c70baa0 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 0d97e87e290..c8e898db0aa 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 214149c0377..2a6f3756da1 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 1d1ae8077b0..f13b111d69d 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 13dc8293cad..51b0a3cedb7 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 0f53cb2dade..a82dbccf69a 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 855c667b70a..30c4d634f32 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 e845635df9a..ceba4cd2abb 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 f6f174f1699..b067fb04643 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 d7c34d31236..7d0f852fef7 100644 --- a/config/initializers/apipie.rb +++ b/config/initializers/apipie.rb @@ -21,6 +21,11 @@ config.translate = ->(str, loc) { str ? FastGettext.with_locale(loc) { _(str) } : nil } config.help_layout = 'apipie_dsl/apipie_dsls/help.html.erb' + config.default_class_description = lambda do |model| + return nil unless model.respond_to?(:model_name) + _("A class representing %s object") % model.model_name.human + end + config.reload_dsl = false end Apipie.configure do |config|