简体   繁体   English

生成由Servlet支持的API的文档的好方法?

[英]Good way to generate documentation for my API backed by servlets?

Does anyone know of a good tool or strategy for generating the external documentation for a collection of java servlets? 有谁知道为Java Servlet集合生成外部文档的良好工具或策略? I could, of course, use my favorite rich text editor to generate an independent document. 当然,我可以使用我最喜欢的RTF编辑器来生成一个独立的文档。 But it might be more likely to be maintained if the documentation is in the source code. 但是,如果文档在源代码中,则可能更易于维护。 Unfortunately, the problem is a bit unstructured. 不幸的是,这个问题有点非结构化。 Each servlet is a Java class, but that's the end of official structure. 每个Servlet都是一个Java类,但这只是正式结构的结尾。 Inside the servlet's doGet method, it consumes some set of URL-encoded parameters in a completely unstructured way, and produces some sort of output, say a web page or a JSON object. 在Servlet的doGet方法内部,它以完全非结构化的方式使用了一些URL编码的参数集,并产生某种输出,例如网页或JSON对象。

Javadoc does a decent job of documenting the code itself, but I want to document the API seen by clients of my service. Javadoc在记录代码本身方面做得不错,但是我想记录服务客户端看到的API。

In javadoc style, I could imagine putting documentation on the class, and maybe define some annotation to put on the doGet method's local variables that represent parameters. 在javadoc风格中,我可以想象将文档放到类上,并且可能定义一些注释以放到代表参数的doGet方法的局部变量上。 But I'd still need specialized processing -- I don't want what javadoc would defaultly produce. 但是我仍然需要专门的处理-我不希望javadoc默认产生什么。

(Yes, I've seen this other question What's the best way to generate a REST API's documentation? , which has no encouraging answers, but I thought I'd try rephrasing the question slightly.) (是的,我已经看到了另一个问题,生成REST API文档的最佳方法是什么? ,它没有令人鼓舞的答案,但我想我会稍微改一下这个问题。)

I'd say you should add a couple of properties to your servlets - add a parameters property and a response_details property (or something similar). 我想说您应该在Servlet中添加几个属性-添加parameters属性和response_details属性(或类似属性)。 Then require those as part of your servlet signature; 然后将这些作为servlet签名的一部分; they can contain strings in some popular text format (Markdown, ReST?) which describes the input and output of that servlet. 它们可以包含一些流行的文本格式(Markdown,ReST?)的字符串,这些字符串描述了该servlet的输入和输出。

You can then just introspect the servlet classes, run the resulting strings through the appropriate existing processor for whatever markup format you use, and viola, docs. 然后,您可以内省servlet类,通过适当的现有处理器以使用的任何标记格式和中提琴文档运行结果字符串。

You could add more structure to what's actually required in those properties if you wanted - for instance, parameters could be required to be a Map<String,String> or something like that. 如果需要,可以向这些属性中实际需要的内容添加更多结构-例如, parameters可能需要为Map<String,String>或类似的东西。 It's all up to you. 这一切都取决于你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM