forked from loafle/openapi-generator-original
add nullable support to oneof, anyof (#6392)
This commit is contained in:
@@ -888,12 +888,25 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
|
||||
// add x-data-type to store powershell type
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
Map<String, Object> _model = (Map<String, Object>) _mo;
|
||||
CodegenModel model = (CodegenModel) _model.get("model");
|
||||
|
||||
for (CodegenProperty cp : cm.allVars) {
|
||||
for (CodegenProperty cp : model.allVars) {
|
||||
cp.vendorExtensions.put("x-powershell-data-type", getPSDataType(cp));
|
||||
}
|
||||
|
||||
// if oneOf contains "null" type
|
||||
if (model.oneOf != null && !model.oneOf.isEmpty() && model.oneOf.contains("ModelNull")) {
|
||||
model.isNullable = true;
|
||||
model.oneOf.remove("ModelNull");
|
||||
}
|
||||
|
||||
// if anyOf contains "null" type
|
||||
if (model.anyOf != null && !model.anyOf.isEmpty() && model.anyOf.contains("ModelNull")) {
|
||||
model.isNullable = true;
|
||||
model.anyOf.remove("ModelNull");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return objs;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,17 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
|
||||
$matchType = $null
|
||||
$matchInstance = $null
|
||||
|
||||
{{#isNullable}}
|
||||
# nullalble check
|
||||
if ([string]::IsNullOrEmpty($Json) -or $Json -eq "{}") {
|
||||
return [PSCustomObject]@{
|
||||
"ActualType" = $null
|
||||
"ActualInstance" = $null
|
||||
"AnyOfSchemas" = @({{#anyOf}}"{{{.}}}"{{^-last}}, {{/-last}}{{/anyOf}})
|
||||
}
|
||||
}
|
||||
|
||||
{{/isNullable}}
|
||||
{{#anyOf}}
|
||||
if ($match -ne 0) { # no match yet
|
||||
# try to match {{{.}}} defined in the anyOf schemas
|
||||
|
||||
@@ -27,6 +27,17 @@ function ConvertFrom-{{{apiNamePrefix}}}JsonTo{{{classname}}} {
|
||||
$matchType = $null
|
||||
$matchInstance = $null
|
||||
|
||||
{{#isNullable}}
|
||||
# nullalble check
|
||||
if ([string]::IsNullOrEmpty($Json) -or $Json -eq "{}") {
|
||||
return [PSCustomObject]@{
|
||||
"ActualType" = $null
|
||||
"ActualInstance" = $null
|
||||
"OneOfSchemas" = @({{#oneOf}}"{{{.}}}"{{^-last}}, {{/-last}}{{/oneOf}})
|
||||
}
|
||||
}
|
||||
|
||||
{{/isNullable}}
|
||||
{{#oneOf}}
|
||||
# try to match {{{.}}} defined in the oneOf schemas
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user