Skip to content

Commit

Permalink
fix(yard_oas_rails_factory): set different expresion for request body…
Browse files Browse the repository at this point in the history
… examples
  • Loading branch information
a-chacon committed Aug 31, 2024
1 parent aedbe7b commit ceea6eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/oas_rails/yard/oas_rails_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]', 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])
Expand Down

0 comments on commit ceea6eb

Please sign in to comment.