Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-line tag text not working with a custom Factory. (Question) #1611

Closed
a-chacon opened this issue Mar 24, 2025 · 1 comment
Closed

Multi-line tag text not working with a custom Factory. (Question) #1611

a-chacon opened this issue Mar 24, 2025 · 1 comment

Comments

@a-chacon
Copy link

Hi! Thanks for make Yard. I am using it in a Rails engine to generate documentation for APIs. I am looking in the code how can I get all the lines from a tag (Multi-line), I try a lot of things read the code and docs, but I don't get how make it works. I tested with the default tags like @abstract and this works. But when I try to use my custom tags, I just get the value stripped.

I already read:

And look at the code, there is no a third parameter like the documentation says:

The text parameter contains pre-parsed text with extra spaces and newlines removed. If required, the method could also be declared with a third parameter containing unmodified raw text

If I add a third parameter, I just get: ArgumentError: wrong number of arguments (given 2, expected 3).

My implementation is something like:

# My factory:
module OasRails
  module YARD
    class OasRailsFactory < ::YARD::Tags::DefaultFactory

      # Parses a tag that represents a request body example.
      # @param tag_name [String] The name of the tag.
      # @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, _raw) 
        description, _, hash = extract_description_type_and_content(text, process_content: true, expresion: /^(.*?)\[([^\]]*)\](.*)$/m)
        RequestBodyExampleTag.new(tag_name, description, content: hash)
      end
  ....
  end
end

I need all lines in the parse tag of my factory.

And this is used like this:

...
    def configure_yard!
      ::YARD::Tags::Library.default_factory = YARD::OasRailsFactory
      yard_tags = {
        'Request body' => [:request_body, :with_request_body],
        'Request body Example' => [:request_body_example, :with_request_body_example],
        'Parameter' => [:parameter, :with_parameter],
        'Response' => [:response, :with_response],
        'Response Example' => [:response_example, :with_response_example],
        'Endpoint Tags' => [:tags],
        'Summary' => [:summary],
        'No Auth' => [:no_auth],
        'Auth methods' => [:auth, :with_types]
      }
      yard_tags.each do |tag_name, (method_name, handler)|
        ::YARD::Tags::Library.define_tag(tag_name, method_name, handler)
      end
    end
...

Currently, I am just able to read tags like:

  # @parameter offset(query) [Integer]  Used for pagination of response data (default: 25 items per response).

But I need to implement a multi-line option.

You can see the complete code in my repo: https://github.com/a-chacon/oas_rails

I hope someone can help me with this please, I will be very thankful.

@a-chacon a-chacon changed the title Multi-line tag text not working with a custom Factory. Multi-line tag text not working with a custom Factory. (Question) Mar 24, 2025
@a-chacon
Copy link
Author

I continue looking, and the problem is with my gem ;)

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

No branches or pull requests

1 participant