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
f33fae22
Commit
f33fae22
authored
Feb 29, 2016
by
octal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Routes can now be hidden from the swagger json file. Also added basePath
parent
07c3163f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
19 deletions
+83
-19
examples/rest_description.cc
examples/rest_description.cc
+4
-2
include/description.h
include/description.h
+58
-15
src/common/description.cc
src/common/description.cc
+21
-2
No files found.
examples/rest_description.cc
View file @
f33fae22
...
@@ -61,12 +61,14 @@ private:
...
@@ -61,12 +61,14 @@ 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
(
"http"
);
desc
.
schemes
(
Rest
::
Scheme
::
Http
);
desc
.
basePath
(
"/v1"
);
desc
desc
.
route
(
desc
.
get
(
"/ready"
))
.
route
(
desc
.
get
(
"/ready"
))
.
bind
(
&
Generic
::
handleReady
)
.
bind
(
&
Generic
::
handleReady
)
.
response
(
Http
::
Code
::
Ok
,
"Response to the /ready call"
);
.
response
(
Http
::
Code
::
Ok
,
"Response to the /ready call"
)
.
hide
();
auto
versionPath
=
desc
.
path
(
"/v1"
);
auto
versionPath
=
desc
.
path
(
"/v1"
);
...
...
include/description.h
View file @
f33fae22
...
@@ -50,10 +50,22 @@ namespace Type {
...
@@ -50,10 +50,22 @@ namespace Type {
}
// namespace Type
}
// namespace Type
enum
class
Flag
{
#define SCHEMES \
Optional
,
Required
SCHEME(Http , "http") \
SCHEME(Https, "https") \
SCHEME(Ws , "ws") \
SCHEME(Wss , "wss") \
enum
class
Scheme
{
#define SCHEME(e, _) e,
SCHEMES
#undef SCHEME
};
};
const
char
*
schemeString
(
Scheme
scheme
);
namespace
Schema
{
namespace
Schema
{
namespace
Traits
{
namespace
Traits
{
...
@@ -253,6 +265,7 @@ struct Path {
...
@@ -253,6 +265,7 @@ struct Path {
std
::
string
value
;
std
::
string
value
;
Http
::
Method
method
;
Http
::
Method
method
;
std
::
string
description
;
std
::
string
description
;
bool
hidden
;
std
::
vector
<
Http
::
Mime
::
MediaType
>
produceMimes
;
std
::
vector
<
Http
::
Mime
::
MediaType
>
produceMimes
;
std
::
vector
<
Http
::
Mime
::
MediaType
>
consumeMimes
;
std
::
vector
<
Http
::
Mime
::
MediaType
>
consumeMimes
;
...
@@ -317,7 +330,17 @@ struct Path {
...
@@ -317,7 +330,17 @@ struct Path {
class
PathGroup
{
class
PathGroup
{
public:
public:
typedef
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
Path
>>
Map
;
struct
Group
:
public
std
::
vector
<
Path
>
{
bool
isHidden
()
const
{
if
(
empty
())
return
false
;
return
std
::
all_of
(
begin
(),
end
(),
[](
const
Path
&
path
)
{
return
path
.
hidden
;
});
}
};
typedef
std
::
unordered_map
<
std
::
string
,
Group
>
Map
;
typedef
Map
::
iterator
iterator
;
typedef
Map
::
iterator
iterator
;
typedef
Map
::
const_iterator
const_iterator
;
typedef
Map
::
const_iterator
const_iterator
;
...
@@ -330,7 +353,7 @@ public:
...
@@ -330,7 +353,7 @@ public:
bool
hasPath
(
const
std
::
string
&
name
,
Http
::
Method
method
)
const
;
bool
hasPath
(
const
std
::
string
&
name
,
Http
::
Method
method
)
const
;
bool
hasPath
(
const
Path
&
path
)
const
;
bool
hasPath
(
const
Path
&
path
)
const
;
std
::
vector
<
Path
>
paths
(
const
std
::
string
&
name
)
const
;
Group
paths
(
const
std
::
string
&
name
)
const
;
Optional
<
Path
>
path
(
const
std
::
string
&
name
,
Http
::
Method
method
)
const
;
Optional
<
Path
>
path
(
const
std
::
string
&
name
,
Http
::
Method
method
)
const
;
group_iterator
add
(
Path
path
);
group_iterator
add
(
Path
path
);
...
@@ -347,21 +370,32 @@ public:
...
@@ -347,21 +370,32 @@ public:
flat_iterator
flatEnd
()
const
;
flat_iterator
flatEnd
()
const
;
template
<
typename
Writer
>
template
<
typename
Writer
>
void
serialize
(
Writer
&
writer
,
Format
format
=
Format
::
Default
)
const
{
void
serialize
(
Writer
&
writer
,
const
std
::
string
&
prefix
,
Format
format
=
Format
::
Default
)
const
{
writer
.
String
(
"paths"
);
writer
.
String
(
"paths"
);
writer
.
StartObject
();
writer
.
StartObject
();
{
{
for
(
const
auto
&
group
:
groups
)
{
for
(
const
auto
&
group
:
groups
)
{
if
(
group
.
second
.
isHidden
())
continue
;
std
::
string
name
(
group
.
first
);
if
(
!
prefix
.
empty
())
{
if
(
!
name
.
compare
(
0
,
prefix
.
size
(),
prefix
))
{
name
=
name
.
substr
(
prefix
.
size
());
}
}
if
(
format
==
Format
::
Default
)
{
if
(
format
==
Format
::
Default
)
{
writer
.
String
(
group
.
first
.
c_str
());
writer
.
String
(
name
.
c_str
());
}
else
{
}
else
{
auto
swaggerPath
=
Path
::
swaggerFormat
(
group
.
first
);
auto
swaggerPath
=
Path
::
swaggerFormat
(
name
);
writer
.
String
(
swaggerPath
.
c_str
());
writer
.
String
(
swaggerPath
.
c_str
());
}
}
writer
.
StartObject
();
writer
.
StartObject
();
{
{
for
(
const
auto
&
path
:
group
.
second
)
{
for
(
const
auto
&
path
:
group
.
second
)
{
path
.
serialize
(
writer
);
if
(
!
path
.
hidden
)
path
.
serialize
(
writer
);
}
}
}
}
writer
.
EndObject
();
writer
.
EndObject
();
...
@@ -436,6 +470,10 @@ struct PathBuilder {
...
@@ -436,6 +470,10 @@ struct PathBuilder {
return
*
this
;
return
*
this
;
}
}
PathBuilder
&
hide
(
bool
value
=
true
)
{
path_
->
hidden
=
value
;
}
private:
private:
Path
*
path_
;
Path
*
path_
;
...
@@ -468,11 +506,11 @@ public:
...
@@ -468,11 +506,11 @@ public:
Schema
::
InfoBuilder
info
();
Schema
::
InfoBuilder
info
();
Description
&
host
(
std
::
string
value
);
Description
&
host
(
std
::
string
value
);
template
<
typename
...
Scheme
>
Description
&
basePath
(
std
::
string
value
);
Description
&
schemes
(
Scheme
...
schemes
)
{
template
<
typename
...
Schemes
>
// @Improve: try to statically assert that every Scheme is convertible to string
Description
&
schemes
(
Schemes
...
schemes
)
{
const
std
::
string
s
[]
=
{
std
::
string
(
schemes
)
...
};
const
Scheme
s
[]
=
{
schemes
...
};
std
::
copy
(
std
::
begin
(
s
),
std
::
end
(
s
),
std
::
back_inserter
(
schemes_
));
std
::
copy
(
std
::
begin
(
s
),
std
::
end
(
s
),
std
::
back_inserter
(
schemes_
));
return
*
this
;
return
*
this
;
}
}
...
@@ -500,18 +538,22 @@ public:
...
@@ -500,18 +538,22 @@ public:
writer
.
String
(
"host"
);
writer
.
String
(
"host"
);
writer
.
String
(
host_
.
c_str
());
writer
.
String
(
host_
.
c_str
());
}
}
if
(
!
basePath_
.
empty
())
{
writer
.
String
(
"basePath"
);
writer
.
String
(
basePath_
.
c_str
());
}
if
(
!
schemes_
.
empty
())
{
if
(
!
schemes_
.
empty
())
{
writer
.
String
(
"schemes"
);
writer
.
String
(
"schemes"
);
writer
.
StartArray
();
writer
.
StartArray
();
{
{
for
(
const
auto
&
scheme
:
schemes_
)
{
for
(
const
auto
&
scheme
:
schemes_
)
{
writer
.
String
(
scheme
.
c_str
(
));
writer
.
String
(
scheme
String
(
scheme
));
}
}
}
}
writer
.
EndArray
();
writer
.
EndArray
();
}
}
paths_
.
serialize
(
writer
,
Schema
::
PathGroup
::
Format
::
Swagger
);
paths_
.
serialize
(
writer
,
basePath_
,
Schema
::
PathGroup
::
Format
::
Swagger
);
}
}
writer
.
EndObject
();
writer
.
EndObject
();
}
}
...
@@ -519,7 +561,8 @@ public:
...
@@ -519,7 +561,8 @@ public:
private:
private:
Schema
::
Info
info_
;
Schema
::
Info
info_
;
std
::
string
host_
;
std
::
string
host_
;
std
::
vector
<
std
::
string
>
schemes_
;
std
::
string
basePath_
;
std
::
vector
<
Scheme
>
schemes_
;
Schema
::
PathGroup
paths_
;
Schema
::
PathGroup
paths_
;
};
};
...
...
src/common/description.cc
View file @
f33fae22
...
@@ -14,6 +14,18 @@ namespace Net {
...
@@ -14,6 +14,18 @@ namespace Net {
namespace
Rest
{
namespace
Rest
{
const
char
*
schemeString
(
Scheme
scheme
)
{
switch
(
scheme
)
{
#define SCHEME(e, str) \
case Scheme::e: \
return str;
SCHEMES
#undef SCHEME
}
return
nullptr
;
}
namespace
Schema
{
namespace
Schema
{
Contact
::
Contact
(
Contact
::
Contact
(
...
@@ -47,6 +59,7 @@ Path::Path(
...
@@ -47,6 +59,7 @@ Path::Path(
:
value
(
std
::
move
(
value
))
:
value
(
std
::
move
(
value
))
,
method
(
method
)
,
method
(
method
)
,
description
(
std
::
move
(
description
))
,
description
(
std
::
move
(
description
))
,
hidden
(
false
)
{
}
{
}
std
::
string
std
::
string
...
@@ -121,11 +134,11 @@ PathGroup::hasPath(const Path& path) const {
...
@@ -121,11 +134,11 @@ PathGroup::hasPath(const Path& path) const {
return
hasPath
(
path
.
value
,
path
.
method
);
return
hasPath
(
path
.
value
,
path
.
method
);
}
}
std
::
vector
<
Path
>
PathGroup
::
Group
PathGroup
::
paths
(
const
std
::
string
&
name
)
const
{
PathGroup
::
paths
(
const
std
::
string
&
name
)
const
{
auto
it
=
groups
.
find
(
name
);
auto
it
=
groups
.
find
(
name
);
if
(
it
==
std
::
end
(
groups
))
if
(
it
==
std
::
end
(
groups
))
return
std
::
vector
<
Path
>
{
};
return
PathGroup
::
Group
{
};
return
it
->
second
;
return
it
->
second
;
}
}
...
@@ -263,6 +276,12 @@ Description::host(std::string value) {
...
@@ -263,6 +276,12 @@ Description::host(std::string value) {
return
*
this
;
return
*
this
;
}
}
Description
&
Description
::
basePath
(
std
::
string
value
)
{
basePath_
=
std
::
move
(
value
);
return
*
this
;
}
Schema
::
PathFragment
Schema
::
PathFragment
Description
::
get
(
std
::
string
name
)
{
Description
::
get
(
std
::
string
name
)
{
return
Schema
::
PathFragment
(
std
::
move
(
name
),
Http
::
Method
::
Get
);
return
Schema
::
PathFragment
(
std
::
move
(
name
),
Http
::
Method
::
Get
);
...
...
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