"Text with **bold**"
is converted from Markdown to HTML as
+ * "Text with <strong>bold</strong> text"
and then
+ * the default compiler with HTML escaping on turns this into
+ * "Text with <strong>bold</strong> text"
.
+ * Here, we disable escaping by setting the compiler to {@link Escapers#NONE
+ * Escapers.NONE}
+ */
+ @Override
+ public Compiler processCompiler(Compiler compiler) {
+ return compiler.withEscaper(Escapers.NONE);
+ }
+
+ private Markdown markdownConverter = new Markdown();
+
+ private static final boolean CONVERT_TO_MARKDOWN_VIA_ESCAPE_TEXT = false;
+
+ /**
+ * Convert Markdown text to HTML
+ * @param input text in Markdown; may be null.
+ * @return the text, converted to Markdown. For null input, "" is returned.
+ */
+ public String toHtml(String input) {
+ if (input == null)
+ return "";
+ return markdownConverter.toHtml(input);
+ }
+
+ public void preprocessSwagger(Swagger swagger) {
+ Info info = swagger.getInfo();
+ info.setDescription(toHtml(info.getDescription()));
+ info.setTitle(toHtml(info.getTitle()));
+ Map...
. + * @param markdown text with Markdown styles. Ifnull,
""
is returned.
+ * @return HTML rendering from the Markdown
+ */
+ public String toHtml(String markdown) {
+ if (markdown == null)
+ return "";
+ Node document = parser.parse(markdown);
+ String html = renderer.render(document);
+ html = unwrapped(html);
+ return html;
+ }
+
+ // The CommonMark library wraps the HTML with
+ // ... html ...
\n + // This method removes that markup wrapper if there are no otherelements, + // do that Markdown can be used in non-block contexts such as operation summary etc. + private static final String P_END = "
\n"; + private static final String P_START = "";
+ private String unwrapped(String html) {
+ if (html.startsWith(P_START) && html.endsWith(P_END)
+ && html.lastIndexOf(P_START) == 0)
+ return html.substring(P_START.length(),
+ html.length() - P_END.length());
+ else
+ return html;
+ }
+}
diff --git a/modules/swagger-codegen/src/test/resources/2_0/markdown.yaml b/modules/swagger-codegen/src/test/resources/2_0/markdown.yaml
new file mode 100644
index 00000000000..efb852f4036
--- /dev/null
+++ b/modules/swagger-codegen/src/test/resources/2_0/markdown.yaml
@@ -0,0 +1,75 @@
+swagger: '2.0'
+
+info:
+ version: '0.1.0'
+ title: An *API* with more **Markdown** in summary, description, and other text
+ description: >
+ Not really a *pseudo-randum* number generator API.
+ This API uses [Markdown](http://daringfireball.net/projects/markdown/syntax)
+ in text:
+
+ 1. in this API description
+
+ 1. in operation summaries
+
+ 1. in operation descriptions
+
+ 1. in schema (model) titles and descriptions
+
+ 1. in schema (model) member descriptions
+
+schemes:
+ - http
+host: api.example.com
+basePath: /v1
+tags:
+ - name: tag1
+ description: A simple API **tag**
+securityDefinitions:
+ apiKey:
+ type: apiKey
+ in: header
+ name: api_key
+security:
+ - apiKey: []
+
+paths:
+
+ /random:
+ get:
+ tags:
+ - tag1
+ summary: A single *random* result
+ description: Return a single *random* result from a given seed
+ operationId: getRandomNumber
+ parameters:
+ - name: seed
+ in: query
+ description: A random number *seed*.
+ required: true
+ type: string
+ responses:
+ '200':
+ description: Operation *succeded*
+ schema:
+ $ref: '#/definitions/RandomNumber'
+ '404':
+ description: Invalid or omitted *seed*. Seeds must be **valid** numbers.
+
+definitions:
+ RandomNumber:
+ title: '*Pseudo-random* number'
+ description: A *pseudo-random* number generated from a seed.
+ properties:
+ value:
+ description: The *pseudo-random* number
+ type: number
+ format: double
+ seed:
+ description: The `seed` used to generate this number
+ type: number
+ format: double
+ sequence:
+ description: The sequence number of this random number.
+ type: integer
+ format: int64
diff --git a/pom.xml b/pom.xml
index c1270d71aeb..2aff5fef3cd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -772,7 +772,6 @@
Not really a pseudo-randum number generator API. This API uses Markdown in text:
+get /random
get /random
{
+ "sequence" : 1,
+ "seed" : 6.027456183070403,
+ "value" : 0.8008281904610115
+}
+
+
+ RandomNumber
- Pseudo-random number Upspecial-key
to test the authorization filters.[ {
- "tags" : [ {
- "id" : 7,
- "name" : "aeiou"
- } ],
- "id" : 2,
- "category" : {
- "id" : 2,
- "name" : "aeiou"
- },
- "status" : "available",
+ "photoUrls" : [ "aeiou" ],
"name" : "doggie",
- "photoUrls" : [ "aeiou" ]
+ "id" : 0,
+ "category" : {
+ "name" : "aeiou",
+ "id" : 6
+ },
+ "tags" : [ {
+ "name" : "aeiou",
+ "id" : 1
+ } ],
+ "status" : "available"
} ]
[ {
- "tags" : [ {
- "id" : 1,
- "name" : "aeiou"
- } ],
- "id" : 9,
- "category" : {
- "id" : 4,
- "name" : "aeiou"
- },
- "status" : "available",
+ "photoUrls" : [ "aeiou" ],
"name" : "doggie",
- "photoUrls" : [ "aeiou" ]
+ "id" : 0,
+ "category" : {
+ "name" : "aeiou",
+ "id" : 6
+ },
+ "tags" : [ {
+ "name" : "aeiou",
+ "id" : 1
+ } ],
+ "status" : "available"
} ]
{
- "tags" : [ {
- "id" : 5,
- "name" : "aeiou"
- } ],
- "id" : 8,
- "category" : {
- "id" : 3,
- "name" : "aeiou"
- },
- "status" : "available",
+ "photoUrls" : [ "aeiou" ],
"name" : "doggie",
- "photoUrls" : [ "aeiou" ]
+ "id" : 0,
+ "category" : {
+ "name" : "aeiou",
+ "id" : 6
+ },
+ "tags" : [ {
+ "name" : "aeiou",
+ "id" : 1
+ } ],
+ "status" : "available"
}
{
- "message" : "aeiou",
- "code" : 3,
- "type" : "aeiou"
+ "code" : 0,
+ "type" : "aeiou",
+ "message" : "aeiou"
}
{
- "key" : 9
+ "key" : 0
}
get /store/order/{orderId}
{
- "id" : 5,
- "petId" : 8,
+ "petId" : 6,
+ "quantity" : 1,
+ "id" : 0,
+ "shipDate" : "2000-01-23T04:56:07.000+00:00",
"complete" : false,
- "status" : "placed",
- "quantity" : 4,
- "shipDate" : "2000-01-23T04:56:07.000+00:00"
+ "status" : "placed"
}
{
- "id" : 6,
- "petId" : 9,
+ "petId" : 6,
+ "quantity" : 1,
+ "id" : 0,
+ "shipDate" : "2000-01-23T04:56:07.000+00:00",
"complete" : false,
- "status" : "placed",
- "quantity" : 2,
- "shipDate" : "2000-01-23T04:56:07.000+00:00"
+ "status" : "placed"
}
{
- "id" : 4,
- "lastName" : "aeiou",
- "phone" : "aeiou",
- "username" : "aeiou",
- "email" : "aeiou",
- "userStatus" : 1,
"firstName" : "aeiou",
- "password" : "aeiou"
+ "lastName" : "aeiou",
+ "password" : "aeiou",
+ "userStatus" : 6,
+ "phone" : "aeiou",
+ "id" : 0,
+ "email" : "aeiou",
+ "username" : "aeiou"
}