Skip to content

[OpenAPI] Validator Task - #163

Merged
rsamoilov merged 12 commits into
rage-rb:mainfrom
alex-rogachev:openapi-validation-task
Aug 12, 2026
Merged

[OpenAPI] Validator Task#163
rsamoilov merged 12 commits into
rage-rb:mainfrom
alex-rogachev:openapi-validation-task

Conversation

@alex-rogachev

@alex-rogachev alex-rogachev commented Jul 28, 2025

Copy link
Copy Markdown
Contributor
  • Add openapi:validate Rake task that builds the OpenAPI spec and fails (non-zero exit) when any tag warnings were produced during the build.
  • Collect warnings only for the duration of a build (Rage::OpenAPI.__collect_warnings) so docs serving does not retain a process-wide warning list; abort if the app is not booted to avoid a false pass on an empty router.

@alex-rogachev
alex-rogachev force-pushed the openapi-validation-task branch from 21b7fc2 to e62337b Compare August 7, 2025 11:51
Comment thread lib/rage/tasks/openapi.rake Outdated
Rage::OpenAPI.build

if Rage::OpenAPI.__warnings.any?
puts "OpenAPI validation failed. Warnings: #{Rage::OpenAPI.__warnings}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are any warnings, Rage::OpenAPI.build will display them anyway.

Suggested change
puts "OpenAPI validation failed. Warnings: #{Rage::OpenAPI.__warnings}"
puts "OpenAPI validation failed."

@alex-rogachev
alex-rogachev force-pushed the openapi-validation-task branch from 5b6ebd6 to 605c595 Compare August 10, 2026 12:23
@alex-rogachev
alex-rogachev force-pushed the openapi-validation-task branch from 8047efe to e3c675b Compare August 11, 2026 12:16
@alex-rogachev alex-rogachev changed the title OpenAPI validator task [OpenAPI] Validator Task Aug 11, 2026
Comment on lines +209 to +214
def self.__collect_warnings
@__warnings = []
yield
@__warnings
ensure
@__warnings = nil

@alex-rogachev alex-rogachev Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @rsamoilov
What do you think about implementing the warnings accumulator as a wrapper around Rage::OpenAPI.build? I feel like this approach works well because the additional logic doesn't add overhead to the original __log_warn implementation and remains optional, which aligns with the idea that new features shouldn't affect performance for users who don't use them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the current approach, but I'm not entirely sure what a wrapper around Rage::OpenAPI.build would look like.

I've approved the PR and will be happy to merge it. Let me know if you'd like to rebuild it though.

Comment on lines +209 to +214
def self.__collect_warnings
@__warnings = []
yield
@__warnings
ensure
@__warnings = nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the current approach, but I'm not entirely sure what a wrapper around Rage::OpenAPI.build would look like.

I've approved the PR and will be happy to merge it. Let me know if you'd like to rebuild it though.

@rsamoilov
rsamoilov merged commit 5920f17 into rage-rb:main Aug 12, 2026
11 checks passed
@rsamoilov

Copy link
Copy Markdown
Member

FIY the approach is now a bit different, so I moved the validation Rake task under Rage::CLI - #382.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants