@@ -155,7 +155,7 @@ std::string RequestLoader::getInputCppType(const RequestVariable& variable) cons
155155 }
156156 }
157157
158- inputType << getCppType (field .type );
158+ inputType << _schemaLoader. getCppType (variable .type -> name () );
159159
160160 for (size_t i = 0 ; i < templateCount; ++i)
161161 {
@@ -167,7 +167,63 @@ std::string RequestLoader::getInputCppType(const RequestVariable& variable) cons
167167
168168std::string RequestLoader::getOutputCppType (const ResponseField& field) const noexcept
169169{
170+ bool nonNull = true ;
171+ size_t templateCount = 0 ;
172+ std::ostringstream outputType;
173+
174+ for (auto modifier : field.modifiers )
175+ {
176+ if (!nonNull)
177+ {
178+ outputType << R"cpp( std::optional<)cpp" ;
179+ ++templateCount;
180+ }
181+
182+ switch (modifier)
183+ {
184+ case service::TypeModifier::None:
185+ nonNull = true ;
186+ break ;
187+
188+ case service::TypeModifier::Nullable:
189+ nonNull = false ;
190+ break ;
191+
192+ case service::TypeModifier::List:
193+ nonNull = true ;
194+ outputType << R"cpp( std::vector<)cpp" ;
195+ ++templateCount;
196+ break ;
197+ }
198+ }
199+
200+ switch (field.type ->kind ())
201+ {
202+ case introspection::TypeKind::OBJECT:
203+ case introspection::TypeKind::UNION:
204+ case introspection::TypeKind::INTERFACE:
205+ // Even if it's non-nullable, we still want to return a shared_ptr for complex types
206+ outputType << R"cpp( std::shared_ptr<)cpp" ;
207+ ++templateCount;
208+ break ;
209+
210+ default :
211+ if (!nonNull)
212+ {
213+ outputType << R"cpp( std::optional<)cpp" ;
214+ ++templateCount;
215+ }
216+ break ;
217+ }
218+
219+ outputType << _schemaLoader.getCppType (field.type ->name ());
220+
221+ for (size_t i = 0 ; i < templateCount; ++i)
222+ {
223+ outputType << R"cpp( >)cpp" ;
224+ }
170225
226+ return outputType.str ();
171227}
172228
173229void RequestLoader::buildSchema ()
0 commit comments