Skip to content

Commit f7193a4

Browse files
committed
Update Petstore sample
1 parent ce01835 commit f7193a4

File tree

12 files changed

+439
-28
lines changed

12 files changed

+439
-28
lines changed

samples/client/petstore/cpprest/api/UserApi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class UserApi
8686
/// <remarks>
8787
///
8888
/// </remarks>
89-
/// <param name="username">The name that needs to be fetched. Use user1 for testing. </param>
89+
/// <param name="username">The name that needs to be fetched. Use user1 for testing.</param>
9090
pplx::task<std::shared_ptr<User>> getUserByName(
9191
utility::string_t username
9292
);
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* Swagger Petstore
3+
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
4+
*
5+
* OpenAPI spec version: 1.0.0
6+
* Contact: [email protected]
7+
*
8+
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
9+
* https://github.com/swagger-api/swagger-codegen.git
10+
* Do not edit the class manually.
11+
*/
12+
13+
14+
15+
#include "Amount.h"
16+
17+
namespace io {
18+
namespace swagger {
19+
namespace client {
20+
namespace model {
21+
22+
Amount::Amount()
23+
{
24+
m_Value = 0.0;
25+
}
26+
27+
Amount::~Amount()
28+
{
29+
}
30+
31+
void Amount::validate()
32+
{
33+
// TODO: implement validation
34+
}
35+
36+
web::json::value Amount::toJson() const
37+
{
38+
web::json::value val = web::json::value::object();
39+
40+
val[utility::conversions::to_string_t("value")] = ModelBase::toJson(m_Value);
41+
val[utility::conversions::to_string_t("currency")] = ModelBase::toJson(m_Currency);
42+
43+
return val;
44+
}
45+
46+
void Amount::fromJson(web::json::value& val)
47+
{
48+
setValue(ModelBase::doubleFromJson(val[utility::conversions::to_string_t("value")]));
49+
std::shared_ptr<Currency> newCurrency(new Currency());
50+
newCurrency->fromJson(val[utility::conversions::to_string_t("currency")]);
51+
setCurrency( newCurrency );
52+
}
53+
54+
void Amount::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
55+
{
56+
utility::string_t namePrefix = prefix;
57+
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
58+
{
59+
namePrefix += utility::conversions::to_string_t(".");
60+
}
61+
62+
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t("value"), m_Value));
63+
m_Currency->toMultipart(multipart, utility::conversions::to_string_t("currency."));
64+
}
65+
66+
void Amount::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
67+
{
68+
utility::string_t namePrefix = prefix;
69+
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
70+
{
71+
namePrefix += utility::conversions::to_string_t(".");
72+
}
73+
74+
setValue(ModelBase::doubleFromHttpContent(multipart->getContent(utility::conversions::to_string_t("value"))));
75+
std::shared_ptr<Currency> newCurrency(new Currency());
76+
newCurrency->fromMultiPart(multipart, utility::conversions::to_string_t("currency."));
77+
setCurrency( newCurrency );
78+
}
79+
80+
double Amount::getValue() const
81+
{
82+
return m_Value;
83+
}
84+
85+
86+
void Amount::setValue(double value)
87+
{
88+
m_Value = value;
89+
90+
}
91+
std::shared_ptr<Currency> Amount::getCurrency() const
92+
{
93+
return m_Currency;
94+
}
95+
96+
97+
void Amount::setCurrency(std::shared_ptr<Currency> value)
98+
{
99+
m_Currency = value;
100+
101+
}
102+
}
103+
}
104+
}
105+
}
106+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Swagger Petstore
3+
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
4+
*
5+
* OpenAPI spec version: 1.0.0
6+
* Contact: [email protected]
7+
*
8+
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
9+
* https://github.com/swagger-api/swagger-codegen.git
10+
* Do not edit the class manually.
11+
*/
12+
13+
/*
14+
* Amount.h
15+
*
16+
* some description
17+
*/
18+
19+
#ifndef IO_SWAGGER_CLIENT_MODEL_Amount_H_
20+
#define IO_SWAGGER_CLIENT_MODEL_Amount_H_
21+
22+
23+
#include "../ModelBase.h"
24+
25+
#include "Currency.h"
26+
27+
namespace io {
28+
namespace swagger {
29+
namespace client {
30+
namespace model {
31+
32+
/// <summary>
33+
/// some description
34+
/// </summary>
35+
class Amount
36+
: public ModelBase
37+
{
38+
public:
39+
Amount();
40+
virtual ~Amount();
41+
42+
/////////////////////////////////////////////
43+
/// ModelBase overrides
44+
45+
void validate() override;
46+
47+
web::json::value toJson() const override;
48+
void fromJson(web::json::value& json) override;
49+
50+
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
51+
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
52+
53+
/////////////////////////////////////////////
54+
/// Amount members
55+
56+
/// <summary>
57+
/// some description
58+
/// </summary>
59+
double getValue() const;
60+
void setValue(double value);
61+
/// <summary>
62+
///
63+
/// </summary>
64+
std::shared_ptr<Currency> getCurrency() const;
65+
void setCurrency(std::shared_ptr<Currency> value);
66+
67+
protected:
68+
double m_Value;
69+
std::shared_ptr<Currency> m_Currency;
70+
};
71+
72+
}
73+
}
74+
}
75+
}
76+
77+
#endif /* IO_SWAGGER_CLIENT_MODEL_Amount_H_ */

samples/client/petstore/cpprest/model/ApiResponse.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,27 @@ void ApiResponse::fromJson(web::json::value& val)
6262
{
6363
if(val.has_field(utility::conversions::to_string_t("code")))
6464
{
65-
setCode(ModelBase::int32_tFromJson(val[utility::conversions::to_string_t("code")]));
65+
web::json::value& fieldValue = val[utility::conversions::to_string_t("code")];
66+
if(!fieldValue.is_null())
67+
{
68+
setCode(ModelBase::int32_tFromJson(fieldValue));
69+
}
6670
}
6771
if(val.has_field(utility::conversions::to_string_t("type")))
6872
{
69-
setType(ModelBase::stringFromJson(val[utility::conversions::to_string_t("type")]));
73+
web::json::value& fieldValue = val[utility::conversions::to_string_t("type")];
74+
if(!fieldValue.is_null())
75+
{
76+
setType(ModelBase::stringFromJson(fieldValue));
77+
}
7078
}
7179
if(val.has_field(utility::conversions::to_string_t("message")))
7280
{
73-
setMessage(ModelBase::stringFromJson(val[utility::conversions::to_string_t("message")]));
81+
web::json::value& fieldValue = val[utility::conversions::to_string_t("message")];
82+
if(!fieldValue.is_null())
83+
{
84+
setMessage(ModelBase::stringFromJson(fieldValue));
85+
}
7486
}
7587
}
7688

samples/client/petstore/cpprest/model/Category.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,19 @@ void Category::fromJson(web::json::value& val)
5656
{
5757
if(val.has_field(utility::conversions::to_string_t("id")))
5858
{
59-
setId(ModelBase::int64_tFromJson(val[utility::conversions::to_string_t("id")]));
59+
web::json::value& fieldValue = val[utility::conversions::to_string_t("id")];
60+
if(!fieldValue.is_null())
61+
{
62+
setId(ModelBase::int64_tFromJson(fieldValue));
63+
}
6064
}
6165
if(val.has_field(utility::conversions::to_string_t("name")))
6266
{
63-
setName(ModelBase::stringFromJson(val[utility::conversions::to_string_t("name")]));
67+
web::json::value& fieldValue = val[utility::conversions::to_string_t("name")];
68+
if(!fieldValue.is_null())
69+
{
70+
setName(ModelBase::stringFromJson(fieldValue));
71+
}
6472
}
6573
}
6674

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Swagger Petstore
3+
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
4+
*
5+
* OpenAPI spec version: 1.0.0
6+
* Contact: [email protected]
7+
*
8+
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
9+
* https://github.com/swagger-api/swagger-codegen.git
10+
* Do not edit the class manually.
11+
*/
12+
13+
14+
15+
#include "Currency.h"
16+
17+
namespace io {
18+
namespace swagger {
19+
namespace client {
20+
namespace model {
21+
22+
Currency::Currency()
23+
{
24+
}
25+
26+
Currency::~Currency()
27+
{
28+
}
29+
30+
void Currency::validate()
31+
{
32+
// TODO: implement validation
33+
}
34+
35+
web::json::value Currency::toJson() const
36+
{
37+
web::json::value val = web::json::value::object();
38+
39+
40+
return val;
41+
}
42+
43+
void Currency::fromJson(web::json::value& val)
44+
{
45+
}
46+
47+
void Currency::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
48+
{
49+
utility::string_t namePrefix = prefix;
50+
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
51+
{
52+
namePrefix += utility::conversions::to_string_t(".");
53+
}
54+
55+
}
56+
57+
void Currency::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
58+
{
59+
utility::string_t namePrefix = prefix;
60+
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
61+
{
62+
namePrefix += utility::conversions::to_string_t(".");
63+
}
64+
65+
}
66+
67+
}
68+
}
69+
}
70+
}
71+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Swagger Petstore
3+
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
4+
*
5+
* OpenAPI spec version: 1.0.0
6+
* Contact: [email protected]
7+
*
8+
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
9+
* https://github.com/swagger-api/swagger-codegen.git
10+
* Do not edit the class manually.
11+
*/
12+
13+
/*
14+
* Currency.h
15+
*
16+
* some description
17+
*/
18+
19+
#ifndef IO_SWAGGER_CLIENT_MODEL_Currency_H_
20+
#define IO_SWAGGER_CLIENT_MODEL_Currency_H_
21+
22+
23+
#include "../ModelBase.h"
24+
25+
26+
namespace io {
27+
namespace swagger {
28+
namespace client {
29+
namespace model {
30+
31+
/// <summary>
32+
/// some description
33+
/// </summary>
34+
class Currency
35+
: public ModelBase
36+
{
37+
public:
38+
Currency();
39+
virtual ~Currency();
40+
41+
/////////////////////////////////////////////
42+
/// ModelBase overrides
43+
44+
void validate() override;
45+
46+
web::json::value toJson() const override;
47+
void fromJson(web::json::value& json) override;
48+
49+
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
50+
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
51+
52+
/////////////////////////////////////////////
53+
/// Currency members
54+
55+
56+
protected:
57+
};
58+
59+
}
60+
}
61+
}
62+
}
63+
64+
#endif /* IO_SWAGGER_CLIENT_MODEL_Currency_H_ */

0 commit comments

Comments
 (0)