@@ -1160,7 +1160,7 @@ concept )cpp" << accessorName
11601160 << R"cpp( WithParams = requires (TImpl impl, service::FieldParams params)cpp" ;
11611161 for (const auto & argument : outputField.arguments )
11621162 {
1163- headerFile << R"cpp( , )cpp" << _loader.getInputCppType (argument) << R"cpp( )cpp"
1163+ headerFile << R"cpp( , )cpp" << _loader.getArgumentCppType (argument) << R"cpp( )cpp"
11641164 << argument.cppName << R"cpp( Arg)cpp" ;
11651165 }
11661166
@@ -1182,7 +1182,7 @@ concept )cpp" << accessorName
11821182 << R"cpp( = requires (TImpl impl)cpp" ;
11831183 for (const auto & argument : outputField.arguments )
11841184 {
1185- headerFile << R"cpp( , )cpp" << _loader.getInputCppType (argument) << R"cpp( )cpp"
1185+ headerFile << R"cpp( , )cpp" << _loader.getArgumentCppType (argument) << R"cpp( )cpp"
11861186 << argument.cppName << R"cpp( Arg)cpp" ;
11871187 }
11881188
@@ -1332,7 +1332,7 @@ void Generator::outputObjectDeclaration(std::ostream& headerFile, const ObjectTy
13321332 headerFile << R"cpp( , )cpp" ;
13331333 }
13341334
1335- headerFile << _loader.getInputCppType (argument) << R"cpp( && )cpp" << argument.cppName
1335+ headerFile << _loader.getArgumentCppType (argument) << R"cpp( && )cpp" << argument.cppName
13361336 << R"cpp( Arg)cpp" ;
13371337 firstArgument = false ;
13381338 }
@@ -1585,7 +1585,7 @@ std::string Generator::getFieldDeclaration(const OutputField& outputField) const
15851585 output << R"cpp( , )cpp" ;
15861586 }
15871587
1588- output << _loader.getInputCppType (argument) << R"cpp( && )cpp" << argument.cppName << " Arg" ;
1588+ output << _loader.getArgumentCppType (argument) << R"cpp( && )cpp" << argument.cppName << " Arg" ;
15891589 firstArgument = false ;
15901590 }
15911591
@@ -1778,7 +1778,8 @@ void Result<)cpp" << _loader.getSchemaNamespace()
17781778
17791779 for (const auto & inputField : inputType.fields )
17801780 {
1781- sourceFile << getArgumentDeclaration (inputField, " value" , " value" , " defaultValue" );
1781+ sourceFile
1782+ << getArgumentDeclaration (inputField, " value" , " value" , " defaultValue" , false );
17821783 }
17831784
17841785 if (!inputType.fields .empty ())
@@ -2841,7 +2842,8 @@ service::AwaitableResolver )cpp"
28412842 sourceFile << getArgumentDeclaration (argument,
28422843 " arg" ,
28432844 " params.arguments" ,
2844- " defaultArguments" );
2845+ " defaultArguments" ,
2846+ true );
28452847 }
28462848 }
28472849
@@ -3208,7 +3210,7 @@ std::string Generator::getArgumentDefaultValue(
32083210}
32093211
32103212std::string Generator::getArgumentDeclaration (const InputField& argument, const char * prefixToken,
3211- const char * argumentsToken, const char * defaultToken) const noexcept
3213+ const char * argumentsToken, const char * defaultToken, bool useOptional ) const noexcept
32123214{
32133215 std::ostringstream argumentDeclaration;
32143216 std::string argumentName (argument.cppName );
@@ -3217,15 +3219,15 @@ std::string Generator::getArgumentDeclaration(const InputField& argument, const
32173219 if (argument.defaultValue .type () == response::Type::Null)
32183220 {
32193221 argumentDeclaration << R"cpp( auto )cpp" << prefixToken << argumentName << R"cpp( = )cpp"
3220- << getArgumentAccessType (argument) << R"cpp( ::require)cpp"
3222+ << getArgumentAccessType (argument, useOptional ) << R"cpp( ::require)cpp"
32213223 << getTypeModifiers (argument.modifiers ) << R"cpp( (")cpp"
32223224 << argument.name << R"cpp( ", )cpp" << argumentsToken << R"cpp( );
32233225)cpp" ;
32243226 }
32253227 else
32263228 {
32273229 argumentDeclaration << R"cpp( auto pair)cpp" << argumentName << R"cpp( = )cpp"
3228- << getArgumentAccessType (argument) << R"cpp( ::find)cpp"
3230+ << getArgumentAccessType (argument, useOptional ) << R"cpp( ::find)cpp"
32293231 << getTypeModifiers (argument.modifiers ) << R"cpp( (")cpp"
32303232 << argument.name << R"cpp( ", )cpp" << argumentsToken << R"cpp( );
32313233 auto )cpp" << prefixToken
@@ -3247,7 +3249,7 @@ std::string Generator::getArgumentDeclaration(const InputField& argument, const
32473249 }
32483250
32493251 argumentDeclaration << R"cpp(
3250- : )cpp" << getArgumentAccessType (argument)
3252+ : )cpp" << getArgumentAccessType (argument, useOptional )
32513253 << R"cpp( ::require)cpp" << getTypeModifiers (argument.modifiers )
32523254 << R"cpp( (")cpp" << argument.name << R"cpp( ", )cpp" << defaultToken
32533255 << R"cpp( ));
@@ -3257,9 +3259,15 @@ std::string Generator::getArgumentDeclaration(const InputField& argument, const
32573259 return argumentDeclaration.str ();
32583260}
32593261
3260- std::string Generator::getArgumentAccessType (const InputField& argument) const noexcept
3262+ std::string Generator::getArgumentAccessType (
3263+ const InputField& argument, bool useOptional) const noexcept
32613264{
32623265 std::ostringstream argumentType;
3266+ const bool optionalInput = useOptional && argument.fieldType == InputFieldType::Input
3267+ && std::find (argument.modifiers .cbegin (),
3268+ argument.modifiers .cend (),
3269+ service::TypeModifier::Nullable)
3270+ != argument.modifiers .cend ();
32633271
32643272 argumentType << R"cpp( service::ModifiedArgument<)cpp" ;
32653273
@@ -3280,7 +3288,7 @@ std::string Generator::getArgumentAccessType(const InputField& argument) const n
32803288 break ;
32813289 }
32823290
3283- argumentType << R"cpp( >)cpp" ;
3291+ argumentType << (optionalInput ? R"cpp( , true >)cpp" : R"cpp( > )cpp" ) ;
32843292
32853293 return argumentType.str ();
32863294}
0 commit comments