Skip to content

Commit 53512f0

Browse files
authored
CI Fixes (#16)
* Added doc generation * Removed testing branch * Added a bunch more doc references * Fixed several documentation warnings
1 parent 8bdedd5 commit 53512f0

16 files changed

+239
-211
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: CI
1+
name: Build
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ main ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ main ]
88

99
jobs:
1010
build:
Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,52 @@
1+
# Workflow for building DocC documentation and deploying to GitHub Pages
12
name: Documentation
23

34
on:
5+
# Runs on pushes targeting the default branch
46
push:
5-
branches:
6-
- master
7-
paths:
8-
- .github/workflows/documentation.yml
9-
- Sources/**.swift
7+
branches: ["main"]
108

11-
jobs:
12-
build:
13-
runs-on: ubuntu-latest
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
1417

18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
docs:
26+
runs-on: macos-latest
1527
steps:
1628
- name: Checkout
17-
uses: actions/checkout@v1
18-
- name: Generate Documentation
19-
uses: SwiftDocOrg/swift-doc@master
29+
uses: actions/checkout@v3
30+
- name: Set up Pages
31+
uses: actions/configure-pages@v3
32+
- name: Generate Docs
33+
run: |
34+
xcodebuild docbuild -scheme Endpoints -destination generic/platform=iOS OTHER_DOCC_FLAGS="--transform-for-static-hosting --hosting-base-path Endpoints --output-path docs"
35+
- name: Upload artifact
36+
uses: actions/upload-pages-artifact@v2
2037
with:
21-
inputs: "Sources"
22-
module-name: Endpoints
23-
base-url: "https://github.com/velos/Endpoints/wiki"
24-
output: "docs"
38+
path: ./docs
2539

26-
- name: Upload Documentation to Wiki
27-
uses: SwiftDocOrg/github-wiki-publish-action@v1
28-
with:
29-
path: "docs"
30-
env:
31-
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
40+
# Single deploy job since we're just deploying
41+
deploy:
42+
environment:
43+
name: github-pages
44+
url: ${{ steps.deployment.outputs.page_url }}
45+
46+
runs-on: ubuntu-latest
47+
needs: docs
48+
49+
steps:
50+
- name: Deploy to GitHub Pages
51+
id: deployment
52+
uses: actions/deploy-pages@v2

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.5
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The purpose of Endpoints is to, in a type-safe way, define how to create a `URLR
1212

1313
The basic process for defining an Endpoint starts with defining a value conforming to `Endpoint`. With the `Endpoint` protocol, you are encapsulating the definition of the endpoint, all the properties that are plugged into the definition and the types for parsing the response. Within the `Endpoint`, the `definition` static var serves as an immutable definition of the server's endpoint and how the variable pieces of the `Endpoint` should fit together when making the full request.
1414

15-
To get started, first create a type (struct or class) conforming to `Endpoint`. There are only two required elements to conform: defining the `Response` and creating the `Definition`.
15+
To get started, first create a type (struct or class) conforming to `Endpoint`. There are only two required elements to conform: defining the `Response` and creating the ``Definition``.
1616

1717
`Endpoints` and `Definitions` do not contain base URLs so that these requests can be used on different environments. Environments are defined as conforming to the `EnvironmentType` and implement a `baseURL` as well as an optional `requestProcessor` which has a final hook before `URLRequest` creation to modify the `URLRequest` to attach authentication or signatures.
1818

Sources/Endpoints/Definition+URLResponse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
import Foundation
1010

11-
extension Definition {
11+
public extension Definition {
1212

1313
/// Converts data, response and error into a Result type by processing data and throwing errors based on response codes and response data.
1414
/// - Parameters:
1515
/// - data: The raw data fetched in the response
1616
/// - response: The response object
1717
/// - error: Any error encountered by the fetch
1818
/// - Returns: A Result value with either the Data or the T.TaskError
19-
public func response(data: Data?, response: URLResponse?, error: Error?) -> Result<Data, T.TaskError> {
19+
func response(data: Data?, response: URLResponse?, error: Error?) -> Result<Data, T.TaskError> {
2020
if let error = error {
2121
guard (error as NSError).code != URLError.Code.notConnectedToInternet.rawValue else {
2222
return .failure(.internetConnectionOffline)

Sources/Endpoints/Endpoint+URLRequest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ extension Endpoint {
1616

1717
/// Generates a `URLRequest` given the associated request value.
1818
/// - Parameter environment: The environment in which to create the request
19-
/// - Throws: An `EndpointError` which describes the error filling in data to the associated `Definition`.
20-
/// - Returns: A `URLRequest` ready for requesting with all values from `self` filled in according to the associated `Endpoint`.
19+
/// - Throws: An ``EndpointError`` which describes the error filling in data to the associated ``Definition``.
20+
/// - Returns: A `URLRequest` ready for requesting with all values from `self` filled in according to the associated ``Endpoint``.
2121
public func urlRequest(in environment: EnvironmentType) throws -> URLRequest {
2222

2323
var components = URLComponents()

Sources/Endpoints/Endpoint.swift

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,59 +49,95 @@ extension JSONDecoder: DecoderType { }
4949

5050
public protocol Endpoint {
5151

52-
/// The response type received from the server. Note that this is just type information which helpers, such as the built-in `URLSession` extensions,
52+
/// The response type received from the server.
53+
///
54+
/// This conveys type information which helpers, such as the built-in ``Foundation/URLSession`` extensions,
5355
/// can use to know how to handle particular types. For instance, if this type conforms to `Decodable`, then a JSON decoder is used
5456
/// on the data coming from the server. If it's typealiased to `Void`, then the extension can know to ignore the response. If it's `Data`, then it can deliver the
5557
/// response data unmodified.
5658
associatedtype Response
5759

58-
/// The type representing the `Decodable` error response from the server. Defaults to an empty `Decodable` struct, `EmptyCodable`.
60+
/// The type representing the `Decodable` error response from the server. Defaults to an empty `Decodable` struct, ``EmptyCodable``.
61+
///
5962
/// This can be useful if your server returns a different JSON structure when there's an error versus a success. Often in a project, this can be defined globally
60-
/// and `typealias` can be used to associate this global type on all `Endpoint`s.
63+
/// and `typealias` can be used to associate this global type on all ``Endpoint``s.
6164
associatedtype ErrorResponse: Decodable = EmptyCodable
6265

63-
/// The body type conforming to `Encodable`. Defaults to `EmptyCodable`.
66+
/// The body type conforming to `Encodable`. Defaults to ``EmptyCodable``.
6467
associatedtype Body: Encodable = EmptyCodable
6568

66-
/// The values needed to fill the `Definition`'s path.
69+
/// The values needed to fill the ``Definition``'s path.
70+
///
71+
/// If a ``Endpoint/PathComponents`` type is associated, properties of that type can be utilized in the `path` of the ``Endpoint`` using a path string interpolation syntax:
72+
///
73+
/// ```swift
74+
/// struct DeleteEndpoint: Endpoint {
75+
/// static let definition: Definition<DeleteEndpoint> = Definition(
76+
/// method: .delete,
77+
/// path: "calendar/v3/calendars/\(path: \.calendarId)/events\(path: \.eventId)"
78+
/// )
79+
///
80+
/// typealias Response = Void
81+
///
82+
/// struct PathComponents {
83+
/// let calendarId: String
84+
/// let eventId: String
85+
/// }
86+
///
87+
/// let pathComponents: PathComponents
88+
/// }
89+
/// ```
6790
associatedtype PathComponents = Void
6891

69-
/// The values needed to fill the `Definition`'s parameters.
92+
/// The values needed to fill the ``Definition``'s parameters.
93+
///
94+
/// A ``Endpoint/ParameterComponents`` type, in a similar way to ``Endpoint/PathComponents``, holds properties that can be referenced in the ``Endpoint`` via ``Parameter`` values in order to define form parameters used in the body or query parameters attached to the URL. The enum type is defined as:
95+
///
96+
/// ```swift
97+
/// public enum Parameter<T> {
98+
/// case form(String, path: PartialKeyPath<T>)
99+
/// case formValue(String, value: PathRepresentable)
100+
/// case query(String, path: PartialKeyPath<T>)
101+
/// case queryValue(String, value: PathRepresentable)
102+
/// }
103+
/// ```
104+
///
105+
/// With this enum, either hard-coded values can be injected into the ``Endpoint`` (with ``Parameter/formValue(_:value:)`` or ``Parameter/queryValue(_:value:)``) or key paths can define which reference properties in the ``Endpoint/ParameterComponents`` associated type to define a form or query parameter that is needed at the time of the request.
70106
associatedtype ParameterComponents = Void
71107

72-
/// The values needed to fill the `Definition`'s headers.
108+
/// The values needed to fill the ``Definition``'s headers.
73109
associatedtype HeaderComponents = Void
74110

75-
/// The `EncoderType` to use when encoding the body of the request. Defaults to `JSONEncoder`.
111+
/// The ``EncoderType`` to use when encoding the body of the request. Defaults to `JSONEncoder`.
76112
associatedtype BodyEncoder: EncoderType = JSONEncoder
77-
/// The `DecoderType` to use when decoding the body of the request. Defaults to `JSONDecoder`.
113+
/// The ``DecoderType`` to use when decoding the body of the request. Defaults to `JSONDecoder`.
78114
associatedtype ErrorDecoder: DecoderType = JSONDecoder
79-
/// The `DecoderType` to use when decoding the response. Defaults to `JSONDecoder`.
115+
/// The ``DecoderType`` to use when decoding the response. Defaults to `JSONDecoder`.
80116
associatedtype ResponseDecoder: DecoderType = JSONDecoder
81117

82-
/// A `Definition` which pieces together all the components defined in the endpoint.
118+
/// A ``Definition`` which pieces together all the components defined in the endpoint.
83119
static var definition: Definition<Self> { get }
84120

85121
/// The instance of the associated `Body` type. Must be `Encodable`.
86122
var body: Body { get }
87123

88-
/// The instance of the associated `PathComponents` type. Used for filling in request data into the path template of the endpoint.
124+
/// The instance of the associated ``Endpoint/PathComponents`` type. Used for filling in request data into the path template of the endpoint.
89125
/// If none are necessary, this can be `Void`
90126
var pathComponents: PathComponents { get }
91127

92-
/// The instance of the associated `ParameterComponents` type. Used for filling in request data into the query and form parameters of the endpoint.
128+
/// The instance of the associated ``Endpoint/ParameterComponents`` type. Used for filling in request data into the query and form parameters of the endpoint.
93129
var parameterComponents: ParameterComponents { get }
94130

95-
/// The instance of the associated `HeaderComponents` type. Used for filling in request data into the headers of the endpoint.
131+
/// The instance of the associated ``Endpoint/HeaderComponents`` type. Used for filling in request data into the headers of the endpoint.
96132
var headerComponents: HeaderComponents { get }
97133

98-
/// The decoder instance to use when decoding the associated `Body` type
134+
/// The decoder instance to use when decoding the associated ``Endpoint/Body`` type
99135
static var bodyEncoder: BodyEncoder { get }
100136

101-
/// The decoder instance to use when decoding the associated `ErrorResponse` type
137+
/// The decoder instance to use when decoding the associated ``Endpoint/ErrorResponse`` type
102138
static var errorDecoder: ErrorDecoder { get }
103139

104-
/// The decoder instance to use when decoding the associated `Response` type
140+
/// The decoder instance to use when decoding the associated ``Endpoint/Response`` type
105141
static var responseDecoder: ResponseDecoder { get }
106142
}
107143

@@ -140,18 +176,18 @@ public extension Endpoint where BodyEncoder == JSONEncoder {
140176

141177
public struct Definition<T: Endpoint> {
142178

143-
/// The HTTP method of the Endpoint
179+
/// The HTTP method of the ``Endpoint``
144180
public let method: Method
145181
/// A template including all elements that appear in the path
146182
public let path: PathTemplate<T.PathComponents>
147-
/// The parameters (form and query) that are included in the Definition
183+
/// The parameters (form and query) that are included in the ``Definition``
148184
public let parameters: [Parameter<T.ParameterComponents>]
149-
/// The headers that are included in the Definition
185+
/// The headers that are included in the ``Definition``
150186
public let headers: [Header: HeaderField<T.HeaderComponents>]
151187

152-
/// Initializes a Definition with the given properties, defining all dynamic pieces as type-safe parameters.
188+
/// Initializes a ``Definition`` with the given properties, defining all dynamic pieces as type-safe parameters.
153189
/// - Parameters:
154-
/// - method: The HTTP method to use when fetching the owning Endpoint
190+
/// - method: The HTTP method to use when fetching the owning ``Endpoint``
155191
/// - path: The path template representing the path and all path-related parameters
156192
/// - parameters: The parameters passed to the endpoint. Either through query or form body.
157193
/// - headerValues: The headers associated with this request
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ``Endpoints``
2+
3+
Endpoints is a small library for creating statically and strongly-typed definitions of endpoints with paths, methods, inputs and outputs.
4+
5+
## Overview
6+
7+
The purpose of Endpoints is to, in a type-safe way, define how to create a `URLRequest` from typed properties and, additionally, define how a response for the request should be handled. The library not only includes the ability to create these requests in a type-safe way, but also includes helpers to perform the requests using ``Foundation/URLSession``. Endpoints does not try to wrap the URL loading system to provide features on top of it like Alamofire. Instead, Endpoints focuses on defining endpoints and associated data to produce a request as a URLRequest object to be plugged into vanilla ``Foundation/URLSession``s. However, this library could be used in conjunction with Alamofire if desired.
8+
9+
## Topics
10+
11+
### Essentials
12+
13+
- ``Endpoint``
14+
- ``EnvironmentType``
15+
- <doc:Examples>
16+
17+
### Making Requests
18+
19+
#### Combine
20+
21+
- ``Foundation/URLSession``
22+
- ``Endpoint/Response``

0 commit comments

Comments
 (0)