Skip to content

Commit

Permalink
feat!: adds support for duration in java (#1604)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethaasan authored Nov 13, 2023
1 parent 9df2ef4 commit e76e394
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
62 changes: 62 additions & 0 deletions docs/migrations/version-2-to-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Migration from v2 to v3

This document contains all the breaking changes and migrations guidelines for adapting your code to the new version.

### TypeScript

Is not affected by this change.

### JavaScript

Is not affected by this change.

### C#

Is not affected by this change.

### Java

#### java.time.Duration is used when format is duration

This example used to generate a `String`, but is now instead using `java.time.Duration`.

```yaml
type: object
properties:
duration:
type: string
format: duration
```
will generate
```java
public class TestClass {
private java.time.Duration duration;
...
}
```

### Kotlin

Is not affected by this change.

### Rust

Is not affected by this change.

### Python

Is not affected by this change.

### Go

Is not affected by this change.

### Dart

Is not affected by this change.

### C++

Is not affected by this change.
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ module.exports = {
'<rootDir>/examples/TEMPLATE',
'<rootDir>/test/generators/template',
'<rootDir>/test/processors/TemplateInputProcessor.spec.ts'
]
],
watchPathIgnorePatterns: ['<rootDir>/node_modules']
};
2 changes: 2 additions & 0 deletions src/generators/java/JavaConstrainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export const JavaDefaultTypeMapping: JavaTypeMapping = {
case 'dateTime':
case 'date-time':
return 'java.time.OffsetDateTime';
case 'duration':
return 'java.time.Duration';
case 'binary':
return 'byte[]';
default:
Expand Down
13 changes: 13 additions & 0 deletions test/generators/java/JavaConstrainer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,19 @@ describe('JavaConstrainer', () => {
});
expect(type).toEqual('byte[]');
});
test('should render Duration when format has duration format', () => {
const model = new ConstrainedStringModel(
'test',
{},
{ format: 'duration' },
''
);
const type = JavaDefaultTypeMapping.String({
constrainedModel: model,
...defaultOptions
});
expect(type).toEqual('java.time.Duration');
});
});
describe('Boolean', () => {
test('should render type', () => {
Expand Down

0 comments on commit e76e394

Please sign in to comment.