Skip to content

Commit

Permalink
#130: updated readme and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
jorre127 committed Sep 6, 2023
1 parent ec11c8c commit fd9d9f8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
# Changelog
## [7.0.0] - 2023-08-14
- *BREAKING CHANGE*: Every type is now defined inline, this means that 'required' is no longer supported, if a field isn't nullable it is automatically required. This also means that the 'array' type is no longer supported and is instead just defined like 'List<T>'.
- *BREAKING CHANGE*: The way enums are defined has changed, see readme for more information. You can now add properties to enums, optional and default values are supported.
- Logs of build runner now get shown in real time.

## [6.3.0] - 2023-06-05
Expand Down
84 changes: 63 additions & 21 deletions README.md
Expand Up @@ -376,64 +376,106 @@ BookCase:
Currently all basic types are supported, simple Lists and Maps (no nested types, no nullable generic parameters) as well as references to other objects.
Items post-fixed with `?` will be marked optional.

## Enum support
## Enum support (as of v7.0.0 enums now support properties)

Add enums with custom values (can be mapped to String,double,int)
Add simple enums, the name of the enum value (MALE, FEMALE, X, Y) will be used when parsing from json

```yaml
Gender:
path: webservice/user
type: enum
properties:
values:
MALE:
value: _mAl3
FEMALE:
value: femAle
X:
value: X
Y:
```

### Generate mapping

For enums, it is also possible to have a map generated that maps from the enum value to its string representation and reverse. To enable this, use `generate_map: true`
Add enums with custom properties (currently supported types are int, double, bool and String)

```yaml
Gender:
path: webservice/user
type: enum
generate_map: true
properties:
abbreviation: String
values:
MALE:
value: _mAl3
properties:
abbreviation: m
FEMALE:
value: femAle
properties:
abbreviation: f
X:
value: X
properties:
abbreviation: x
Y:
properties:
abbreviation: y
```

### Generate mapping extensions
Define custom json key using is_json_key, the value of this property will then be used to parse from json

```yaml
Gender:
path: webservice/user
type: enum
properties:
key:
type: String
is_json_key: true
abbreviation: String
values:
MALE:
properties:
key: male
abbreviation: m
FEMALE:
properties:
key: female
abbreviation: f
X:
properties:
key: x
abbreviation: x
Y:
properties:
key: y
abbreviation: y
```

When generating maps, it is also possible to specify that special extension functions should be added that return either the string value or that takes a string value and tries to
convert it to the enum value. To enable this, use `generate_map: true` **AND** `generate_extensions: true`
Optional and default values are supported. If value isn't defined for a property then it will use the defaultValue. If a property is optional and no value is given it is null.

```yaml
Gender:
path: webservice/user
type: enum
generate_map: true
generate_extensions: true
properties:
key:
type: String
is_json_key: true
abbreviation:
type: String
default_value: m
lastName: String?
values:
MALE:
value: _mAl3
properties:
key: male
FEMALE:
value: femAle
properties:
key: female
abbreviation: f
X:
value: X
properties:
key: x
Y:
properties:
key: y
lastName: lastName
```

### Generate mapping extensions And Generate mapping are no longer supported as of V7.0.0, use properties instead
### Use unknownEnumValue

```yaml
Expand Down

0 comments on commit fd9d9f8

Please sign in to comment.