Skip to content

Commit 26a3503

Browse files
committed
Updated documentation style for jazzy
1 parent 6982d92 commit 26a3503

3 files changed

Lines changed: 151 additions & 77 deletions

File tree

Sources/ApplicationConfiguration/AppProtocol.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ import Foundation
33
import PerfectHTTPServer
44
import PerfectHTTP
55

6-
/// A protocol to define Applications
7-
/// name: application name
8-
/// config: application configuration
9-
/// routes: a group of routes
10-
/// filters: application filters (request & response)
11-
/// init: to initialize the Application
12-
/// server to return the server object
6+
/**
7+
A protocol to define Applications
8+
It is already implemented by Application
9+
- see also: Application
10+
*/
1311
public protocol AppProtocol {
12+
/// application name
1413
var name: String { get }
14+
/// application configuration
1515
var config: Configuration? { get}
16+
/// a group of routes
1617
var routes: Routes? { get }
18+
/// application filters (request & response)
1719
var filters: AppFilters? { get }
20+
/// initialize the Application
1821
init(name: String, path: String)
22+
/// to return the server object
1923
func server() -> HTTPServer.Server
2024
}

Sources/ApplicationConfiguration/Application.swift

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,72 @@ import PerfectLib
44
import PerfectHTTPServer
55
import PerfectHTTP
66

7-
/// This struct represnts an Application
8-
/// with its configuration, routes and filters
9-
/// You could use this application or create another
10-
/// Application object that complies with AppProtocol
7+
/**
8+
This struct represnts an Application
9+
with its configuration, routes and filters
10+
You could use this application or create another
11+
Application object that complies with AppProtocol
12+
- see also: AppProtocol
13+
*/
1114
public struct Application: AppProtocol {
12-
15+
/// Application name
1316
public var name: String
17+
/// Application routes
1418
public var routes: Routes?
19+
/// Application configuration
1520
public var config: Configuration?
21+
/// Application filters
1622
public var filters: AppFilters?
17-
/// init with only name and configuration file path
18-
/// - parameter name: application name
19-
/// - parameter path: confuration file path - a json file that represents the configs such as:
20-
/// {
21-
/// "server": {
22-
/// "baseURL": "localhost:8181",
23-
/// "baseDomain": "localhost",
24-
/// "port": 8181,
25-
/// "secure": 0
26-
/// },
27-
/// "os": 2,
28-
/// "environment": 1,
29-
/// "ssl": {
30-
/// "port": 443,
31-
/// "originCertificatePath": "",
32-
/// "privateKeyPath": "",
33-
/// "verifyMode": "peer"
34-
/// },
35-
/// "logging": {
36-
/// "requestLoggingPath": "./perfectRequests.log",
37-
/// "logPath": "./perfect.log"
38-
/// },
39-
/// "db": {
40-
/// "name": "perfect",
41-
/// "host": "localhost",
42-
/// "port": 3306,
43-
/// "user": "",
44-
/// "pass": "",
45-
/// "driverType": 1
46-
/// }
47-
/// }
23+
/**
24+
init with only name and configuration file path
25+
- parameters:
26+
- name: application name
27+
- path: confuration file path - a json file that represents the configs
28+
### Example configuration JSON:
29+
````
30+
{
31+
"server": {
32+
"baseURL": "localhost:8181",
33+
"baseDomain": "localhost",
34+
"port": 8181,
35+
"secure": 0
36+
},
37+
"os": 2,
38+
"environment": 1,
39+
"ssl": {
40+
"port": 443,
41+
"originCertificatePath": "",
42+
"privateKeyPath": "",
43+
"verifyMode": "peer"
44+
},
45+
"logging": {
46+
"requestLoggingPath": "./perfectRequests.log",
47+
"logPath": "./perfect.log"
48+
},
49+
"db": {
50+
"name": "perfect",
51+
"host": "localhost",
52+
"port": 3306,
53+
"user": "",
54+
"pass": "",
55+
"driverType": 1
56+
}
57+
}
58+
````
59+
*/
4860
public init(name: String, path: String) {
4961
self.init(name: name, path: path, routes: nil, filters: nil)
5062
self.name = name
5163
}
52-
/// init with name, path, routes and filters
53-
/// - parameter name: application name
54-
/// - parameter path: confuration file path - a json file that represents the configs
55-
/// - parameter routes: a group of routes
56-
/// - parameter filters: application filters (request & response)
64+
65+
/**
66+
init with name, path, routes and filters
67+
- parameters:
68+
- name: application name
69+
- path: confuration file path - a json file that represents the configs
70+
- routes: a group of routes
71+
- filters: application filters (request & response)
72+
*/
5773
public init(name: String,
5874
path: String,
5975
routes: Routes?,
@@ -86,7 +102,11 @@ public struct Application: AppProtocol {
86102
self.filters = nil
87103
}
88104
}
89-
/// return configured server
105+
106+
/**
107+
Configure and return the server
108+
- Returns: HTTPServer.Server
109+
*/
90110
public func server() -> HTTPServer.Server {
91111

92112
let port = config?.server?.port ?? 8181

Sources/ApplicationConfiguration/Configuration.swift

Lines changed: 78 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11

22
import Foundation
3-
4-
/// This struct represents the configuration of
5-
/// an application
6-
/// example usage:
7-
/// // path represents a json file location that have the same key names as the struct props
8-
/// let file = File(path)
9-
/// if file.exists == false {
10-
/// print("Configuration file doesn't exist!")
11-
/// }
12-
/// do {
13-
/// try file.open(.read, permissions: .readUser)
14-
/// defer { file.close() }
15-
/// let json = try file.readString()
16-
/// let conf = try Configuration(json)
17-
/// app.config = conf // assign it to your application's config to be used when you launch the server
18-
/// } catch {
19-
/// print(error)
20-
/// }
21-
3+
/**
4+
This struct represents the configuration of an application
5+
### Example usage: ###
6+
````
7+
// path represents a json file location that have the same key names as the struct props
8+
let file = File(path)
9+
if file.exists == false {
10+
print("Configuration file doesn't exist!")
11+
}
12+
do {
13+
try file.open(.read, permissions: .readUser)
14+
defer { file.close() }
15+
let json = try file.readString()
16+
let conf = try Configuration(json)
17+
app.config = conf // assign it to your application's config to be used when you launch the server
18+
} catch {
19+
print(error)
20+
}
21+
````
22+
*/
2223
public struct Configuration: Codable {
2324
/// server configuration including url and port
2425
let server: ServerConfiguration?
@@ -35,31 +36,59 @@ public struct Configuration: Codable {
3536
let environment: Environment?
3637
}
3738

38-
/// This struct represents the server configuration
39+
/**
40+
This struct represents the server configuration
41+
*/
3942
public struct ServerConfiguration: Codable {
43+
/// base URL
4044
let baseURL: String?
45+
/// base domain
4146
let baseDomain: String?
47+
/// port
4248
let port: Int?
49+
/// if it is a https server 1 else 0
4350
let secure: Int?
4451
}
4552

46-
/// configuration for logging
53+
/**
54+
configuration for logging
55+
*/
4756
public struct LoggingConfiguration: Codable {
57+
/// logging path for requests
4858
let requestLoggingPath: String?
59+
/// logging path
4960
let logPath: String?
5061
}
5162

52-
/// database configuration that should be initialized when Configuration is initialized
53-
/// ScantORM uses this configuration to initialize the DatabaseAdapter
54-
/// You can use it without ScantORM if you need to
63+
/**
64+
database configuration that should be initialized when Configuration is initialized.
65+
**ScantORM** uses this configuration to initialize the DatabaseAdapter.
66+
You can use it without ScantORM if you need to!
67+
*/
5568
public struct DBConfiguration: Codable {
69+
/// database name
5670
public let name: String?
71+
/// host url
5772
public let host: String?
73+
/// port
5874
public let port: Int?
75+
/// database user name
5976
public let user: String?
77+
/// database password
6078
public let pass: String?
79+
/// database driver type
6180
public let driverType: DBDriverType
6281

82+
/**
83+
initialize the database configuration
84+
- parameters:
85+
- name: database name
86+
- host: host url
87+
- port: port address
88+
- user: user name
89+
- pass: password
90+
- driverType: database driver type such as mySQL
91+
*/
6392
public init(name: String?,
6493
host: String?,
6594
port: Int?,
@@ -75,36 +104,57 @@ public struct DBConfiguration: Codable {
75104
}
76105
}
77106

78-
/// Database driver type
107+
/**
108+
Database driver type
109+
*/
79110
public enum DBDriverType: Int, Codable {
111+
/// MySQL
80112
case mySQL = 1
113+
/// PostgreSQL
81114
case postgreSQL = 2
115+
/// SQLite
82116
case sqLite = 3
83117
}
84118

85-
/// SSL configuration for https server
119+
/**
120+
SSL configuration for https server
121+
*/
86122
public struct SSLConfiguration: Codable {
123+
/// https port
87124
let port: Int?
125+
/// origin certificate path
88126
let originCertificatePath: String?
127+
/// private key path
89128
let privateKeyPath: String?
129+
/// verify mode
90130
let verifyMode: String?
91131
}
92132

93-
/// operating system
133+
/**
134+
operating system
135+
*/
94136
public enum OS: Int, Codable {
137+
/// Linux
95138
case linux = 1
139+
/// macOS
96140
case macOS = 2
97141
}
98142

99-
/// deployment environment
143+
/**
144+
deployment environment
145+
*/
100146
public enum Environment: Int, Codable {
147+
/// development environment
101148
case dev = 1
149+
/// pre production environment
102150
case preProd = 2
151+
/// production environment
103152
case prod = 3
104153
}
105154

106155
// MARK: Convenience initializers
107156

157+
108158
extension Configuration {
109159
/// init configuration with Data
110160
public init(data: Data) throws {

0 commit comments

Comments
 (0)