swagger-api / swagger-api/swagger-codegen-generators

[html] Lists in response description, model description and property description are not generated properly.

Open Beginner friendly
#1,087 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

As far as I know, the 'description' property in the swagger spec supports lists using * like:

* item1: 1
* item2: 2

The method description is correctly rendered as:

  • item1: 1
  • item2: 2

but in the response, model and property description it is incorrectly rendered as:

<ul> <li>item1: 1</li> <li>item2: 2</li> </ul>

There is a merged PR that solved the problem for the method description but not for the other cases (https://github.com/swagger-api/swagger-codegen-generators/pull/982)

This is a sample that shows the problem:

openapi: 3.0.0

info:
  title: API
  description: Process.
  version: 1.0.0

tags:
  - name: info
    description: Provides info.

paths:

  /info:
    post:
      description: |
              Right:
              * item1: 1
              * item2: 2

      responses:
        "200":
          description: |
              Wrong:
              * item3: 3
              * item4: 4
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Object"

components:
  schemas:

    Object:
      description: |
              Wrong:
              * item5: 5
              * item6: 6
      type: object
      properties:
        prop:
          description: |
              Wrong:
              * item7: 7
              * item8: 8

This is a diff that solves the problem:

diff --git a/src/main/resources/handlebars/htmlDocs/index.mustache b/src/main/resources/handlebars/htmlDocs/index.mustache
index 6d2c2001..d68a64c8 100644
--- a/src/main/resources/handlebars/htmlDocs/index.mustache
+++ b/src/main/resources/handlebars/htmlDocs/index.mustache
@@ -133,7 +133,7 @@
     <h3 class="field-label">Responses</h3>
     {{#responses}}
     <h4 class="field-label">{{code}}</h4>
-    {{message}}
+    {{{message}}}
         {{#simpleType}}<a href="#{{dataType}}">{{dataType}}</a>{{/simpleType}}
     {{#examples}}
     <h3 class="field-label">Example data</h3>
@@ -164,9 +164,9 @@
   {{#model}}
   <div class="model">
     <h3><a name="{{name}}"><code>{{name}}</code>{{#title}} - {{title}}{{/title}}</a> <a class="up" href="#__Models">Up</a></h3>
-    {{#unescapedDescription}}<div class='model-description'>{{unescapedDescription}}</div>{{/unescapedDescription}}
+    {{#unescapedDescription}}<div class='model-description'>{{{unescapedDescription}}}</div>{{/unescapedDescription}}
     <div class="field-items">
-      {{#vars}}<div class="param">{{name}} {{^required}}(optional){{/required}}</div><div class="param-desc"><span class="param-type">{{#isNot this 'primitive-type'}}<a href="#{{complexType}}">{{datatype}}</a>{{/isNot}}</span> {{unescapedDescription}} {{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}</div>
+	    {{#vars}}<div class="param">{{name}} {{^required}}(optional){{/required}}</div><div class="param-desc"><span class="param-type">{{#isNot this 'primitive-type'}}<a href="#{{complexType}}">{{datatype}}</a>{{/isNot}}</span> {{{unescapedDescription}}} {{#dataFormat}}format: {{{dataFormat}}}{{/dataFormat}}</div>
       {{#is this 'enum'}}
         <div class="param-enum-header">Enum:</div>
         {{#_enum}}<div class="param-enum">{{this}}</div>{{/_enum}}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/main/resources/handlebars/htmlDocs/index.mustache and inspect the response, model, and property description expressions shown in the issue. Generate the HTML documentation from the supplied OpenAPI example and verify that all list descriptions render as HTML lists rather than escaped tags.

Written by the indexing model from the issue text.

Assessment

Tech stack
html
Domain
documentation
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.