Commit 5362256e by liyijie

Add resource not exist protection

parent bc05441b
...@@ -10,6 +10,7 @@ class SimpleControllerGenerator < Rails::Generators::NamedBase ...@@ -10,6 +10,7 @@ class SimpleControllerGenerator < Rails::Generators::NamedBase
def setup def setup
@routes = RSpec::Rails::Swagger::RouteParser.new(controller_path.sub(/^\//, '')).routes @routes = RSpec::Rails::Swagger::RouteParser.new(controller_path.sub(/^\//, '')).routes
p "Warning!! Resource is not exist, CHECK & regenerate after you have configurate the model and routes already" if resource_class&.columns_hash.blank?
end end
def create_controller_files def create_controller_files
......
...@@ -4,9 +4,11 @@ require 'swagger_helper' ...@@ -4,9 +4,11 @@ require 'swagger_helper'
type: :object, properties: { type: :object, properties: {
<%= singular_name %>: { <%= singular_name %>: {
type: :object, properties: { type: :object, properties: {
<% if resource_class&.columns_hash.present? -%>
<% resource_class.columns_hash.except('id', 'created_at', 'updated_at').values.each do |column| -%> <% resource_class.columns_hash.except('id', 'created_at', 'updated_at').values.each do |column| -%>
<%= column.name %>: { type: :<%= column.type %>, description: '' }, <%= column.name %>: { type: :<%= column.type %>, description: '' },
<% end -%> <% end -%>
<% end -%>
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment