Skip to content

Commit

Permalink
Fix: OpenAPI warnings (#270)
Browse files Browse the repository at this point in the history
* Fix: Send FactoryBot examples to JbuilderSchema for proper attributes and properties examples in schemas

* Fix for unwrapped parameters in examples

* Fix Standard

* Fix id type in paths

* Upgrade Ruby to 3.2.2

* Hacked Jbuilder to correct action_text values

* Rename Jbuilder Hacks module to ValuesTransformer

* Updated jbuilder-schema

* Fix: namespaced model names transform to undercored
  • Loading branch information
newstler authored Aug 24, 2023
1 parent a88fc49 commit 69c493a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ RUBY VERSION
ruby 3.2.2p53

BUNDLED WITH
2.3.8
2.4.12
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
in: path
required: true
schema:
type: string
type: integer
- $ref: "#/components/parameters/after"
responses:
"404":
Expand Down Expand Up @@ -44,7 +44,7 @@
in: path
required: true
schema:
type: string
type: integer
requestBody:
description: "Information about a new Tangible Thing"
required: true
Expand Down
2 changes: 1 addition & 1 deletion bullet_train-api/bullet_train-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "pagy_cursor"
spec.add_dependency "rack-cors"
spec.add_dependency "doorkeeper"
spec.add_dependency "jbuilder-schema", ">= 2.0.0"
spec.add_dependency "jbuilder-schema", ">= 2.2.0"
spec.add_dependency "factory_bot"

spec.add_dependency "bullet_train"
Expand Down
1 change: 1 addition & 0 deletions bullet_train-api/lib/bullet_train/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require "scaffolding/block_manipulator"
require "scaffolding/transformer"
require "jbuilder/schema"
require "jbuilder/values_transformer"

module BulletTrain
module Api
Expand Down
5 changes: 4 additions & 1 deletion bullet_train-api/lib/bullet_train/api/example_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _path_examples(method, model, **options)
else
template, class_name, var_name, values = _set_values("get_example", model)

unless %w[example examples].include?(method.split("_").last)
if method.end_with?("parameters")
if has_strong_parameters?("::Api::#{version.upcase}::#{class_name.pluralize}Controller".constantize)
strong_params_module = "::Api::#{version.upcase}::#{class_name.pluralize}Controller::StrongParameters".constantize
strong_parameter_keys = BulletTrain::Api::StrongParametersReporter.new(class_name.constantize, strong_params_module).report
Expand All @@ -112,6 +112,9 @@ def _path_examples(method, model, **options)
parameters_output = JSON.parse(output)
parameters_output&.select! { |key| strong_parameter_keys.include?(key.to_sym) }

# Wrapping the example as parameters should be wrapped with the model name:
parameters_output = {model.to_s => parameters_output}

return indent(parameters_output.to_yaml.delete_prefix("---\n"), 6).html_safe
end
return nil
Expand Down
13 changes: 13 additions & 0 deletions bullet_train-api/lib/jbuilder/values_transformer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require "jbuilder"

module ValuesTransformer
def _set_value(key, value)
value = value.body if value.is_a?(ActionText::RichText)

super(key, value)
end
end

::Jbuilder.prepend ValuesTransformer

0 comments on commit 69c493a

Please sign in to comment.