9

ServiceStack marks rest paths for web services using c# attributes.

For example

[RestService("/hello1")]
[RestService("/hello2")]
public class Hello

I would like to make Doxygen include values of the RestService attribute in the doxygen output for the Hello class. I'm not concerned too much with pretty formattin if the full line with brackets is included in the output document.

Any suggestions?

A quick and dirty trick would be a preferable to writing a Doxygen extension ;)

Cheers

Tymek

====EDIT

The Python version (so will work on Windows easily) of doxygen user's answer would be:

#!/usr/bin/env python
import sys
import re

if (len(sys.argv) < 2):
    print "No input file"
else:
    f = open(sys.argv[1])
    line = f.readline()
    while line:
        re1 = re.compile("\[RestService\(\"(.*)\",.*\"(.*)\"\)]")
        re1.search(line)
        sys.stdout.write(re1.sub(r"/** \\b RestService: \2 \1\\n */\n", line))
        #sys.stdout.write(line)
        line = f.readline()
    f.close()

and the DOXYFILE would have:

INPUT_FILTER           = "doxygenFilter.py"

2 Answers 2

10

You could make an input filter that converts a line with

[RestService("/hello1")]

to

/** \b RestService: "/hello1"\n */

like for instance by putting following piece of perl magic in a file called filter.pl:

open(F, "<", $ARGV[0]);
while(<F>) { /^\s*\[RestService\((.*)\)\]\s*$/ ? 
             print "/** \\b RestService: $1\\n */\n" : print $_; }

and use that with the INPUT_FILTER tag in the Doxyfile:

INPUT_FILTER           = "perl filter.pl"
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of using a python or perl scrip, it made more sense to me to do it in C#

As an added bonus inline xml documentation for attributes will also be added to the documentation. Example:

[FromForm(Name = "e_mail")]
[Required] /// <div>Specifies that a data field value is required.</div><p>More info...</p>

Name the C# console project "AttributesDocumenter" and use the resulting binary with the INPUT_FILTER tag in the Doxyfile: INPUT_FILTER = "AttributesDocumenter.exe"

using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AttributesDocumenter
{
    class Program
    {
        static async Task Main(string[] args)
        {
            if (args.Length < 1)
            {
                await Console.Out.WriteLineAsync("No input file");
                return;
            }

            var f = File.OpenText(args[0]);
            while (!f.EndOfStream)
            {
                var line = await f.ReadLineAsync();
                var match = Regex.Match(line, @"\s*\[(.*)]\s*");

                if (match.Success)
                {
                    var inlineXmlComment = Regex.Match(line, @".*\/\/\/");
                    if (inlineXmlComment.Success)
                    {
                        var inlineXmlCommentList = new Regex(@"\s*(</?([^>/]*)/?>).*").Matches(line);
                        var inlineXmlCommentCombined = string.Join("", inlineXmlCommentList);
                        await Console.Out.WriteLineAsync($"{inlineXmlComment.Value} <para><b>Attribute:</b> {match.Value}</para> {inlineXmlCommentCombined}");
                    }
                    else
                    {
                        await Console.Out.WriteLineAsync($"{line} /// <para><b>Attribute:</b> {match.Value}</para>");
                    }
                }
                else
                {
                    await Console.Out.WriteLineAsync(line);
                }
            }
        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.