oas_rails 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,10 +7,12 @@ module OasRails
7
7
  # @param klass [Class] The class for which the schema is built.
8
8
  # @return [Hash] The schema as a JSON-compatible hash.
9
9
  def build_incoming_schema(klass:, model_to_schema_class: EasyTalk)
10
- configure_common_settings(model_to_schema_class:)
11
- model_to_schema_class.configuration.excluded_columns = OasRails.config.excluded_columns_incoming
12
-
13
- model_to_schema_class::ActiveRecordSchemaBuilder.new(klass).build_schema_definition.as_json["schema"]
10
+ build_schema(
11
+ klass: klass,
12
+ model_to_schema_class: model_to_schema_class,
13
+ excluded_columns: OasRails.config.excluded_columns_incoming,
14
+ exclude_primary_key: true
15
+ )
14
16
  end
15
17
 
16
18
  # Builds a schema for a class when it is used as outgoing API data.
@@ -18,21 +20,37 @@ module OasRails
18
20
  # @param klass [Class] The class for which the schema is built.
19
21
  # @return [Hash] The schema as a JSON-compatible hash.
20
22
  def build_outgoing_schema(klass:, model_to_schema_class: EasyTalk)
21
- configure_common_settings(model_to_schema_class:)
22
- model_to_schema_class.configuration.excluded_columns = OasRails.config.excluded_columns_outgoing
23
- model_to_schema_class.configuration.exclude_primary_key = false
24
-
25
- model_to_schema_class::ActiveRecordSchemaBuilder.new(klass).build_schema_definition.as_json["schema"]
23
+ build_schema(
24
+ klass: klass,
25
+ model_to_schema_class: model_to_schema_class,
26
+ excluded_columns: OasRails.config.excluded_columns_outgoing,
27
+ exclude_primary_key: false
28
+ )
26
29
  end
27
30
 
28
31
  private
29
32
 
33
+ # Builds a schema with the given configuration.
34
+ #
35
+ # @param klass [Class] The class for which the schema is built.
36
+ # @param model_to_schema_class [Class] The schema builder class.
37
+ # @param excluded_columns [Array] Columns to exclude from the schema.
38
+ # @param exclude_primary_key [Boolean] Whether to exclude the primary key.
39
+ # @return [Hash] The schema as a JSON-compatible hash.
40
+ def build_schema(klass:, model_to_schema_class:, excluded_columns:, exclude_primary_key:)
41
+ configure_common_settings(model_to_schema_class: model_to_schema_class)
42
+ model_to_schema_class.configuration.excluded_columns = excluded_columns
43
+ model_to_schema_class.configuration.exclude_primary_key = exclude_primary_key
44
+
45
+ definition = model_to_schema_class::ActiveRecordSchemaBuilder.new(klass).build_schema_definition
46
+ EasyTalk::Builders::ObjectBuilder.new(definition).build.as_json
47
+ end
48
+
30
49
  # Configures common settings for schema building.
31
50
  #
32
51
  # Excludes associations and foreign keys from the schema.
33
52
  def configure_common_settings(model_to_schema_class: EasyTalk)
34
53
  model_to_schema_class.configuration.exclude_associations = true
35
- model_to_schema_class.configuration.exclude_foreign_keys = true
36
54
  end
37
55
  end
38
56
  end
@@ -13,7 +13,8 @@ module OasRails
13
13
  :possible_default_responses,
14
14
  :response_body_of_default,
15
15
  :http_verbs,
16
- :use_model_names
16
+ :use_model_names,
17
+ :rapidoc_theme
17
18
  attr_reader :servers, :tags, :security_schema
18
19
 
19
20
  def initialize
@@ -35,6 +36,7 @@ module OasRails
35
36
  @http_verbs = [:get, :post, :put, :patch, :delete]
36
37
  @response_body_of_default = "Hash{ success: !Boolean, message: String }"
37
38
  @use_model_names = false
39
+ @rapidoc_theme = :rails
38
40
  end
39
41
 
40
42
  def security_schema=(value)
@@ -6,5 +6,11 @@ module OasRails
6
6
  inflect.acronym 'YARD'
7
7
  end
8
8
  end
9
+
10
+ config.app_middleware.use(
11
+ Rack::Static,
12
+ urls: ["/oas-rails-assets"],
13
+ root: OasRails::Engine.root.join("public")
14
+ )
9
15
  end
10
16
  end
@@ -1,3 +1,3 @@
1
1
  module OasRails
2
- VERSION = "0.10.1"
2
+ VERSION = "0.11.0"
3
3
  end