quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

[FEATURE]: Add option 'acronym-style' to Dart

Open vitordeap opened this issue 7 months ago • 0 comments

Context (Input, Language)

Input Format: JSONSchema Output Language: Dart

Description

I use quicktype to generate Contracts for multiple languages, and by default all my contracts were implemented using snake_case (most of the systems are python based).

In Dart, the standard is to use camelCase, but as I am defining contracts, I end up with inconsistency when using Dart. The acronym-style parameter available for other languages would suffice this problem, specifically the 'original' option.

Current Behaviour / Output

All class properties are converted to camelCase.

Proposed Behaviour / Output

All class properties are mantained as the initial definition.

Solution

When using the CLI and the option acronym-style=original is selected, no case conversion is made.

Context

Adding an example just for illustration:

JSONSchema

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "Dog",
    "type": "object",
    "properties": {
        "name": {
            "type": "string"
        },
        "fur_color": {
            "type": "string",
            "index": true
        }
    }
}

Generated Dart Class

class Dog {
    String? name;
    String? furColor; // -------> This property should be `fur_color`

    Dog({
        this.name,
        this.furColor,
    });

    factory Dog.fromJson(Map<String, dynamic> json) => Dog(
        name: json["name"],
        furColor: json["furColor"],
    );

    Map<String, dynamic> toJson() => {
        "name": name,
        "furColor": furColor,
    };
}

vitordeap avatar Mar 17 '25 15:03 vitordeap