Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sap.cloud.sdk.datamodel.openapi.generator;

import static com.sap.cloud.sdk.datamodel.openapi.generator.GeneratorCustomProperties.FIX_REDUNDANT_IS_BOOLEAN_PREFIX;
import static com.sap.cloud.sdk.datamodel.openapi.generator.GeneratorCustomProperties.USE_ONE_OF_CREATORS;

import java.nio.file.Path;
Expand All @@ -10,8 +11,10 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.openapitools.codegen.ClientOptInput;
import org.openapitools.codegen.CodegenConstants;
Expand Down Expand Up @@ -78,8 +81,20 @@ static ClientOptInput convertGenerationConfiguration(
private static JavaClientCodegen createCodegenConfig( @Nonnull final GenerationConfiguration config )
{
final var primitives = Set.of("String", "Integer", "Long", "Double", "Float", "Byte");
final var doubleIs = Pattern.compile("^isIs[A-Z]").asPredicate();
return new JavaClientCodegen()
{
@Override
@Nullable
public String toBooleanGetter( @Nullable final String name )
{
final String result = super.toBooleanGetter(name);
if( FIX_REDUNDANT_IS_BOOLEAN_PREFIX.isEnabled(config) && result != null && doubleIs.test(result) ) {
return "is" + result.substring(4);
}
return result;
}

// Custom processor to inject "x-return-nullable" extension
@Override
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ enum GeneratorCustomProperties
/**
* Use JsonCreator instead of sub-type deduction for oneOf and anyOf schemas.
*/
USE_ONE_OF_CREATORS("useOneOfCreators", "false");
USE_ONE_OF_CREATORS("useOneOfCreators", "false"),

/**
* Fix isIsBoolean() to isBoolean() for fields specified as `"isBoolean":{"type":"boolean"}`.
*/
FIX_REDUNDANT_IS_BOOLEAN_PREFIX("fixRedundantIsBooleanPrefix", "false");

private final String key;
private final String defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private enum TestCase
true,
true,
6,
Map.of("aiSdkConstructor", "true")),
Map.of("aiSdkConstructor", "true", "fixRedundantIsBooleanPrefix", "true")),
API_CLASS_VENDOR_EXTENSION_YAML(
"api-class-vendor-extension-yaml",
"sodastore.yaml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@
"brand": {
"type": "string"
},
"isAvailable": {
"type": "boolean"
},
"flavor": {
"type": "string"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class Soda
@JsonProperty("brand")
private String brand;

@JsonProperty("isAvailable")
private Boolean isAvailable;

@JsonProperty("flavor")
private String flavor;

Expand Down Expand Up @@ -147,6 +150,35 @@ public void setBrand( @Nonnull final String brand) {
this.brand = brand;
}

/**
* Set the isAvailable of this {@link Soda} instance and return the same instance.
*
* @param isAvailable The isAvailable of this {@link Soda}
* @return The same instance of this {@link Soda} class
*/
@Nonnull public Soda isAvailable( @Nullable final Boolean isAvailable) {
this.isAvailable = isAvailable;
return this;
}

/**
* Get isAvailable
* @return isAvailable The isAvailable of this {@link Soda} instance.
*/
@Nonnull
public Boolean isAvailable() {
return isAvailable;
}

/**
* Set the isAvailable of this {@link Soda} instance.
*
* @param isAvailable The isAvailable of this {@link Soda}
*/
public void setIsAvailable( @Nullable final Boolean isAvailable) {
this.isAvailable = isAvailable;
}

/**
* Set the flavor of this {@link Soda} instance and return the same instance.
*
Expand Down Expand Up @@ -244,6 +276,7 @@ public Map<String, Object> toMap()
if( id != null ) declaredFields.put("id", id);
if( name != null ) declaredFields.put("name", name);
if( brand != null ) declaredFields.put("brand", brand);
if( isAvailable != null ) declaredFields.put("isAvailable", isAvailable);
if( flavor != null ) declaredFields.put("flavor", flavor);
if( price != null ) declaredFields.put("price", price);
return declaredFields;
Expand Down Expand Up @@ -275,13 +308,14 @@ public boolean equals(@Nullable final java.lang.Object o) {
Objects.equals(this.id, soda.id) &&
Objects.equals(this.name, soda.name) &&
Objects.equals(this.brand, soda.brand) &&
Objects.equals(this.isAvailable, soda.isAvailable) &&
Objects.equals(this.flavor, soda.flavor) &&
Objects.equals(this.price, soda.price);
}

@Override
public int hashCode() {
return Objects.hash(id, name, brand, flavor, price, cloudSdkCustomFields);
return Objects.hash(id, name, brand, isAvailable, flavor, price, cloudSdkCustomFields);
}

@Override
Expand All @@ -291,6 +325,7 @@ public int hashCode() {
sb.append(" id: ").append(toIndentedString(id)).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" brand: ").append(toIndentedString(brand)).append("\n");
sb.append(" isAvailable: ").append(toIndentedString(isAvailable)).append("\n");
sb.append(" flavor: ").append(toIndentedString(flavor)).append("\n");
sb.append(" price: ").append(toIndentedString(price)).append("\n");
cloudSdkCustomFields.forEach((k,v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n"));
Expand Down
Loading