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

feat!: adds support for duration in java #1604

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading