Class: SwaggerDocsRails::SchemaParser

Inherits:
Object
  • Object
show all
Defined in:
lib/swagger_docs_rails/schema_parser.rb

Constant Summary collapse

IGNORED_COLUMNS =
%w[
  id created_by updated_by deleted_at created_at updated_at
  encrypted_password reset_password_token reset_password_sent_at
  remember_created_at refresh_token refresh_token_expires_at
  token_primeiro_acesso
].freeze
COLUMN_TYPE_MAP =
{
  string:   { type: "string" },
  text:     { type: "string" },
  integer:  { type: "integer", format: "int64" },
  bigint:   { type: "integer", format: "int64" },
  float:    { type: "number",  format: "float" },
  decimal:  { type: "number",  format: "double" },
  boolean:  { type: "boolean" },
  date:     { type: "string",  format: "date" },
  datetime: { type: "string",  format: "date-time" },
  jsonb:    { type: "object" },
  json:     { type: "object" }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_path = nil) ⇒ SchemaParser

Returns a new instance of SchemaParser.



35
36
37
38
39
# File 'lib/swagger_docs_rails/schema_parser.rb', line 35

def initialize(schema_path = nil)
  @schema_path = schema_path || Rails.root.join("db", "schema.rb")
  @tables = {}
  parse!
end

Instance Attribute Details

#tablesObject (readonly)

Returns the value of attribute tables.



33
34
35
# File 'lib/swagger_docs_rails/schema_parser.rb', line 33

def tables
  @tables
end

Instance Method Details

#model_name_for_table(table_name) ⇒ Object



53
54
55
# File 'lib/swagger_docs_rails/schema_parser.rb', line 53

def model_name_for_table(table_name)
  table_to_model_name(table_name)
end

#to_openapi_schemasObject

Retorna Hash com todos os schemas OpenAPI gerados



42
43
44
45
46
47
48
49
50
51
# File 'lib/swagger_docs_rails/schema_parser.rb', line 42

def to_openapi_schemas
  schemas = {}
  @tables.each do |table_name, columns|
    model = table_to_model_name(table_name)
    schemas[model]           = build_full_schema(columns)
    schemas["#{model}Input"] = build_input_schema(columns)
    schemas["#{model}List"]  = build_list_schema(model)
  end
  schemas
end