refactor(dart): align enum description field name with the DefaultCodegen

Merged
MA
4mo ago
+67-69

This changes how enum descriptions are handled in Dart, and aligns the behavior with the DefaultCodegen.

The behavioral change is that we look for enumDescription rather than description in allowableValues -> enumVars. This can unexpectedly affect a consumer that redefines the template, since now the codegen will expose enumDescription rather than description. The fallback is the update the local template to also use enumDescription.

The change from description to enumDescription also ensures that the enum's own description is not leaked to each enum item. This occurs now when the enum items do not have a description themselves, which in turn makes the mustache parses look further up the tree for a value (and thus find the CodegenModel's description). An enum like the one below is an example that would leak the description.

components:
  schemas:
    Order:
      status:
        type: string
        description: Order Status
        enum:
          - placed
          - approved
          - delivered

I have instead aligned all Dart enum classes so that they place the schema description once on the class itself instead. This behavior already exists on some enums.

The interpretation of the vendor extension x-enum-values have also been extracted to the EnumUtils since it is a format that comes from Bungie, and it might be of interest to use in other Codegens too. See for example https://github.com/OpenAPITools/openapi-generator/pull/1486.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Dart commitee:
@jaumard (2018/09) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08)


Summary by cubic

Aligns Dart enum descriptions with DefaultCodegen: enum items now expose enumDescription, and the schema description is emitted once on the enum type. Standardizes Bungie x-enum-values handling and updates templates, tests, and samples.

  • Refactors

    • Update built_value and json_serializable templates (inline and non-inline) to read enumDescription for item docs and render the enum’s description once at the type.
    • Centralize x-enum-values parsing in EnumUtils (BUNGIE_X_ENUM_VALUES, getBungieEnumValues) and use it in AbstractDartCodegen; tests and samples updated to expect enumDescription.
  • Migration

    • If you customized Dart enum templates, replace enum item description with enumDescription.