Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 2551e95

Browse files
authored
Java, property getters added to map output class (#297)
* Fixes input types for map schemas * Adds empty map detection and handling * Integrates correct generics into map output types + constructor + getMapOutputInstance * Adds schema ref feature, adds missing list imports * Adds map output property methods * Adds close braces in getters * Fixes property casting in map output getters * Adds requiredKeys + optionalKeys * Writes requiredKeys + optionalKeys in 2 lines if thye are empty * Adds throwIfKeyNotPresent * Simplifies getAdditionalProperty * Adds missing import * Adds schema ref feature to docs
1 parent 5b22520 commit 2551e95

164 files changed

Lines changed: 5006 additions & 475 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/generators/java.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
355355
|PrefixItems|✗|OAS3
356356
|Properties|✓|OAS2,OAS3
357357
|PropertyNames|✗|OAS3
358+
|Ref|✓|OAS2,OAS3
358359
|Required|✓|OAS2,OAS3
359360
|Then|✗|OAS3
360361
|Type|✓|OAS2,OAS3

docs/generators/jaxrs-jersey.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
337337
|PrefixItems|✗|OAS3
338338
|Properties|✓|OAS2,OAS3
339339
|PropertyNames|✗|OAS3
340+
|Ref|✗|OAS2,OAS3
340341
|Required|✓|OAS2,OAS3
341342
|Then|✗|OAS3
342343
|Type|✓|OAS2,OAS3

docs/generators/jmeter.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
190190
|PrefixItems|✗|OAS3
191191
|Properties|✓|OAS2,OAS3
192192
|PropertyNames|✗|OAS3
193+
|Ref|✗|OAS2,OAS3
193194
|Required|✓|OAS2,OAS3
194195
|Then|✗|OAS3
195196
|Type|✓|OAS2,OAS3

docs/generators/kotlin.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
300300
|PrefixItems|✗|OAS3
301301
|Properties|✓|OAS2,OAS3
302302
|PropertyNames|✗|OAS3
303+
|Ref|✗|OAS2,OAS3
303304
|Required|✓|OAS2,OAS3
304305
|Then|✗|OAS3
305306
|Type|✓|OAS2,OAS3

docs/generators/python.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
259259
|PrefixItems|✓|OAS3
260260
|Properties|✓|OAS2,OAS3
261261
|PropertyNames|✓|OAS3
262+
|Ref|✓|OAS2,OAS3
262263
|Required|✓|OAS2,OAS3
263264
|Then|✓|OAS3
264265
|Type|✓|OAS2,OAS3

samples/client/petstore/java/src/main/java/org/openapijsonschematools/components/responses/headerswithnobody/Headers.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,27 @@ public class AdditionalProperties extends NotAnyTypeJsonSchema {}
2323
// NotAnyTypeSchema
2424

2525

26-
public static class HeadersMap extends FrozenMap<String, Object> {
27-
HeadersMap(FrozenMap<? extends String, ?> m) {
26+
public static class HeadersMap extends FrozenMap<String, String> {
27+
28+
HeadersMap(FrozenMap<String, String> m) {
29+
2830
super(m);
2931
}
30-
public static HeadersMap of(Map<String, Object> arg, SchemaConfiguration configuration) {
32+
public static final Set<String> requiredKeys = Set.of();
33+
public static final Set<String> optionalKeys = Set.of(
34+
"location"
35+
);
36+
public static HeadersMap of(Map<String, String> arg, SchemaConfiguration configuration) {
37+
3138
return Headers1.validate(arg, configuration);
3239
}
40+
41+
public String location() {
42+
43+
String key = "location";
44+
throwIfKeyNotPresent(key);
45+
return get(key);
46+
}
3347
}
3448

3549
public class Headers1 extends JsonSchema {
@@ -40,10 +54,12 @@ public class Headers1 extends JsonSchema {
4054
))),
4155
new KeywordEntry("additionalProperties", new AdditionalPropertiesValidator(AdditionalProperties.class))
4256
));
43-
protected static HeadersMap getMapOutputInstance(FrozenMap<? extends String, ?> arg) {
57+
protected static HeadersMap getMapOutputInstance(FrozenMap<String, String> arg) {
58+
4459
return new HeadersMap(arg);
4560
}
46-
public static HeadersMap validate(Map<String, Object> arg, SchemaConfiguration configuration) {
61+
public static HeadersMap validate(Map<String, String> arg, SchemaConfiguration configuration) {
62+
4763
return JsonSchema.validate(Headers1.class, arg, configuration);
4864
}
4965
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/components/responses/successinlinecontentandheader/Headers.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,27 @@ public class AdditionalProperties extends NotAnyTypeJsonSchema {}
2323
// NotAnyTypeSchema
2424

2525

26-
public static class HeadersMap extends FrozenMap<String, Object> {
27-
HeadersMap(FrozenMap<? extends String, ?> m) {
26+
public static class HeadersMap extends FrozenMap<String, String> {
27+
28+
HeadersMap(FrozenMap<String, String> m) {
29+
2830
super(m);
2931
}
30-
public static HeadersMap of(Map<String, Object> arg, SchemaConfiguration configuration) {
32+
public static final Set<String> requiredKeys = Set.of();
33+
public static final Set<String> optionalKeys = Set.of(
34+
"someHeader"
35+
);
36+
public static HeadersMap of(Map<String, String> arg, SchemaConfiguration configuration) {
37+
3138
return Headers1.validate(arg, configuration);
3239
}
40+
41+
public String someHeader() {
42+
43+
String key = "someHeader";
44+
throwIfKeyNotPresent(key);
45+
return get(key);
46+
}
3347
}
3448

3549
public class Headers1 extends JsonSchema {
@@ -40,10 +54,12 @@ public class Headers1 extends JsonSchema {
4054
))),
4155
new KeywordEntry("additionalProperties", new AdditionalPropertiesValidator(AdditionalProperties.class))
4256
));
43-
protected static HeadersMap getMapOutputInstance(FrozenMap<? extends String, ?> arg) {
57+
protected static HeadersMap getMapOutputInstance(FrozenMap<String, String> arg) {
58+
4459
return new HeadersMap(arg);
4560
}
46-
public static HeadersMap validate(Map<String, Object> arg, SchemaConfiguration configuration) {
61+
public static HeadersMap validate(Map<String, String> arg, SchemaConfiguration configuration) {
62+
4763
return JsonSchema.validate(Headers1.class, arg, configuration);
4864
}
4965
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/components/responses/successinlinecontentandheader/content/applicationjson/Schema.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,37 @@ public class Schema {
1818
public class AdditionalProperties extends Int32JsonSchema {}
1919

2020

21-
public static class SchemaMap extends FrozenMap<String, Object> {
22-
SchemaMap(FrozenMap<? extends String, ?> m) {
21+
public static class SchemaMap extends FrozenMap<String, Integer> {
22+
23+
SchemaMap(FrozenMap<String, Integer> m) {
24+
2325
super(m);
2426
}
25-
public static SchemaMap of(Map<String, Object> arg, SchemaConfiguration configuration) {
27+
public static final Set<String> requiredKeys = Set.of();
28+
public static final Set<String> optionalKeys = Set.of();
29+
public static SchemaMap of(Map<String, Integer> arg, SchemaConfiguration configuration) {
30+
2631
return Schema1.validate(arg, configuration);
2732
}
33+
34+
public int getAdditionalProperty(String name) {
35+
36+
throwIfKeyNotPresent(name);
37+
return get(name);
38+
}
2839
}
2940

3041
public class Schema1 extends JsonSchema {
3142
public static final LinkedHashMap<String, KeywordValidator> keywordToValidator = new LinkedHashMap<>(Map.ofEntries(
3243
new KeywordEntry("type", new TypeValidator(Set.of(FrozenMap.class))),
3344
new KeywordEntry("additionalProperties", new AdditionalPropertiesValidator(AdditionalProperties.class))
3445
));
35-
protected static SchemaMap getMapOutputInstance(FrozenMap<? extends String, ?> arg) {
46+
protected static SchemaMap getMapOutputInstance(FrozenMap<String, Integer> arg) {
47+
3648
return new SchemaMap(arg);
3749
}
38-
public static SchemaMap validate(Map<String, Object> arg, SchemaConfiguration configuration) {
50+
public static SchemaMap validate(Map<String, Integer> arg, SchemaConfiguration configuration) {
51+
3952
return JsonSchema.validate(Schema1.class, arg, configuration);
4053
}
4154
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/components/responses/successwithjsonapiresponse/Headers.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,44 @@ public class AdditionalProperties extends NotAnyTypeJsonSchema {}
2828

2929

3030
public static class HeadersMap extends FrozenMap<String, Object> {
31-
HeadersMap(FrozenMap<? extends String, ?> m) {
31+
32+
HeadersMap(FrozenMap<String, Object> m) {
33+
3234
super(m);
3335
}
36+
public static final Set<String> requiredKeys = Set.of(
37+
"int32",
38+
"ref-content-schema-header",
39+
"ref-schema-header",
40+
"stringHeader"
41+
);
42+
public static final Set<String> optionalKeys = Set.of(
43+
"numberHeader"
44+
);
3445
public static HeadersMap of(Map<String, Object> arg, SchemaConfiguration configuration) {
46+
3547
return Headers1.validate(arg, configuration);
3648
}
49+
50+
public int int32() {
51+
52+
return (int) get("int32");
53+
54+
}
55+
56+
public String stringHeader() {
57+
58+
return (String) get("stringHeader");
59+
60+
}
61+
62+
public String numberHeader() {
63+
64+
String key = "numberHeader";
65+
throwIfKeyNotPresent(key);
66+
return (String) get(key);
67+
68+
}
3769
}
3870

3971
public class Headers1 extends JsonSchema {
@@ -54,10 +86,12 @@ public class Headers1 extends JsonSchema {
5486
))),
5587
new KeywordEntry("additionalProperties", new AdditionalPropertiesValidator(AdditionalProperties.class))
5688
));
57-
protected static HeadersMap getMapOutputInstance(FrozenMap<? extends String, ?> arg) {
89+
protected static HeadersMap getMapOutputInstance(FrozenMap<String, Object> arg) {
90+
5891
return new HeadersMap(arg);
5992
}
6093
public static HeadersMap validate(Map<String, Object> arg, SchemaConfiguration configuration) {
94+
6195
return JsonSchema.validate(Headers1.class, arg, configuration);
6296
}
6397
}

samples/client/petstore/java/src/main/java/org/openapijsonschematools/components/schemas/AbstractStepMessage.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,41 @@ public class Discriminator extends StringJsonSchema {}
2121

2222

2323
public static class AbstractStepMessageMap extends FrozenMap<String, Object> {
24-
AbstractStepMessageMap(FrozenMap<? extends String, ?> m) {
24+
25+
AbstractStepMessageMap(FrozenMap<String, Object> m) {
26+
2527
super(m);
2628
}
29+
public static final Set<String> requiredKeys = Set.of(
30+
"description",
31+
"discriminator",
32+
"sequenceNumber"
33+
);
34+
public static final Set<String> optionalKeys = Set.of();
2735
public static AbstractStepMessageMap of(Map<String, Object> arg, SchemaConfiguration configuration) {
36+
2837
return AbstractStepMessage1.validate(arg, configuration);
2938
}
39+
40+
public Object description() {
41+
return get("description");
42+
}
43+
44+
public String discriminator() {
45+
46+
return (String) get("discriminator");
47+
48+
}
49+
50+
public Object sequenceNumber() {
51+
return get("sequenceNumber");
52+
}
53+
54+
public Object getAdditionalProperty(String name) {
55+
throwIfKeyKnown(name, requiredKeys, optionalKeys);
56+
throwIfKeyNotPresent(name);
57+
return get(name);
58+
}
3059
}
3160

3261
public class AbstractStepMessage1 extends JsonSchema {
@@ -49,10 +78,12 @@ public class AbstractStepMessage1 extends JsonSchema {
4978
"sequenceNumber"
5079
)))
5180
));
52-
protected static AbstractStepMessageMap getMapOutputInstance(FrozenMap<? extends String, ?> arg) {
81+
protected static AbstractStepMessageMap getMapOutputInstance(FrozenMap<String, Object> arg) {
82+
5383
return new AbstractStepMessageMap(arg);
5484
}
5585
public static AbstractStepMessageMap validate(Map<String, Object> arg, SchemaConfiguration configuration) {
86+
5687
return JsonSchema.validate(AbstractStepMessage1.class, arg, configuration);
5788
}
5889
}

0 commit comments

Comments
 (0)