From ceea6eb3572006c2a0222f86625fc755d3c856db Mon Sep 17 00:00:00 2001 From: a-chacon Date: Fri, 30 Aug 2024 21:27:54 -0400 Subject: [PATCH] fix(yard_oas_rails_factory): set different expresion for request body examples --- lib/oas_rails/yard/oas_rails_factory.rb | 6 +++--- test/dummy/app/controllers/users_controller.rb | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/oas_rails/yard/oas_rails_factory.rb b/lib/oas_rails/yard/oas_rails_factory.rb index b1687ba..a1026ec 100644 --- a/lib/oas_rails/yard/oas_rails_factory.rb +++ b/lib/oas_rails/yard/oas_rails_factory.rb @@ -15,7 +15,7 @@ def parse_tag_with_request_body(tag_name, text) # @param text [String] The tag text to parse. # @return [RequestBodyExampleTag] The parsed request body example tag object. def parse_tag_with_request_body_example(tag_name, text) - description, _, hash = extract_description_type_and_content(text, process_content: true) + description, _, hash = extract_description_type_and_content(text, process_content: true, expresion: /^(.*?)\[([^\]]*)\](.*)$/m) RequestBodyExampleTag.new(tag_name, description, content: hash) end @@ -52,8 +52,8 @@ def parse_tag_with_response_example(tag_name, text) # @param text [String] The text to parse. # @param process_content [Boolean] Whether to evaluate the content as a hash. # @return [Array] An array containing the description, type, and content or remaining text. - def extract_description_type_and_content(text, process_content: false) - match = text.match(/^(.*?)\s*\[(.*)\]\s*(.*)$/) + def extract_description_type_and_content(text, process_content: false, expresion: /^(.*?)\s*\[(.*)\]\s*(.*)$/) + match = text.match(expresion) raise ArgumentError, "Invalid tag format: #{text}" if match.nil? description = match[1].strip diff --git a/test/dummy/app/controllers/users_controller.rb b/test/dummy/app/controllers/users_controller.rb index 3b4efa9..58cd0b8 100644 --- a/test/dummy/app/controllers/users_controller.rb +++ b/test/dummy/app/controllers/users_controller.rb @@ -8,6 +8,7 @@ class UsersController < ApplicationController # @summary Login # @request_body Valid Login Params [!Hash{email: !String, password: !String}] # @request_body_example Test User [Hash] {email: 'oas@test.com', password: 'Test12345'} + # @request_body_example The Appointment to be created [Hash] {appointment: {start_date: '14/07/2024 10:00',end_date: '14/07/2024 10:30', comment: 'For my son.'}, appointment_services: [1, 2]} # @no_auth def login @user = User.find_by_email(params[:email])