Skip to content

4.2.0 generates invalid Dart code when OpenAPI descriptions contain newlines (\n) #64

Description

@TimvdVooren

When generating API clients from an OpenAPI specification that contains multi-line descriptions with \n characters, swagger_to_dart generates invalid Dart code that cannot be formatted by dart_style.

Environment
swagger_to_dart: 4.1.0 and 4.2.0
dart_style: 3.0.0+
Dart SDK: 3.10.4

Problem
The generator embeds OpenAPI descriptions into @Extras() annotations using raw strings (r'...'). However, it does not properly handle \n characters in these descriptions, resulting in literal newlines within raw strings, which is invalid Dart syntax.

Example
OpenAPI specification:

{
  "description": "HTTP proxy endpoint.\n\nArgs:\n    request: The original request from client.\n\nReturns:\n    The response from target server."
}

Error

Could not format because the source could not be parsed:
Unterminated string literal.

Expected Behavior
The generator should either:

  1. Use regular strings (not raw strings) and properly escape the content
  2. Replace \n with \n in raw strings
  3. Use triple-quoted strings for multi-line content

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions