forked from loafle/openapi-generator-original
[cpp-ue4] Handled nullable by setting the required tag, effectively making nullables optionals (even if they may be required in the spec). This is because there is no such concept as a value being nullable in C++, and this generator deals with values, not pointers. (#18168)
Co-authored-by: Samuel Kahn <samuel@darewise.com>
This commit is contained in:
parent
93b76dde37
commit
783119b687
@ -20,6 +20,10 @@ import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenParameter;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.CodegenResponse;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.meta.GeneratorMetadata;
|
||||
import org.openapitools.codegen.meta.Stability;
|
||||
@ -246,6 +250,34 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
||||
this.optionalProjectFileFlag = flag;
|
||||
}
|
||||
|
||||
// override to post-process any model properties
|
||||
@Override
|
||||
@SuppressWarnings("unused")
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
super.postProcessModelProperty(model, property);
|
||||
// Nullable will be handled as optional
|
||||
property.required = !property.notRequiredOrIsNullable();
|
||||
}
|
||||
|
||||
// override to post-process any response
|
||||
@Override
|
||||
@SuppressWarnings("unused")
|
||||
public void postProcessResponseWithProperty(CodegenResponse response, CodegenProperty property) {
|
||||
super.postProcessResponseWithProperty(response, property);
|
||||
// Nullable will be handled as optional
|
||||
property.required = !property.notRequiredOrIsNullable();
|
||||
}
|
||||
|
||||
// override to post-process any parameters
|
||||
@Override
|
||||
@SuppressWarnings("unused")
|
||||
public void postProcessParameter(CodegenParameter parameter) {
|
||||
super.postProcessParameter(parameter);
|
||||
// Nullable will be handled as optional
|
||||
parameter.required = !parameter.notRequiredOrIsNullable();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
|
@ -448,10 +448,11 @@ inline bool TryGetJsonValue(const TSharedPtr<FJsonObject>& JsonObject, const FSt
|
||||
template<typename T>
|
||||
inline bool TryGetJsonValue(const TSharedPtr<FJsonObject>& JsonObject, const FString& Key, TOptional<T>& OptionalValue)
|
||||
{
|
||||
if(JsonObject->HasField(Key))
|
||||
const TSharedPtr<FJsonValue> JsonValue = JsonObject->TryGetField(Key);
|
||||
if (JsonValue.IsValid() && !JsonValue->IsNull())
|
||||
{
|
||||
T Value;
|
||||
if (TryGetJsonValue(JsonObject, Key, Value))
|
||||
if (TryGetJsonValue(JsonValue, Value))
|
||||
{
|
||||
OptionalValue = Value;
|
||||
return true;
|
||||
@ -459,7 +460,9 @@ inline bool TryGetJsonValue(const TSharedPtr<FJsonObject>& JsonObject, const FSt
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return true; // Absence of optional value is not a parsing error
|
||||
// Absence of optional value is not a parsing error.
|
||||
// Nullable is handled like optional.
|
||||
return true;
|
||||
}
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user