-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #293 from muehmar/160-support-custom-types-with-va…
…lidation 160 support custom types with validation
- Loading branch information
Showing
333 changed files
with
26,678 additions
and
5,070 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
## Warnings | ||
The plugin emit warnings for certain scenarios. These warnings are printed to the console of | ||
the gradle build. These warnings can also be turned off completely if necessary via configuration of | ||
the plugin. | ||
|
||
The plugin emit warnings for certain scenarios. These warnings are printed to the console of the gradle build. These | ||
warnings can also be turned off completely if necessary via configuration of the plugin. | ||
|
||
The plugin can also be configured to let the generation fail in case warnings occurred (similar to the -Werror flag for | ||
the Java compiler). This can be done globally for every warning or selective for any warning type, see the | ||
[Configuration](#configuration) section. | ||
|
||
The plugin generates the following warnings: | ||
|
||
| Type | Description | | ||
|------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| UNSUPPORTED_VALIDATION | Validation of custom types is currently not supported. This means, if a property has some constraints but is mapped to a custom type, no validation will be performed for this property. This may be supported in a future version of the plugin, see issue [#160](https://github.com/muehmar/gradle-openapi-schema/issues/160). | | ||
| Type | Description | | ||
|----------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| UNSUPPORTED_VALIDATION | Mappings can be defined without conversions. For custom types without conversion, no validation annotations will be generated which will produce this warning. | | ||
| MISSING_MAPPING_CONVERSION | Mappings without conversion may lead to serialisation or validations issues (see [asd](010_configuration.md#conversions-for-mappings). This warning is generated for each mapping without conversion. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
plugin/src/main/java/com/github/muehmar/gradle/openapi/dsl/Conversion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.github.muehmar.gradle.openapi.dsl; | ||
|
||
import com.github.muehmar.gradle.openapi.exception.OpenApiGeneratorException; | ||
import com.github.muehmar.gradle.openapi.generator.settings.TypeConversion; | ||
import java.io.Serializable; | ||
import java.util.Optional; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class Conversion implements Serializable { | ||
String fromCustomType; | ||
String toCustomType; | ||
|
||
public Optional<TypeConversion> toTypeConversion() { | ||
if (fromCustomType == null || toCustomType == null) { | ||
return Optional.empty(); | ||
} | ||
return Optional.of(new TypeConversion(fromCustomType, toCustomType)); | ||
} | ||
|
||
void assertValidConfig(String mappingIdentifier) { | ||
if (fromCustomType == null ^ toCustomType == null) { | ||
final String missingConfig = | ||
fromCustomType == null ? "fromCustomType is missing" : "toCustomType is missing"; | ||
throw new OpenApiGeneratorException( | ||
"Invalid configuration for conversion for %s: Both " | ||
+ "fromCustomType and toCustomType must be set but %s.", | ||
mappingIdentifier, missingConfig); | ||
} | ||
} | ||
} |
23 changes: 12 additions & 11 deletions
23
plugin/src/main/java/com/github/muehmar/gradle/openapi/dsl/FormatTypeMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
package com.github.muehmar.gradle.openapi.dsl; | ||
|
||
import java.io.Serializable; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
import lombok.Data; | ||
|
||
@EqualsAndHashCode | ||
@ToString | ||
@Data | ||
public class FormatTypeMapping implements Serializable { | ||
private String formatType; | ||
private String classType; | ||
private final Conversion conversion; | ||
|
||
public void setFormatType(String formatType) { | ||
this.formatType = formatType; | ||
} | ||
|
||
public void setClassType(String classType) { | ||
this.classType = classType; | ||
public FormatTypeMapping() { | ||
this.conversion = new Conversion(); | ||
} | ||
|
||
public com.github.muehmar.gradle.openapi.generator.settings.FormatTypeMapping | ||
toSettingsFormatTypeMapping() { | ||
return new com.github.muehmar.gradle.openapi.generator.settings.FormatTypeMapping( | ||
formatType, classType); | ||
formatType, classType, conversion.toTypeConversion()); | ||
} | ||
|
||
void assertCompleteTypeConversion() { | ||
conversion.assertValidConfig( | ||
String.format( | ||
"formatTypeMapping with formatType '%s' and classType '%s'", formatType, classType)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.