Skip to content

Commit dbb501e

Browse files
authored
Merge branch 'next' into update_next_with_master_6
2 parents 8a5e10f + 9b6984d commit dbb501e

File tree

10 files changed

+88
-52
lines changed

10 files changed

+88
-52
lines changed

docs/migrations/version-4-to-5.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Migration from v4 to v5
2+
3+
This document contain all the breaking changes and migrations guidelines for adapting your code to the new version.

examples/java-generate-jackson-annotation/__snapshots__/index.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
exports[`Should be able to generate data models for jackson annotation and should log expected output to console 1`] = `
44
Array [
55
"public class Root {
6-
@JsonProperty(\\"min_number_prop\\")
76
@JsonInclude(JsonInclude.Include.NON_NULL)
87
private Double minNumberProp;
9-
@JsonProperty(\\"max_number_prop\\")
108
@JsonInclude(JsonInclude.Include.NON_NULL)
119
private Double maxNumberProp;
1210
@JsonAnySetter
1311
@JsonInclude(JsonInclude.Include.NON_NULL)
1412
private Map<String, Object> additionalProperties;
1513
14+
@JsonProperty(\\"min_number_prop\\")
1615
public Double getMinNumberProp() { return this.minNumberProp; }
1716
public void setMinNumberProp(Double minNumberProp) { this.minNumberProp = minNumberProp; }
1817
18+
@JsonProperty(\\"max_number_prop\\")
1919
public Double getMaxNumberProp() { return this.maxNumberProp; }
2020
public void setMaxNumberProp(Double maxNumberProp) { this.maxNumberProp = maxNumberProp; }
2121

modelina-cli/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modelina-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@asyncapi/modelina-cli",
33
"description": "CLI to work with Modelina",
4-
"version": "4.0.4",
4+
"version": "4.0.4-next.1",
55
"bin": {
66
"modelina": "./bin/run_bin"
77
},

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@asyncapi/modelina",
3-
"version": "4.0.4",
3+
"version": "4.0.4-next.1",
44
"description": "Library for generating data models based on inputs such as AsyncAPI, OpenAPI, or JSON Schema documents",
55
"license": "Apache-2.0",
66
"homepage": "https://www.modelina.org",

src/generators/java/presets/JacksonPreset.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ export const JAVA_JACKSON_PRESET: JavaPreset = {
5050
return renderer.renderBlock(blocks);
5151
}
5252

53-
blocks.push(
54-
renderer.renderAnnotation(
55-
'JsonProperty',
56-
`"${property.unconstrainedPropertyName}"`
57-
)
58-
);
59-
6053
if (!property.required) {
6154
blocks.push(
6255
renderer.renderAnnotation(
@@ -84,6 +77,13 @@ export const JAVA_JACKSON_PRESET: JavaPreset = {
8477
const blocks: string[] = [];
8578
if (hasUnwrappedOptions) {
8679
blocks.push(renderer.renderAnnotation('JsonAnyGetter'));
80+
} else {
81+
blocks.push(
82+
renderer.renderAnnotation(
83+
'JsonProperty',
84+
`"${property.unconstrainedPropertyName}"`
85+
)
86+
);
8787
}
8888
blocks.push(content);
8989
return renderer.renderBlock(blocks);

test/generators/java/__snapshots__/JavaGenerator.spec.ts.snap

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ public interface Animal {
1414
String getPetType();
1515
}",
1616
"public class Boxer implements Animal, Dog {
17-
@JsonProperty(\\"breed\\")
1817
@JsonInclude(JsonInclude.Include.NON_NULL)
1918
private final String breed = \\"Boxer\\";
20-
@JsonProperty(\\"petType\\")
2119
@JsonInclude(JsonInclude.Include.NON_NULL)
2220
private String petType;
2321
@JsonAnySetter
2422
@JsonInclude(JsonInclude.Include.NON_NULL)
2523
private Map<String, Object> additionalProperties;
2624
25+
@JsonProperty(\\"breed\\")
2726
public String getBreed() { return this.breed; }
2827
28+
@JsonProperty(\\"petType\\")
2929
@Override
3030
public String getPetType() { return this.petType; }
3131
@Override
@@ -82,13 +82,13 @@ public interface Animal {
8282
8383
}",
8484
"public class Cat implements Animal, Pet {
85-
@JsonProperty(\\"petType\\")
8685
@JsonInclude(JsonInclude.Include.NON_NULL)
8786
private String petType;
8887
@JsonAnySetter
8988
@JsonInclude(JsonInclude.Include.NON_NULL)
9089
private Map<String, Object> additionalProperties;
9190
91+
@JsonProperty(\\"petType\\")
9292
public String getPetType() { return this.petType; }
9393
public void setPetType(String petType) { this.petType = petType; }
9494
@@ -198,18 +198,18 @@ Array [
198198
"public class Event {
199199
@Valid
200200
@NotNull
201-
@JsonProperty(\\"action\\")
202201
private Action action;
203-
@JsonProperty(\\"event_time\\")
204202
@JsonInclude(JsonInclude.Include.NON_NULL)
205203
private java.time.OffsetDateTime eventTime;
206204
@JsonAnySetter
207205
@JsonInclude(JsonInclude.Include.NON_NULL)
208206
private Map<String, Object> additionalProperties;
209207
208+
@JsonProperty(\\"action\\")
210209
public Action getAction() { return this.action; }
211210
public void setAction(Action action) { this.action = action; }
212211
212+
@JsonProperty(\\"event_time\\")
213213
public java.time.OffsetDateTime getEventTime() { return this.eventTime; }
214214
public void setEventTime(java.time.OffsetDateTime eventTime) { this.eventTime = eventTime; }
215215
@@ -304,41 +304,41 @@ public interface Pet {
304304
}",
305305
"public class Dog implements Pet {
306306
@NotNull
307-
@JsonProperty(\\"id\\")
308307
private String id;
309308
@NotNull
310-
@JsonProperty(\\"source\\")
311309
private String source;
312310
@NotNull
313-
@JsonProperty(\\"specversion\\")
314311
private final String specversion = \\"1.0\\";
315312
@Valid
316313
@NotNull
317-
@JsonProperty(\\"type\\")
318314
private final CloudEventType type = CloudEventType.DOG;
319-
@JsonProperty(\\"dataschema\\")
320315
@JsonInclude(JsonInclude.Include.NON_NULL)
321316
private String dataschema;
322-
@JsonProperty(\\"time\\")
323317
@JsonInclude(JsonInclude.Include.NON_NULL)
324318
private java.time.OffsetDateTime time;
325319
@JsonAnySetter
326320
@JsonInclude(JsonInclude.Include.NON_NULL)
327321
private Map<String, Object> additionalProperties;
328322
323+
@JsonProperty(\\"id\\")
329324
public String getId() { return this.id; }
330325
public void setId(String id) { this.id = id; }
331326
327+
@JsonProperty(\\"source\\")
332328
public String getSource() { return this.source; }
333329
public void setSource(String source) { this.source = source; }
334330
331+
@JsonProperty(\\"specversion\\")
335332
public String getSpecversion() { return this.specversion; }
336333
334+
@JsonProperty(\\"type\\")
337335
public CloudEventType getType() { return this.type; }
338336
337+
@JsonProperty(\\"dataschema\\")
339338
public String getDataschema() { return this.dataschema; }
340339
public void setDataschema(String dataschema) { this.dataschema = dataschema; }
341340
341+
@JsonProperty(\\"time\\")
342342
public java.time.OffsetDateTime getTime() { return this.time; }
343343
public void setTime(java.time.OffsetDateTime time) { this.time = time; }
344344
@@ -425,41 +425,41 @@ public interface Pet {
425425
}",
426426
"public class Cat implements Pet {
427427
@NotNull
428-
@JsonProperty(\\"id\\")
429428
private String id;
430429
@NotNull
431-
@JsonProperty(\\"source\\")
432430
private String source;
433431
@NotNull
434-
@JsonProperty(\\"specversion\\")
435432
private final String specversion = \\"1.0\\";
436433
@Valid
437434
@NotNull
438-
@JsonProperty(\\"type\\")
439435
private final CloudEventType type = CloudEventType.CAT;
440-
@JsonProperty(\\"dataschema\\")
441436
@JsonInclude(JsonInclude.Include.NON_NULL)
442437
private String dataschema;
443-
@JsonProperty(\\"time\\")
444438
@JsonInclude(JsonInclude.Include.NON_NULL)
445439
private java.time.OffsetDateTime time;
446440
@JsonAnySetter
447441
@JsonInclude(JsonInclude.Include.NON_NULL)
448442
private Map<String, Object> additionalProperties;
449443
444+
@JsonProperty(\\"id\\")
450445
public String getId() { return this.id; }
451446
public void setId(String id) { this.id = id; }
452447
448+
@JsonProperty(\\"source\\")
453449
public String getSource() { return this.source; }
454450
public void setSource(String source) { this.source = source; }
455451
452+
@JsonProperty(\\"specversion\\")
456453
public String getSpecversion() { return this.specversion; }
457454
455+
@JsonProperty(\\"type\\")
458456
public CloudEventType getType() { return this.type; }
459457
458+
@JsonProperty(\\"dataschema\\")
460459
public String getDataschema() { return this.dataschema; }
461460
public void setDataschema(String dataschema) { this.dataschema = dataschema; }
462461
462+
@JsonProperty(\\"time\\")
463463
public java.time.OffsetDateTime getTime() { return this.time; }
464464
public void setTime(java.time.OffsetDateTime time) { this.time = time; }
465465
@@ -522,19 +522,19 @@ exports[`JavaGenerator oneOf/discriminator with jackson preset handle one const
522522
Array [
523523
"public class Dog {
524524
@NotNull
525-
@JsonProperty(\\"id\\")
526525
private String id;
527526
@Valid
528527
@NotNull
529-
@JsonProperty(\\"type\\")
530528
private final CloudEventType type = CloudEventType.DOG;
531529
@JsonAnySetter
532530
@JsonInclude(JsonInclude.Include.NON_NULL)
533531
private Map<String, Object> additionalProperties;
534532
533+
@JsonProperty(\\"id\\")
535534
public String getId() { return this.id; }
536535
public void setId(String id) { this.id = id; }
537536
537+
@JsonProperty(\\"type\\")
538538
public CloudEventType getType() { return this.type; }
539539
540540
@JsonAnyGetter
@@ -629,12 +629,12 @@ public interface Pet {
629629
"public class Dog implements Pet {
630630
@Valid
631631
@NotNull
632-
@JsonProperty(\\"type\\")
633632
private final DogType type = DogType.DOG;
634633
@JsonAnySetter
635634
@JsonInclude(JsonInclude.Include.NON_NULL)
636635
private Map<String, Object> additionalProperties;
637636
637+
@JsonProperty(\\"type\\")
638638
public DogType getType() { return this.type; }
639639
640640
@JsonAnyGetter
@@ -711,12 +711,12 @@ public interface Pet {
711711
"public class Cat implements Pet {
712712
@Valid
713713
@NotNull
714-
@JsonProperty(\\"type\\")
715714
private final CatType type = CatType.CAT;
716715
@JsonAnySetter
717716
@JsonInclude(JsonInclude.Include.NON_NULL)
718717
private Map<String, Object> additionalProperties;
719718
719+
@JsonProperty(\\"type\\")
720720
public CatType getType() { return this.type; }
721721
722722
@JsonAnyGetter
@@ -808,13 +808,13 @@ public interface Vehicle {
808808
}",
809809
"public class Cargo {
810810
@Valid
811-
@JsonProperty(\\"vehicle\\")
812811
@JsonInclude(JsonInclude.Include.NON_NULL)
813812
private Vehicle vehicle;
814813
@JsonAnySetter
815814
@JsonInclude(JsonInclude.Include.NON_NULL)
816815
private Map<String, Object> additionalProperties;
817816
817+
@JsonProperty(\\"vehicle\\")
818818
public Vehicle getVehicle() { return this.vehicle; }
819819
public void setVehicle(Vehicle vehicle) { this.vehicle = vehicle; }
820820
@@ -863,12 +863,12 @@ public interface Vehicle {
863863
"public class Car implements Vehicle {
864864
@Valid
865865
@NotNull
866-
@JsonProperty(\\"vehicleType\\")
867866
private final VehicleType vehicleType = VehicleType.CAR;
868867
@JsonAnySetter
869868
@JsonInclude(JsonInclude.Include.NON_NULL)
870869
private Map<String, Object> additionalProperties;
871870
871+
@JsonProperty(\\"vehicleType\\")
872872
public VehicleType getVehicleType() { return this.vehicleType; }
873873
874874
@JsonAnyGetter
@@ -945,12 +945,12 @@ public interface Vehicle {
945945
"public class Truck implements Vehicle {
946946
@Valid
947947
@NotNull
948-
@JsonProperty(\\"vehicleType\\")
949948
private final VehicleType vehicleType = VehicleType.TRUCK;
950949
@JsonAnySetter
951950
@JsonInclude(JsonInclude.Include.NON_NULL)
952951
private Map<String, Object> additionalProperties;
953952
953+
@JsonProperty(\\"vehicleType\\")
954954
public VehicleType getVehicleType() { return this.vehicleType; }
955955
956956
@JsonAnyGetter

test/generators/java/presets/JacksonPreset.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,28 @@ describe('JAVA_JACKSON_PRESET', () => {
7171
expect(models.map((model) => model.result)).toMatchSnapshot();
7272
});
7373

74+
test('should place @JsonProperty annotation on the getter', async () => {
75+
const doc = {
76+
$id: 'AnnotateGetterWithJsonProperty',
77+
type: 'object',
78+
properties: {
79+
a_property: { type: 'string' }
80+
}
81+
};
82+
83+
const generator = new JavaGenerator({
84+
presets: [JAVA_JACKSON_PRESET],
85+
processorOptions: {
86+
interpreter: {
87+
ignoreAdditionalProperties: true
88+
}
89+
}
90+
});
91+
92+
const models = await generator.generate(doc);
93+
expect(models[0].result).toMatchSnapshot();
94+
});
95+
7496
describe('union', () => {
7597
test('handle oneOf with AsyncAPI discriminator with Jackson', async () => {
7698
const asyncapiDoc = {

0 commit comments

Comments
 (0)