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

Support useBeanValidation-configOption #50

Merged
merged 35 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f0c5029
Support `useBeanValidation`-configOption in Record-fields
Chrimle Sep 11, 2024
eb4e260
Update pom.xml
Chrimle Sep 14, 2024
f679a2d
Update pojo.mustache
Chrimle Sep 14, 2024
dbe36f0
Merge branch 'main' into 48-support-the-configoption-property-usebean…
Chrimle Sep 14, 2024
abc8eec
Annotate fields with bean validation
Chrimle Sep 14, 2024
053619a
Update comment in `pojo.mustache`
Chrimle Sep 14, 2024
decdf82
Support `useBeanValidation`-configOption in Record-fields
Chrimle Sep 11, 2024
c1c0968
Annotate fields with bean validation
Chrimle Sep 14, 2024
03e661d
Update comment in `pojo.mustache`
Chrimle Sep 14, 2024
7c8897c
Merge branch '48-support-the-configoption-property-usebeanvalidation'…
Chrimle Sep 15, 2024
3a0d6ce
Merge branch 'main' into 48-support-the-configoption-property-usebean…
Chrimle Sep 19, 2024
dc8ce5f
Merge branch 'main' into 48-support-the-configoption-property-usebean…
Chrimle Sep 21, 2024
11bcbfc
Merge branch 'main' into 48-support-the-configoption-property-usebean…
Chrimle Sep 27, 2024
434018b
Add execution for `useBeanValidation`
Chrimle Sep 27, 2024
1092852
Merge branch 'main' into 48-support-the-configoption-property-usebean…
Chrimle Sep 27, 2024
7c00eb2
Format `PluginExecution.java`
Chrimle Sep 29, 2024
0ff95af
Annotate boolean-fields
Chrimle Sep 29, 2024
3ed1992
Add new schema for testing string constraints
Chrimle Sep 29, 2024
f194d4d
Merge branch 'main' into 48-support-the-configoption-property-usebean…
Chrimle Oct 3, 2024
9694bac
Support Nullable String-fields
Chrimle Oct 3, 2024
f0c5ed5
Merge branch 'main' into 48-support-the-configoption-property-usebean…
Chrimle Oct 9, 2024
a73a434
Execute baseline tests of `RecordWithAllConstraints`
Chrimle Oct 9, 2024
bfef41b
Add tests for `@NotNull`-annotations
Chrimle Oct 9, 2024
0b1211b
Add inner `Builder`-class to `GenerateField`
Chrimle Oct 9, 2024
ff0904a
Remove primitive-type check
Chrimle Oct 10, 2024
531b604
Annotate fields with `@Pattern`
Chrimle Oct 10, 2024
21a5a64
Add `@Size`-annotation based on `minLength`/`maxLength`
Chrimle Oct 10, 2024
25e2944
Annotate with `@Size` when `minItems`/`maxItems` is set
Chrimle Oct 10, 2024
032c7ce
Annotate `Integer`-fields with `@Min`/`@Max`
Chrimle Oct 10, 2024
85430e6
Annotate `Long`-fields with `@Min`/`@Max`
Chrimle Oct 10, 2024
2a3b276
Annotate `BigDecimal`-fields with `@DecimalMin`/`@DecimalMax`
Chrimle Oct 10, 2024
a890693
Remove prototype `.mustache`-template
Chrimle Oct 10, 2024
1558918
Update project version 1.7.6 -> 1.8.0
Chrimle Oct 10, 2024
aec4401
Update project version 1.7.6 -> 1.8.0
Chrimle Oct 10, 2024
dbbdc69
Reset minimum package line coverage ratio to 100%
Chrimle Oct 10, 2024
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
44 changes: 43 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.github.chrimle</groupId>
<artifactId>openapi-to-java-records-mustache-templates</artifactId>
<version>1.7.6</version>
<version>1.8.0</version>

<!-- Project Information -->
<name>OpenAPI to Java records :: Mustache Templates</name>
Expand Down Expand Up @@ -90,6 +90,7 @@
<serializableModel.default>false</serializableModel.default>
<generateBuilders.default>false</generateBuilders.default>
<useJakartaEe.default>false</useJakartaEe.default>
<useBeanValidation.default>false</useBeanValidation.default>

<!-- Plugin Executions -->
<!-- The Plugin Execution with Standard Configurations -->
Expand All @@ -106,6 +107,8 @@
<execution.generateBuilders>generateBuilders</execution.generateBuilders>
<!-- The Plugin Execution with useJakartaEe=true -->
<execution.useJakartaEe>useJakartaEe</execution.useJakartaEe>
<!-- The Plugin Execution with useBeanValidation=true -->
<execution.useBeanValidation>useBeanValidation</execution.useBeanValidation>
</properties>


Expand Down Expand Up @@ -151,6 +154,12 @@
<artifactId>jackson-annotations</artifactId>
<version>${jackson-annotations.version}</version>
</dependency>
<dependency>
<!-- Needed when useBeanValidation=true -->
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
</dependencies>


Expand Down Expand Up @@ -183,6 +192,7 @@
<serializableModel>${serializableModel.default}</serializableModel>
<generateBuilders>${generateBuilders.default}</generateBuilders>
<useJakartaEe>${useJakartaEe.default}</useJakartaEe>
<useBeanValidation>${useBeanValidation.default}</useBeanValidation>
</configOptions>
</configuration>
</execution>
Expand All @@ -208,6 +218,7 @@
<serializableModel>${serializableModel.default}</serializableModel>
<generateBuilders>${generateBuilders.default}</generateBuilders>
<useJakartaEe>${useJakartaEe.default}</useJakartaEe>
<useBeanValidation>${useBeanValidation.default}</useBeanValidation>
</configOptions>
</configuration>
</execution>
Expand Down Expand Up @@ -238,6 +249,7 @@
<serializableModel>${serializableModel.default}</serializableModel>
<generateBuilders>${generateBuilders.default}</generateBuilders>
<useJakartaEe>${useJakartaEe.default}</useJakartaEe>
<useBeanValidation>${useBeanValidation.default}</useBeanValidation>
</configOptions>
</configuration>
</execution>
Expand All @@ -264,6 +276,7 @@
<serializableModel>${serializableModel.default}</serializableModel>
<generateBuilders>${generateBuilders.default}</generateBuilders>
<useJakartaEe>${useJakartaEe.default}</useJakartaEe>
<useBeanValidation>${useBeanValidation.default}</useBeanValidation>
</configOptions>
</configuration>
</execution>
Expand All @@ -289,6 +302,7 @@
<serializableModel>true</serializableModel>
<generateBuilders>${generateBuilders.default}</generateBuilders>
<useJakartaEe>${useJakartaEe.default}</useJakartaEe>
<useBeanValidation>${useBeanValidation.default}</useBeanValidation>
</configOptions>
</configuration>
</execution>
Expand All @@ -314,6 +328,7 @@
<serializableModel>${serializableModel.default}</serializableModel>
<generateBuilders>true</generateBuilders>
<useJakartaEe>${useJakartaEe.default}</useJakartaEe>
<useBeanValidation>${useBeanValidation.default}</useBeanValidation>
</configOptions>
</configuration>
</execution>
Expand All @@ -339,6 +354,33 @@
<serializableModel>${serializableModel.default}</serializableModel>
<generateBuilders>${generateBuilders.default}</generateBuilders>
<useJakartaEe>true</useJakartaEe>
<useBeanValidation>${useBeanValidation.default}</useBeanValidation>
</configOptions>
</configuration>
</execution>
<execution>
<id>generate-${execution.useBeanValidation}</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<output>${output.default}</output>
<modelPackage>${modelPackage.default}.${execution.useBeanValidation}</modelPackage>
<generateModels>${generateModels.default}</generateModels>
<generateApis>${generateApis.default}</generateApis>
<generateSupportingFiles>${generateSupportingFiles.default}</generateSupportingFiles>
<generateModelTests>${generateModelTests.default}</generateModelTests>
<generateModelDocumentation>${generateModelDocumentation.default}</generateModelDocumentation>
<inputSpec>${inputSpec.default}</inputSpec>
<templateDirectory>${templateDirectory.default}</templateDirectory>
<generatorName>${generatorName.default}</generatorName>
<configOptions>
<sourceFolder>${sourceFolder.default}</sourceFolder>
<useEnumCaseInsensitive>${useEnumCaseInsensitive.default}</useEnumCaseInsensitive>
<serializableModel>${serializableModel.default}</serializableModel>
<generateBuilders>${generateBuilders.default}</generateBuilders>
<useJakartaEe>${useJakartaEe.default}</useJakartaEe>
<useBeanValidation>true</useBeanValidation>
</configOptions>
</configuration>
</execution>
Expand Down
83 changes: 83 additions & 0 deletions src/main/resources/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,86 @@ components:
- ENUM1
- ENUM2
- ENUM3
RecordWithAllConstraints:
type: object
description: Example of a Record which has fields with constraints
required:
- stringRequired
- stringRequiredNullable
- stringRequiredPattern
properties:
stringStandard:
type: string
stringDefault:
type: string
default: 'someDefaultValue'
stringNullable:
type: string
nullable: true
stringRequired:
type: string
stringRequiredNullable:
type: string
nullable: true
stringRequiredPattern:
type: string
pattern: '^\d{3}-\d{2}-\d{4}$'
stringMinLength:
type: string
minLength: 3
stringMaxLength:
type: string
maxLength: 7
stringMinAndMaxLength:
type: string
minLength: 3
maxLength: 7
arrayMinItems:
type: array
minItems: 1
items:
type: string
arrayMaxItems:
type: array
maxItems: 10
items:
type: string
arrayMinAndMaxItems:
type: array
minItems: 1
maxItems: 10
items:
type: string
intMinimum:
type: integer
minimum: 18
intMaximum:
type: integer
maximum: 100
intMinimumAndMaximum:
type: integer
minimum: 0
maximum: 100
longMinimum:
type: integer
format: int64
minimum: 18
longMaximum:
type: integer
format: int64
maximum: 100
longMinimumAndMaximum:
type: integer
format: int64
minimum: 0
maximum: 100
bigDecimalMinimum:
type: number
minimum: 0
bigDecimalMaximum:
type: number
maximum: 100
bigDecimalMinimumAndMaximum:
type: number
minimum: 0
maximum: 100
2 changes: 1 addition & 1 deletion src/main/resources/templates/generateBuilders.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{!
Source: openapi-to-java-records-mustache-templates
Version: 1.7.6
Version: 1.8.0
Enabled via configOptions.generateBuilders=true
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/javadoc.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{!
Source: openapi-to-java-records-mustache-templates
Version: 1.7.6
Version: 1.8.0
This template is optional, and does not override an existing template.
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/licenseInfo.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
* openapi-to-java-records-mustache-templates. For further information,
* questions, requesting features or reporting issues, please visit:
* https://github.com/Chrimle/openapi-to-java-records-mustache-templates.
* Generated with Version: 1.7.6
* Generated with Version: 1.8.0
*
*/
2 changes: 1 addition & 1 deletion src/main/resources/templates/modelEnum.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{!
Source: openapi-to-java-records-mustache-templates
Version: 1.7.6
Version: 1.8.0
Required mustache templates (generation will fail without them):
- `deprecation.mustache`
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/templates/pojo.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{!
Source: openapi-to-java-records-mustache-templates
Version: 1.7.6
Version: 1.8.0
Required imports:
- none
Expand All @@ -10,11 +10,12 @@
- `generateBuilders.mustache`
- `javadoc.mustache`
- `serializableModel.mustache`
- `useBeanValidation.mustache`
- `additionalModelTypeAnnotations.mustache` (Official)
}}{{>javadoc}}{{>deprecation}}{{>additionalModelTypeAnnotations}}{{!
}}public record {{classname}}(
{{#vars}}@{{javaxPackage}}.annotation.{{#isNullable}}Nullable{{/isNullable}}{{^isNullable}}Nonnull{{/isNullable}} {{{datatypeWithEnum}}} {{name}}{{^-last}},
{{#vars}}@{{javaxPackage}}.annotation.{{#isNullable}}Nullable{{/isNullable}}{{^isNullable}}Nonnull{{/isNullable}}{{>useBeanValidation}} {{{datatypeWithEnum}}} {{name}}{{^-last}},
{{/-last}}{{/vars}}{{^serializableModel}}){{/serializableModel}}{{#serializableModel}}
) implements Serializable{{/serializableModel}} {
{{>serializableModel}}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/serializableModel.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{!
Source: openapi-to-java-records-mustache-templates
Version: 1.7.6
Version: 1.8.0
Enabled via configOptions.serializableModel=true
Expand Down
79 changes: 79 additions & 0 deletions src/main/resources/templates/useBeanValidation.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{{!
Source: openapi-to-java-records-mustache-templates
Version: 1.8.0
Enabled via configOption.useBeanValidation=true
}}{{#useBeanValidation}}{{!
}}{{^required}}{{!
When not required, the field *may* be nullable according to openapi-generator-maven-plugin.
}}{{/required}}{{!
}}{{#required}}{{!
}}{{#isNullable}}{{!
Jakarta Bean Validation does not have constraint annotations for nullable values,
as values are nullable by default.
}}{{/isNullable}}{{!
}}{{^isNullable}}{{!
}} @NotNull{{!
}}{{/isNullable}}{{!
}}{{/required}}{{!
}}{{#pattern}}{{!
}} @Pattern(regexp = "{{{.}}}"){{!
}}{{/pattern}}{{!
}}{{#minLength}}{{!
}}{{#maxLength}}{{!
}} @Size(min = {{minLength}}, max = {{maxLength}}){{!
}}{{/maxLength}}{{!
}}{{/minLength}}{{!
}}{{#minLength}}{{!
}}{{^maxLength}}{{!
}} @Size(min = {{minLength}}){{!
}}{{/maxLength}}{{!
}}{{/minLength}}{{!
}}{{^minLength}}{{!
}}{{#maxLength}}{{!
}} @Size(max = {{maxLength}}){{!
}}{{/maxLength}}{{!
}}{{/minLength}}{{!
}}{{#minItems}}{{!
}}{{#maxItems}}{{!
}} @Size(min = {{minItems}}, max = {{maxItems}}){{!
}}{{/maxItems}}{{!
}}{{/minItems}}{{!
}}{{#minItems}}{{!
}}{{^maxItems}}{{!
}} @Size(min = {{minItems}}){{!
}}{{/maxItems}}{{!
}}{{/minItems}}{{!
}}{{^minItems}}{{!
}}{{#maxItems}}{{!
}} @Size(max = {{maxItems}}){{!
}}{{/maxItems}}{{!
}}{{/minItems}}{{!
}}{{#isInteger}}{{!
}}{{#minimum}}{{!
}} @Min({{.}}){{!
}}{{/minimum}}{{!
}}{{#maximum}}{{!
}} @Max({{.}}){{!
}}{{/maximum}}{{!
}}{{/isInteger}}{{!
}}{{#isLong}}{{!
}}{{#minimum}}{{!
}} @Min({{.}}L){{!
}}{{/minimum}}{{!
}}{{#maximum}}{{!
}} @Max({{.}}L){{!
}}{{/maximum}}{{!
}}{{/isLong}}{{!
}}{{^isInteger}}{{!
}}{{^isLong}}{{!
}}{{#minimum}}{{!
}} @DecimalMin({{#exclusiveMinimum}}value={{/exclusiveMinimum}}"{{minimum}}"{{#exclusiveMinimum}},inclusive=false{{/exclusiveMinimum}}){{!
}}{{/minimum}}{{!
}}{{#maximum}}{{!
}} @DecimalMax({{#exclusiveMaximum}}value={{/exclusiveMaximum}}"{{maximum}}"{{#exclusiveMaximum}},inclusive=false{{/exclusiveMaximum}}){{!
}}{{/maximum}}{{!
}}{{/isLong}}{{!
}}{{/isInteger}}{{!
}}{{/useBeanValidation}}
3 changes: 2 additions & 1 deletion src/test/java/com/chrimle/example/GeneratedClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public enum GeneratedClass {
EXAMPLE_RECORD_WITH_REQUIRED_FIELDS_OF_EACH_TYPE(
"ExampleRecordWithRequiredFieldsOfEachType", false, false),
EXAMPLE_RECORD_WITH_NULLABLE_FIELDS_OF_EACH_TYPE(
"ExampleRecordWithNullableFieldsOfEachType", false, false);
"ExampleRecordWithNullableFieldsOfEachType", false, false),
RECORD_WITH_ALL_CONSTRAINTS("RecordWithAllConstraints", false, false);

public static final String PACKAGE_NAME = "io.github.chrimle.example";
public final String simpleClassName;
Expand Down
Loading