Skip to content

Commit 20ed1ee

Browse files
authored
Fixes to cpp-oatpp-server generator. (#21595)
1 parent 90001d4 commit 20ed1ee

File tree

7 files changed

+78
-72
lines changed

7 files changed

+78
-72
lines changed

modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-header.mustache

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
{{{defaultInclude}}}
1212
{{#imports}}{{{this}}}
1313
{{/imports}}
14+
{{^isEnum}}
1415
#include "oatpp/core/macro/codegen.hpp"
16+
{{/isEnum}}
1517
#include "oatpp/core/Types.hpp"
1618

1719
namespace {{modelNamespace}}
1820
{
1921
22+
{{^isEnum}}
2023
/* Begin DTO code-generation */
2124
#include OATPP_CODEGEN_BEGIN(DTO)
2225

@@ -28,19 +31,28 @@ class {{classname}} : public oatpp::DTO {
2831
DTO_INIT({{classname}}, DTO /* Extends */)
2932

3033
{{#vars}}
31-
DTO_FIELD({{#isModel}}oatpp::Object<{{{dataType}}}>{{/isModel}}{{^isModel}}{{{dataType}}}{{/isModel}}, {{name}});
34+
DTO_FIELD({{#isModel}}oatpp::Object<{{{dataType}}}>{{/isModel}}{{^isModel}}{{{dataType}}}{{/isModel}}, {{baseName}});
3235
{{^required}}
33-
DTO_FIELD(oatpp::Boolean, {{name}}IsSet);{{/required}}
36+
DTO_FIELD(oatpp::Boolean, {{baseName}}IsSet);{{/required}}
3437
{{/vars}}
3538

36-
{{#isEnum}} // TODO:
37-
{{classname}}::e{{classname}} m_value = {{classname}}::e{{classname}}::INVALID_VALUE_OPENAPI_GENERATED;{{/isEnum}}
38-
{{#vendorExtensions.x-is-string-enum-container}} // TODO:
39-
{{#anyOf}}{{#-first}}{{{this}}} m_value;{{/-first}}{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}
4039
};
4140

4241
/* End DTO code-generation */
4342
#include OATPP_CODEGEN_END(DTO)
43+
{{/isEnum}}
44+
45+
{{#isEnum}}
46+
typedef {{dataType}} {{classname}};
47+
class {{classname}}Values {
48+
public:
49+
{{#allowableValues}}
50+
{{#enumVars}}
51+
static {{classname}} {{value}}(void) { return "{{value}}"; }
52+
{{/enumVars}}
53+
{{/allowableValues}}
54+
};
55+
{{/isEnum}}
4456

4557
} // namespace {{modelNamespace}}
4658

samples/server/petstore/cpp-oatpp/model/ApiResponse.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,19 @@ class ApiResponse : public oatpp::DTO {
3535

3636
DTO_INIT(ApiResponse, DTO /* Extends */)
3737

38-
DTO_FIELD(oatpp::Int32, Code);
39-
DTO_FIELD(oatpp::Boolean, CodeIsSet);
40-
DTO_FIELD(oatpp::String, Type);
41-
DTO_FIELD(oatpp::Boolean, TypeIsSet);
42-
DTO_FIELD(oatpp::String, Message);
43-
DTO_FIELD(oatpp::Boolean, MessageIsSet);
44-
45-
46-
38+
DTO_FIELD(oatpp::Int32, code);
39+
DTO_FIELD(oatpp::Boolean, codeIsSet);
40+
DTO_FIELD(oatpp::String, type);
41+
DTO_FIELD(oatpp::Boolean, typeIsSet);
42+
DTO_FIELD(oatpp::String, message);
43+
DTO_FIELD(oatpp::Boolean, messageIsSet);
44+
4745
};
4846

4947
/* End DTO code-generation */
5048
#include OATPP_CODEGEN_END(DTO)
5149

50+
5251
} // namespace org::openapitools::server::model
5352

5453
#endif /* ApiResponse_H_ */

samples/server/petstore/cpp-oatpp/model/Category.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,17 @@ class Category : public oatpp::DTO {
3535

3636
DTO_INIT(Category, DTO /* Extends */)
3737

38-
DTO_FIELD(oatpp::Int64, Id);
39-
DTO_FIELD(oatpp::Boolean, IdIsSet);
40-
DTO_FIELD(oatpp::String, Name);
41-
DTO_FIELD(oatpp::Boolean, NameIsSet);
38+
DTO_FIELD(oatpp::Int64, id);
39+
DTO_FIELD(oatpp::Boolean, idIsSet);
40+
DTO_FIELD(oatpp::String, name);
41+
DTO_FIELD(oatpp::Boolean, nameIsSet);
4242

43-
44-
4543
};
4644

4745
/* End DTO code-generation */
4846
#include OATPP_CODEGEN_END(DTO)
4947

48+
5049
} // namespace org::openapitools::server::model
5150

5251
#endif /* Category_H_ */

samples/server/petstore/cpp-oatpp/model/Order.hpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,25 @@ class Order : public oatpp::DTO {
3535

3636
DTO_INIT(Order, DTO /* Extends */)
3737

38-
DTO_FIELD(oatpp::Int64, Id);
39-
DTO_FIELD(oatpp::Boolean, IdIsSet);
40-
DTO_FIELD(oatpp::Int64, PetId);
41-
DTO_FIELD(oatpp::Boolean, PetIdIsSet);
42-
DTO_FIELD(oatpp::Int32, Quantity);
43-
DTO_FIELD(oatpp::Boolean, QuantityIsSet);
44-
DTO_FIELD(oatpp::String, ShipDate);
45-
DTO_FIELD(oatpp::Boolean, ShipDateIsSet);
46-
DTO_FIELD(oatpp::String, Status);
47-
DTO_FIELD(oatpp::Boolean, StatusIsSet);
48-
DTO_FIELD(oatpp::Boolean, Complete);
49-
DTO_FIELD(oatpp::Boolean, CompleteIsSet);
50-
51-
52-
38+
DTO_FIELD(oatpp::Int64, id);
39+
DTO_FIELD(oatpp::Boolean, idIsSet);
40+
DTO_FIELD(oatpp::Int64, petId);
41+
DTO_FIELD(oatpp::Boolean, petIdIsSet);
42+
DTO_FIELD(oatpp::Int32, quantity);
43+
DTO_FIELD(oatpp::Boolean, quantityIsSet);
44+
DTO_FIELD(oatpp::String, shipDate);
45+
DTO_FIELD(oatpp::Boolean, shipDateIsSet);
46+
DTO_FIELD(oatpp::String, status);
47+
DTO_FIELD(oatpp::Boolean, statusIsSet);
48+
DTO_FIELD(oatpp::Boolean, complete);
49+
DTO_FIELD(oatpp::Boolean, completeIsSet);
50+
5351
};
5452

5553
/* End DTO code-generation */
5654
#include OATPP_CODEGEN_END(DTO)
5755

56+
5857
} // namespace org::openapitools::server::model
5958

6059
#endif /* Order_H_ */

samples/server/petstore/cpp-oatpp/model/Pet.hpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,25 @@ class Pet : public oatpp::DTO {
3737

3838
DTO_INIT(Pet, DTO /* Extends */)
3939

40-
DTO_FIELD(oatpp::Int64, Id);
41-
DTO_FIELD(oatpp::Boolean, IdIsSet);
42-
DTO_FIELD(oatpp::Object<org::openapitools::server::model::Category>, Category);
43-
DTO_FIELD(oatpp::Boolean, CategoryIsSet);
44-
DTO_FIELD(oatpp::String, Name);
40+
DTO_FIELD(oatpp::Int64, id);
41+
DTO_FIELD(oatpp::Boolean, idIsSet);
42+
DTO_FIELD(oatpp::Object<org::openapitools::server::model::Category>, category);
43+
DTO_FIELD(oatpp::Boolean, categoryIsSet);
44+
DTO_FIELD(oatpp::String, name);
4545

46-
DTO_FIELD(oatpp::Vector<oatpp::String>, PhotoUrls);
46+
DTO_FIELD(oatpp::Vector<oatpp::String>, photoUrls);
4747

48-
DTO_FIELD(oatpp::Vector<oatpp::Object<org::openapitools::server::model::Tag>>, Tags);
49-
DTO_FIELD(oatpp::Boolean, TagsIsSet);
50-
DTO_FIELD(oatpp::String, Status);
51-
DTO_FIELD(oatpp::Boolean, StatusIsSet);
48+
DTO_FIELD(oatpp::Vector<oatpp::Object<org::openapitools::server::model::Tag>>, tags);
49+
DTO_FIELD(oatpp::Boolean, tagsIsSet);
50+
DTO_FIELD(oatpp::String, status);
51+
DTO_FIELD(oatpp::Boolean, statusIsSet);
5252

53-
54-
5553
};
5654

5755
/* End DTO code-generation */
5856
#include OATPP_CODEGEN_END(DTO)
5957

58+
6059
} // namespace org::openapitools::server::model
6160

6261
#endif /* Pet_H_ */

samples/server/petstore/cpp-oatpp/model/Tag.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,17 @@ class Tag : public oatpp::DTO {
3535

3636
DTO_INIT(Tag, DTO /* Extends */)
3737

38-
DTO_FIELD(oatpp::Int64, Id);
39-
DTO_FIELD(oatpp::Boolean, IdIsSet);
40-
DTO_FIELD(oatpp::String, Name);
41-
DTO_FIELD(oatpp::Boolean, NameIsSet);
38+
DTO_FIELD(oatpp::Int64, id);
39+
DTO_FIELD(oatpp::Boolean, idIsSet);
40+
DTO_FIELD(oatpp::String, name);
41+
DTO_FIELD(oatpp::Boolean, nameIsSet);
4242

43-
44-
4543
};
4644

4745
/* End DTO code-generation */
4846
#include OATPP_CODEGEN_END(DTO)
4947

48+
5049
} // namespace org::openapitools::server::model
5150

5251
#endif /* Tag_H_ */

samples/server/petstore/cpp-oatpp/model/User.hpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,29 @@ class User : public oatpp::DTO {
3535

3636
DTO_INIT(User, DTO /* Extends */)
3737

38-
DTO_FIELD(oatpp::Int64, Id);
39-
DTO_FIELD(oatpp::Boolean, IdIsSet);
40-
DTO_FIELD(oatpp::String, Username);
41-
DTO_FIELD(oatpp::Boolean, UsernameIsSet);
42-
DTO_FIELD(oatpp::String, FirstName);
43-
DTO_FIELD(oatpp::Boolean, FirstNameIsSet);
44-
DTO_FIELD(oatpp::String, LastName);
45-
DTO_FIELD(oatpp::Boolean, LastNameIsSet);
46-
DTO_FIELD(oatpp::String, Email);
47-
DTO_FIELD(oatpp::Boolean, EmailIsSet);
48-
DTO_FIELD(oatpp::String, Password);
49-
DTO_FIELD(oatpp::Boolean, PasswordIsSet);
50-
DTO_FIELD(oatpp::String, Phone);
51-
DTO_FIELD(oatpp::Boolean, PhoneIsSet);
52-
DTO_FIELD(oatpp::Int32, UserStatus);
53-
DTO_FIELD(oatpp::Boolean, UserStatusIsSet);
38+
DTO_FIELD(oatpp::Int64, id);
39+
DTO_FIELD(oatpp::Boolean, idIsSet);
40+
DTO_FIELD(oatpp::String, username);
41+
DTO_FIELD(oatpp::Boolean, usernameIsSet);
42+
DTO_FIELD(oatpp::String, firstName);
43+
DTO_FIELD(oatpp::Boolean, firstNameIsSet);
44+
DTO_FIELD(oatpp::String, lastName);
45+
DTO_FIELD(oatpp::Boolean, lastNameIsSet);
46+
DTO_FIELD(oatpp::String, email);
47+
DTO_FIELD(oatpp::Boolean, emailIsSet);
48+
DTO_FIELD(oatpp::String, password);
49+
DTO_FIELD(oatpp::Boolean, passwordIsSet);
50+
DTO_FIELD(oatpp::String, phone);
51+
DTO_FIELD(oatpp::Boolean, phoneIsSet);
52+
DTO_FIELD(oatpp::Int32, userStatus);
53+
DTO_FIELD(oatpp::Boolean, userStatusIsSet);
5454

55-
56-
5755
};
5856

5957
/* End DTO code-generation */
6058
#include OATPP_CODEGEN_END(DTO)
6159

60+
6261
} // namespace org::openapitools::server::model
6362

6463
#endif /* User_H_ */

0 commit comments

Comments
 (0)