swagger_parser icon indicating copy to clipboard operation
swagger_parser copied to clipboard

Missing concrete implementations of 'getter mixin....

Open jlambright opened this issue 3 months ago • 7 comments

Steps to reproduce

I'm seeing this Missing concrete implementations of 'getter mixin...' error on every model that is being generated (when using freezed). Coupled with output like this in the console:

W json_serializable on lib/gen/models/token_data.dart:
  Field `roomName` has conflicting `JsonKey.name` annotations: both constructor parameter and class field have this annotation. Using constructor parameter value.
W json_serializable on lib/gen/models/token_data.dart:
  Field `serverUrl` has conflicting `JsonKey.name` annotations: both constructor parameter and class field have this annotation. Using constructor parameter value.

Expected results

I'd expect models to be generated without syntax errors.

Actual results

Models require manually adding getters for the missing properties.

Your OpenApi snippet

I can't provide that information.

Code sample

Code sample
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, unused_import, invalid_annotation_target, unnecessary_import

import 'package:freezed_annotation/freezed_annotation.dart';

import 'metadata_model.dart';

part 'boolean_list_response.freezed.dart';
part 'boolean_list_response.g.dart';

@Freezed()
class BooleanListResponse with _$BooleanListResponse {
  const factory BooleanListResponse({
    required MetadataModel metadata,
    required List<bool>? data,
  }) = _BooleanListResponse;
  
  factory BooleanListResponse.fromJson(Map<String, Object?> json) => _$BooleanListResponseFromJson(json);
}

Logs

Logs
[Paste your logs here]

Dart version and used packages versions

Dart version
Dart SDK version: 3.9.2 (stable) (Wed Aug 27 03:49:40 2025 -0700) on "linux_x64"
Packages version
dependencies:
  dio: ^5.8.0+1
  freezed_annotation: ^3.1.0
  json_annotation: ^4.9.0
  retrofit: ^4.7.0

dev_dependencies:
  build_runner: ^2.1.1
  carapacik_lints: ^1.12.0
  freezed: ^3.2.0
  json_serializable: ^6.10.0
  retrofit_generator: ^10.0.1
  swagger_parser: ^1.30.0

jlambright avatar Sep 26 '25 04:09 jlambright

I think this is the root cause of the issue:

https://github.com/rrousselGit/freezed/issues/1240

jlambright avatar Sep 26 '25 18:09 jlambright

So the issue is again in swagger_parser - which fails in support that freezed version??

jayjah avatar Sep 30 '25 12:09 jayjah

Yes. There was a switch moving towards abstract and sealed classes for freezed. I can't remember which version that started with.

On Tue, Sep 30, 2025, 8:58 AM Markus @.***> wrote:

jayjah left a comment (Carapacik/swagger_parser#380) https://github.com/Carapacik/swagger_parser/issues/380#issuecomment-3351992385

So the issue is again in swagger_parser - which fails in support that freezed version??

— Reply to this email directly, view it on GitHub https://github.com/Carapacik/swagger_parser/issues/380#issuecomment-3351992385, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGBYI7RGDLXNWC7RIB5BST3VJ5ARAVCNFSM6AAAAACHRSKJB6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGNJRHE4TEMZYGU . You are receiving this because you authored the thread.Message ID: @.***>

jlambright avatar Sep 30 '25 13:09 jlambright

any solutions?

woogi-kang avatar Oct 02 '25 06:10 woogi-kang

That's the question, a person could leverage a post build script, to add the correct keywords, but that is tedious and has the potential to introduce problems.

Ideally, we'd get a new a new version of swagger_parser which has had it's class/model templates updated.

jlambright avatar Oct 02 '25 10:10 jlambright

Here is a sample post-gen script:


#!/usr/bin/env dart

import 'dart:io';

Future<void> main() async {
  print('Fixing generated freezed models...');
  
  final modelsDir = Directory('lib/gen/models');
  if (!await modelsDir.exists()) {
    print('Error: lib/gen/models directory not found');
    exit(1);
  }
  
  final files = await modelsDir
      .list()
      .where((e) => e is File && e.path.endsWith('.dart') && !e.path.endsWith('.freezed.dart') && !e.path.endsWith('.g.dart'))
      .cast<File>()
      .toList();
  
  for (final file in files) {
    var content = await file.readAsString();
    bool modified = false;
    
    // Find class with freezed mixin
    final classRegex = RegExp(r'class (\w+) with _\$\1 \{');
    final match = classRegex.firstMatch(content);
    
    if (match != null) {
      final className = match.group(1)!;
      
      // Add const constructor if not present
      if (!content.contains('const $className._();')) {
        content = content.replaceFirst(
          'class $className with _\$$className {',
          'class $className with _\$$className {\n  const $className._();',
        );
        modified = true;
      }
    }
    
    if (modified) {
      await file.writeAsString(content);
      print('Fixed: ${file.path}');
    }
  }
  
  print('\nRunning build_runner to generate .freezed.dart files...');
  
  final result = await Process.run(
    'dart',
    ['run', 'build_runner', 'build', '--delete-conflicting-outputs'],
    workingDirectory: Directory.current.path,
    runInShell: true,
  );
  
  stdout.write(result.stdout);
  stderr.write(result.stderr);
  
  if (result.exitCode != 0) {
    print('Error: build_runner failed with exit code ${result.exitCode}');
    exit(result.exitCode);
  }
  
  print('Post-generation completed successfully!');
}

jlambright avatar Oct 06 '25 15:10 jlambright

you can use use_freezed3: true

Image

andrea689 avatar Oct 08 '25 13:10 andrea689