Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#130 custom enum field #147

Merged

Conversation

jorre127
Copy link
Contributor

@jorre127 jorre127 commented Sep 6, 2023

fixes #130

@jorre127 jorre127 changed the base branch from master to feature/#142-up-test-coverage September 6, 2023 10:58
Base automatically changed from feature/#142-up-test-coverage to master September 7, 2023 10:30
@vanlooverenkoen vanlooverenkoen changed the base branch from master to feature/#135-map-with-list September 7, 2023 10:49
@vanlooverenkoen
Copy link
Contributor

Tested this:

DoubleStatus:
  path: status
  type: enum
  properties:
    value:
      type: double
      is_json_key: true
  values:
    status_0:
      properties:
        value: 0.1
    status_1:

and it gave me this:

// GENERATED CODE - DO NOT MODIFY BY HAND

import 'package:json_annotation/json_annotation.dart';

enum DoubleStatus {
  @JsonValue(0.1)
  STATUS_0(
    value: 0.1,
  ),
  @JsonValue(null)  <================ error ====================>
  STATUS_1(
    value: null, <================ error ====================>
  );

  final double value;

  const DoubleStatus({
    required this.value,
  });
}

@vanlooverenkoen
Copy link
Contributor

rename is_json_key to is_json_value

}

final deprecatedGenerateMap = value['generate_map'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this deprecated? Because the map is still needed. but it should use the values fields from the enum values instead. Otherwise we will have to write our own mapping each time we want to map something. Keeping this logic will make it the same for all projects

@ikbendewilliam
Copy link
Contributor

There is an issue with the lowercasing in enum names
This config results in this dart code:

    inBrowser:
      properties:
        value: inBrowser
  @JsonValue('inBrowser')
  inbrowser(
    value: 'inBrowser',
  );

I would expect inbrowser to still have a capital B

Copy link
Contributor

@ikbendewilliam ikbendewilliam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment in conversation

@ikbendewilliam ikbendewilliam merged commit 121e5d1 into feature/#135-map-with-list Sep 15, 2023
@ikbendewilliam ikbendewilliam deleted the feature/#130-custom-enum-field branch September 15, 2023 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom fields on enum
3 participants