Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
pistache
Commits
65df3deb
Commit
65df3deb
authored
Feb 29, 2016
by
octal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added produce and consume fields to the root description
parent
6db3a102
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
22 deletions
+53
-22
examples/rest_description.cc
examples/rest_description.cc
+6
-3
include/description.h
include/description.h
+47
-19
No files found.
examples/rest_description.cc
View file @
65df3deb
...
@@ -61,8 +61,11 @@ private:
...
@@ -61,8 +61,11 @@ private:
auto
backendErrorResponse
=
auto
backendErrorResponse
=
desc
.
response
(
Http
::
Code
::
Internal_Server_Error
,
"An error occured with the backend"
);
desc
.
response
(
Http
::
Code
::
Internal_Server_Error
,
"An error occured with the backend"
);
desc
.
schemes
(
Rest
::
Scheme
::
Http
);
desc
desc
.
basePath
(
"/v1"
);
.
schemes
(
Rest
::
Scheme
::
Http
)
.
basePath
(
"/v1"
)
.
produces
(
MIME
(
Application
,
Json
))
.
consumes
(
MIME
(
Application
,
Json
));
desc
desc
.
route
(
desc
.
get
(
"/ready"
))
.
route
(
desc
.
get
(
"/ready"
))
...
@@ -77,7 +80,7 @@ private:
...
@@ -77,7 +80,7 @@ private:
accountsPath
accountsPath
.
route
(
desc
.
get
(
"/all"
))
.
route
(
desc
.
get
(
"/all"
))
.
bind
(
&
BankerService
::
retrieveAllAccounts
,
this
)
.
bind
(
&
BankerService
::
retrieveAllAccounts
,
this
)
.
produces
(
MIME
(
Application
,
Json
))
.
produces
(
MIME
(
Application
,
Json
)
,
MIME
(
Application
,
Xml
)
)
.
response
(
Http
::
Code
::
Ok
,
"The list of all account"
);
.
response
(
Http
::
Code
::
Ok
,
"The list of all account"
);
accountsPath
accountsPath
...
...
include/description.h
View file @
65df3deb
...
@@ -104,6 +104,32 @@ template<typename DT> struct DataTypeValidation {
...
@@ -104,6 +104,32 @@ template<typename DT> struct DataTypeValidation {
}
// namespace Traits
}
// namespace Traits
struct
ProduceConsume
{
std
::
vector
<
Http
::
Mime
::
MediaType
>
produce
;
std
::
vector
<
Http
::
Mime
::
MediaType
>
consume
;
template
<
typename
Writer
>
void
serialize
(
Writer
&
writer
)
const
{
auto
serializeMimes
=
[
&
](
const
char
*
name
,
const
std
::
vector
<
Http
::
Mime
::
MediaType
>&
mimes
)
{
if
(
!
mimes
.
empty
())
{
writer
.
String
(
name
);
writer
.
StartArray
();
{
for
(
const
auto
&
mime
:
mimes
)
{
auto
str
=
mime
.
toString
();
writer
.
String
(
str
.
c_str
());
}
}
writer
.
EndArray
();
}
};
serializeMimes
(
"consumes"
,
consume
);
serializeMimes
(
"produces"
,
produce
);
}
};
struct
Contact
{
struct
Contact
{
Contact
(
std
::
string
name
,
std
::
string
url
,
std
::
string
email
);
Contact
(
std
::
string
name
,
std
::
string
url
,
std
::
string
email
);
...
@@ -267,8 +293,7 @@ struct Path {
...
@@ -267,8 +293,7 @@ struct Path {
std
::
string
description
;
std
::
string
description
;
bool
hidden
;
bool
hidden
;
std
::
vector
<
Http
::
Mime
::
MediaType
>
produceMimes
;
ProduceConsume
pc
;
std
::
vector
<
Http
::
Mime
::
MediaType
>
consumeMimes
;
std
::
vector
<
Parameter
>
parameters
;
std
::
vector
<
Parameter
>
parameters
;
std
::
vector
<
Response
>
responses
;
std
::
vector
<
Response
>
responses
;
...
@@ -282,19 +307,6 @@ struct Path {
...
@@ -282,19 +307,6 @@ struct Path {
template
<
typename
Writer
>
template
<
typename
Writer
>
void
serialize
(
Writer
&
writer
)
const
{
void
serialize
(
Writer
&
writer
)
const
{
auto
serializeMimes
=
[
&
](
const
char
*
name
,
const
std
::
vector
<
Http
::
Mime
::
MediaType
>&
mimes
)
{
if
(
!
mimes
.
empty
())
{
writer
.
String
(
name
);
writer
.
StartArray
();
{
for
(
const
auto
&
mime
:
mimes
)
{
auto
str
=
mime
.
toString
();
writer
.
String
(
str
.
c_str
());
}
}
writer
.
EndArray
();
}
};
std
::
string
methodStr
(
methodString
(
method
));
std
::
string
methodStr
(
methodString
(
method
));
// So it looks like Swagger requires method to be in lowercase
// So it looks like Swagger requires method to be in lowercase
...
@@ -305,8 +317,7 @@ struct Path {
...
@@ -305,8 +317,7 @@ struct Path {
{
{
writer
.
String
(
"description"
);
writer
.
String
(
"description"
);
writer
.
String
(
description
.
c_str
());
writer
.
String
(
description
.
c_str
());
serializeMimes
(
"consumes"
,
consumeMimes
);
pc
.
serialize
(
writer
);
serializeMimes
(
"produces"
,
produceMimes
);
if
(
!
parameters
.
empty
())
{
if
(
!
parameters
.
empty
())
{
writer
.
String
(
"parameters"
);
writer
.
String
(
"parameters"
);
writer
.
StartArray
();
writer
.
StartArray
();
...
@@ -418,14 +429,14 @@ struct PathBuilder {
...
@@ -418,14 +429,14 @@ struct PathBuilder {
template
<
typename
...
Mimes
>
template
<
typename
...
Mimes
>
PathBuilder
&
produces
(
Mimes
...
mimes
)
{
PathBuilder
&
produces
(
Mimes
...
mimes
)
{
const
Http
::
Mime
::
MediaType
m
[]
=
{
mimes
...
};
const
Http
::
Mime
::
MediaType
m
[]
=
{
mimes
...
};
std
::
copy
(
std
::
begin
(
m
),
std
::
end
(
m
),
std
::
back_inserter
(
path_
->
p
roduceMimes
));
std
::
copy
(
std
::
begin
(
m
),
std
::
end
(
m
),
std
::
back_inserter
(
path_
->
p
c
.
produce
));
return
*
this
;
return
*
this
;
}
}
template
<
typename
...
Mimes
>
template
<
typename
...
Mimes
>
PathBuilder
&
consumes
(
Mimes
...
mimes
)
{
PathBuilder
&
consumes
(
Mimes
...
mimes
)
{
const
Http
::
Mime
::
MediaType
m
[]
=
{
mimes
...
};
const
Http
::
Mime
::
MediaType
m
[]
=
{
mimes
...
};
std
::
copy
(
std
::
begin
(
m
),
std
::
end
(
m
),
std
::
back_inserter
(
path_
->
consumeMimes
));
std
::
copy
(
std
::
begin
(
m
),
std
::
end
(
m
),
std
::
back_inserter
(
path_
->
pc
.
consume
));
return
*
this
;
return
*
this
;
}
}
...
@@ -511,6 +522,7 @@ public:
...
@@ -511,6 +522,7 @@ public:
Description
&
host
(
std
::
string
value
);
Description
&
host
(
std
::
string
value
);
Description
&
basePath
(
std
::
string
value
);
Description
&
basePath
(
std
::
string
value
);
template
<
typename
...
Schemes
>
template
<
typename
...
Schemes
>
Description
&
schemes
(
Schemes
...
schemes
)
{
Description
&
schemes
(
Schemes
...
schemes
)
{
...
@@ -519,6 +531,20 @@ public:
...
@@ -519,6 +531,20 @@ public:
return
*
this
;
return
*
this
;
}
}
template
<
typename
...
Mimes
>
Description
&
produces
(
Mimes
...
mimes
)
{
const
Http
::
Mime
::
MediaType
m
[]
=
{
mimes
...
};
std
::
copy
(
std
::
begin
(
m
),
std
::
end
(
m
),
std
::
back_inserter
(
pc
.
produce
));
return
*
this
;
}
template
<
typename
...
Mimes
>
Description
&
consumes
(
Mimes
...
mimes
)
{
const
Http
::
Mime
::
MediaType
m
[]
=
{
mimes
...
};
std
::
copy
(
std
::
begin
(
m
),
std
::
end
(
m
),
std
::
back_inserter
(
pc
.
consume
));
return
*
this
;
}
Schema
::
PathFragment
get
(
std
::
string
name
);
Schema
::
PathFragment
get
(
std
::
string
name
);
Schema
::
PathFragment
post
(
std
::
string
name
);
Schema
::
PathFragment
post
(
std
::
string
name
);
Schema
::
PathFragment
put
(
std
::
string
name
);
Schema
::
PathFragment
put
(
std
::
string
name
);
...
@@ -556,6 +582,7 @@ public:
...
@@ -556,6 +582,7 @@ public:
}
}
writer
.
EndArray
();
writer
.
EndArray
();
}
}
pc
.
serialize
(
writer
);
paths_
.
serialize
(
writer
,
basePath_
,
Schema
::
PathGroup
::
Format
::
Swagger
);
paths_
.
serialize
(
writer
,
basePath_
,
Schema
::
PathGroup
::
Format
::
Swagger
);
}
}
...
@@ -567,6 +594,7 @@ private:
...
@@ -567,6 +594,7 @@ private:
std
::
string
host_
;
std
::
string
host_
;
std
::
string
basePath_
;
std
::
string
basePath_
;
std
::
vector
<
Scheme
>
schemes_
;
std
::
vector
<
Scheme
>
schemes_
;
Schema
::
ProduceConsume
pc
;
Schema
::
PathGroup
paths_
;
Schema
::
PathGroup
paths_
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment