2525import java .util .List ;
2626import java .util .Map ;
2727import java .util .Set ;
28+ import java .util .logging .Logger ;
2829
2930import org .apache .commons .lang3 .StringUtils ;
3031import org .openapitools .codegen .*;
3132import org .openapitools .codegen .utils .ModelUtils ;
33+ import org .slf4j .LoggerFactory ;
3234
3335import io .swagger .v3 .oas .models .media .*;
3436
3537public class CppRestbedServerCodegen extends AbstractCppCodegen {
3638
39+ private static final org .slf4j .Logger LOGGER = LoggerFactory .getLogger (CppRestbedServerCodegen .class );
40+
3741 public static final String DECLSPEC = "declspec" ;
3842 public static final String DEFAULT_INCLUDE = "defaultInclude" ;
3943
@@ -287,25 +291,63 @@ public String getTypeDeclaration(Schema p) {
287291 @ Override
288292 public String toDefaultValue (Schema p ) {
289293 if (ModelUtils .isStringSchema (p )) {
290- return "\" \" " ;
294+ if (p .getDefault () != null ) {
295+ return "\" " + p .getDefault ().toString () + "\" " ;
296+ } else {
297+ return "\" \" " ;
298+ }
291299 } else if (ModelUtils .isBooleanSchema (p )) {
292- return "false" ;
300+ if (p .getDefault () != null ) {
301+ return p .getDefault ().toString ();
302+ } else {
303+ return "false" ;
304+ }
293305 } else if (ModelUtils .isDateSchema (p )) {
294- return "\" \" " ;
306+ if (p .getDefault () != null ) {
307+ return "\" " + p .getDefault ().toString () + "\" " ;
308+ } else {
309+ return "\" \" " ;
310+ }
295311 } else if (ModelUtils .isDateTimeSchema (p )) {
296- return "\" \" " ;
312+ if (p .getDefault () != null ) {
313+ return "\" " + p .getDefault ().toString () + "\" " ;
314+ } else {
315+ return "\" \" " ;
316+ }
297317 } else if (ModelUtils .isNumberSchema (p )) {
298- if (ModelUtils .isFloatSchema (p )) {
299- return "0.0f" ;
318+ if (ModelUtils .isFloatSchema (p )) { // float
319+ if (p .getDefault () != null ) {
320+ return p .getDefault ().toString () + "f" ;
321+ } else {
322+ return "0.0f" ;
323+ }
324+ } else { // double
325+ if (p .getDefault () != null ) {
326+ return p .getDefault ().toString ();
327+ } else {
328+ return "0.0" ;
329+ }
300330 }
301- return "0.0" ;
302331 } else if (ModelUtils .isIntegerSchema (p )) {
303- if (ModelUtils .isLongSchema (p )) {
304- return "0L" ;
332+ if (ModelUtils .isLongSchema (p )) { // long
333+ if (p .getDefault () != null ) {
334+ return p .getDefault ().toString () + "L" ;
335+ } else {
336+ return "0L" ;
337+ }
338+ } else { // integer
339+ if (p .getDefault () != null ) {
340+ return p .getDefault ().toString ();
341+ } else {
342+ return "0" ;
343+ }
305344 }
306- return "0" ;
307345 } else if (ModelUtils .isByteArraySchema (p )) {
308- return "\" \" " ;
346+ if (p .getDefault () != null ) {
347+ return "\" " + p .getDefault ().toString () + "\" " ;
348+ } else {
349+ return "\" \" " ;
350+ }
309351 } else if (ModelUtils .isMapSchema (p )) {
310352 String inner = getSchemaType (ModelUtils .getAdditionalProperties (p ));
311353 return "std::map<std::string, " + inner + ">()" ;
@@ -319,6 +361,7 @@ public String toDefaultValue(Schema p) {
319361 } else if (!StringUtils .isEmpty (p .get$ref ())) {
320362 return "new " + toModelName (ModelUtils .getSimpleRef (p .get$ref ())) + "()" ;
321363 }
364+
322365 return "nullptr" ;
323366 }
324367
0 commit comments