Skip to content

API path definitions are incorrectly converted to PascalCase #429

@tatsuhama

Description

@tatsuhama

Steps to reproduce

  1. Create an OpenAPI spec with snake_case API path definitions:
    paths:                                                                                                                                       
      /api/v1/app/user_point_balance:                                                                                                            
        get:                                                                                                                                     
          summary: Get user point balance                                                                                                        
  2. Generate Dart code using dart run swagger_parser
  3. Check the generated @GET annotation in the Retrofit client

Expected results

The generated Retrofit annotation should preserve the original case from the OpenAPI path definition:

@GET('/api/v1/app/user_point_balance')

Actual results

The API path is incorrectly converted to PascalCase:

@GET('/api/v1/app/UserPointBalance')

This results in incorrect API endpoints that don't match the backend server routes.

Your OpenApi snippet

openapi: 3.0.0                                                                                                                                  
  paths:                                                                                                                                          
    /api/v1/app/user_point_balance:                                                                                                               
      get:                                                                                                                                        
        summary: Get user point balance                                                                                                           
        operationId: getUserPointBalance                                                                                                          
        responses:                                                                                                                                
          '200':                                                                                                                                  
            description: Success                                                                                                                  
            content:                                                                                                                              
              application/json:                                                                                                                   
                schema:                                                                                                                           
                  $ref: '#/components/schemas/UserPointBalance'                                                                                   
                                                                                                                                                  
  components:                                                                                                                                     
    schemas:                                                                                                                                      
      UserPointBalance:                                                                                                                           
        type: object                                                                                                                              
        properties:                                                                                                                               
          balance:                                                                                                                                
            type: integer                      

Code sample

  @RestApi()                                                                                                                                      
  abstract class PointsClient {                                                                                                                   
    factory PointsClient(Dio dio, {String? baseUrl}) = _PointsClient;                                                                             
                                                                                                                                                  
    @GET('/api/v1/app/UserPointBalance')  // ❌ Wrong! Path converted to PascalCase                                                               
    Future<UserPointBalance> getUserPointBalance();                                                                                               
  }                                                                                                                                               
  @RestApi()                                                                                                                                      
  abstract class PointsClient {                                                                                                                   
    factory PointsClient(Dio dio, {String? baseUrl}) = _PointsClient;                                                                             
                                                                                                                                                  
    @GET('/api/v1/app/user_point_balance')  // ✅ Correct! Path preserved as snake_case                                                           
    Future<UserPointBalance> getUserPointBalance();                                                                                               
  }  

Logs

Logs
[Paste your logs here]

Dart version and used packages versions

Dart SDK version: 3.10.0 (stable)

dependencies:
retrofit: ^4.9.1

dev_dependencies:
swagger_parser: ^1.41.0

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