OpenAPITools / OpenAPITools/openapi-generator

[BUG][dart][dart-dio] Dart Docs Improperly Formatted

Open
#21,010 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I am having trouble getting basic doc formatting to work with the Dart code generator.

It seems that newlines are not being respected in multi line strings

Additional html features don't work (such as the <b> tag), but I am considering that out of scope for this issue.

openapi-generator version

OpenAPI Version 3.1.0

OpenAPI declaration file content or url
openapi: 3.1.0

# Case 1: Description is displayed on the same line as the summary
paths:
  /api/v1/location/{location_id}:
    get:
      summary: Specific Authorized Location
      description: >
        Retrieve data for a single location identified by the `location_id` provided, 
        if the user is authorized to access the location.
      operationId: getLocation
      parameters: [ ... ]
      responses: [ ... ]

# Case 2: Newlines are ignored
components:
  schemas:
    Alert:
      type: object
      description: >
        An alert indicating that something is not behaving as expected
      properties:
        severity:
          type: string
          # See: https://github.com/OAI/OpenAPI-Specification/issues/348
          description: |
            The severity of the alert.
            
            * `alarm` - Action is urgently required.
            * `alert` - Actions should be taken to fix the problem.
            * `intrigue` - Low-severity alert; things are not functioning as they should.
          enum: [ alarm, alert, intrigue ]
      required: [ severity ]
Generation Details

I am using the openapi_generator pub package, which I understand to be a simple wrapper around the java implementation.

Steps to reproduce

The above sample generates the following client code:

Case 1:

  /// Specific Authorized Location
  /// Retrieve data for a single location identified by the &#x60;location_id&#x60; provided,  if the user is authorized to access the location.
  ///
  /// Parameters:
  /// * ...
  ///
  /// Returns a [Future] containing a [Response] with a [LocationData] as data
  /// Throws [DioException] if API call or serialization fails
  Future<Response<LocationData>> getLocation({ ... })

which incorrectly renders as:

Specific Authorized Location Retrieve data for a single location identified by the `location_id` provided, if the user is authorized to access the location.

Case 2:

/// An alert indicating that something is not behaving as expected
///
/// Properties:
/// * [severity] - The severity of the alert.  * `alarm` - Action is urgently required. * `alert` - Actions should be taken to fix the problem. * `intrigue` - Low-severity alert; things are not functioning as they should.
@BuiltValue()
abstract class Alert implements Built<Alert, AlertBuilder> {
    ...
}

(The enum description is correctly displayed in the Swagger UI preview from the IntelliJ OpenAPI Specifications plugin)

Related issues/PRs
Suggest a fix

I believe that the dart generator is stripping newline characters and failing to un-escape symbols like ` and <>.

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 by reproducing the issue with the provided OpenAPI YAML through the openapi_generator Dart package and inspect the generated Dart documentation. Trace the Dart generator's handling of multiline descriptions, escaped symbols, and enum descriptions. Done means generated documentation preserves intended line breaks and renders the reported symbols correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.