Skip to content

Commit

Permalink
use SwiftStencilKit
Browse files Browse the repository at this point in the history
  • Loading branch information
yonaskolb committed Feb 20, 2019
1 parent 70cdf16 commit c79543e
Show file tree
Hide file tree
Showing 74 changed files with 76 additions and 292 deletions.
27 changes: 18 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/kylef/PathKit.git",
"state": {
"branch": null,
"revision": "891a3fec2699fc43aed18b7649950677c0152a22",
"version": "0.8.0"
"revision": "e2f5be30e4c8f531c9c1e8765aa7b71c0a45d7a0",
"version": "0.9.2"
}
},
{
Expand All @@ -33,26 +33,35 @@
"repositoryURL": "https://github.com/kylef/Spectre.git",
"state": {
"branch": null,
"revision": "e46b75cf03ad5e563b4b0a5068d3d6f04d77d80b",
"version": "0.7.2"
"revision": "f14ff47f45642aa5703900980b014c2e9394b6e5",
"version": "0.9.0"
}
},
{
"package": "Stencil",
"repositoryURL": "https://github.com/yonaskolb/Stencil.git",
"repositoryURL": "https://github.com/stencilproject/Stencil.git",
"state": {
"branch": null,
"revision": "daf4e41549a534904376794e899ca6aecaf4ff83",
"version": "0.9.3"
"revision": "0e9a78d6584e3812cd9c09494d5c7b483e8f533c",
"version": "0.13.1"
}
},
{
"package": "StencilSwiftKit",
"repositoryURL": "https://github.com/SwiftGen/StencilSwiftKit.git",
"state": {
"branch": null,
"revision": "dbf02bd6afe71b65ead2bd250aaf974abc688094",
"version": "2.7.2"
}
},
{
"package": "SwiftCLI",
"repositoryURL": "https://github.com/jakeheis/SwiftCLI",
"state": {
"branch": null,
"revision": "37f4a7f863f6fe76ce44fc0023f331eea0089beb",
"version": "5.2.0"
"revision": "5318c37d3cacc8780f50b87a8840a6774320ebdf",
"version": "5.2.2"
}
},
{
Expand Down
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ let package = Package(
.library(name: "Swagger", targets: ["Swagger"]),
],
dependencies: [
.package(url: "https://github.com/kylef/PathKit.git", from: "0.8.0"),
.package(url: "https://github.com/kylef/PathKit.git", from: "0.9.0"),
.package(url: "https://github.com/jakeheis/SwiftCLI", from: "5.0.0"),
.package(url: "https://github.com/yonaskolb/Stencil.git", from: "0.9.0"),
.package(url: "https://github.com/SwiftGen/StencilSwiftKit.git", from: "2.7.2"),
.package(url: "https://github.com/jpsim/Yams.git", from: "1.0.0"),
.package(url: "https://github.com/yonaskolb/JSONUtilities.git", from: "3.3.0"),
.package(url: "https://github.com/kylef/Spectre.git", from: "0.7.0"),
.package(url: "https://github.com/kylef/Spectre.git", from: "0.9.0"),
.package(url: "https://github.com/onevcat/Rainbow.git", from: "3.1.0"),
],
targets: [
Expand All @@ -28,7 +28,7 @@ let package = Package(
"Swagger",
"JSONUtilities",
"PathKit",
"Stencil",
"StencilSwiftKit",
]),
.target(name: "Swagger", dependencies: [
"JSONUtilities",
Expand Down
8 changes: 7 additions & 1 deletion Sources/SwagGenKit/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation
import JSONUtilities
import PathKit
import Stencil
import StencilSwiftKit

public class Generator {

Expand All @@ -21,7 +22,12 @@ public class Generator {
filterExtension.registerFilter("lowerCamelCase") { ($0 as? String)?.lowerCamelCased() ?? $0 }
filterExtension.registerFilter("upperCamelCase") { ($0 as? String)?.upperCamelCased() ?? $0 }

environment = Environment(loader: FileSystemLoader(paths: [templateConfig.basePath]), extensions: [filterExtension])
let stencilSwiftKitExtension = Extension()
stencilSwiftKitExtension.registerStencilSwiftExtensions()

environment = Environment(loader: FileSystemLoader(paths: [templateConfig.basePath]),
extensions: [filterExtension, stencilSwiftKitExtension],
templateClass: SwagGenStencilTemplate.self)
}

public enum Clean: String {
Expand Down
34 changes: 34 additions & 0 deletions Sources/SwagGenKit/SwagGenStencilTemplate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// SwagGenStencilTemplate.swift
// SwagGenKit
//
// Created by Yonas Kolb on 20/2/19.
//

import Foundation
import Stencil

open class SwagGenStencilTemplate: Template {

let replacementString = "akdjh4rhjdfgkv4nvdfdfg"

public required init(templateString: String, environment: Environment? = nil, name: String? = nil) {
let templateStringWithMarkedNewlines = templateString
.replacingOccurrences(of: "\n([ \t]*)\n", with: "\n$1\(replacementString)\n", options: .regularExpression)
.replacingOccurrences(of: "\n([ \t]*)\n", with: "\n$1\(replacementString)\n", options: .regularExpression)
super.init(templateString: templateStringWithMarkedNewlines, environment: environment, name: name)
}

// swiftlint:disable:next discouraged_optional_collection
override open func render(_ dictionary: [String: Any]? = nil) throws -> String {
return try removeExtraLines(from: super.render(dictionary))
}

// Workaround until Stencil fixes https://github.com/stencilproject/Stencil/issues/22
private func removeExtraLines(from string: String) -> String {
return string
.replacingOccurrences(of: "\\n([ \\t]*\\n)+", with: "\n", options: .regularExpression)
.replacingOccurrences(of: "\n([ \t]*)\(replacementString)\n", with: "\n\n", options: .regularExpression)
.replacingOccurrences(of: "\n([ \t]*)\(replacementString)\n", with: "\n\n", options: .regularExpression)
}
}
1 change: 1 addition & 0 deletions Specs/Petstore/generated/Swift/Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

github "Alamofire/Alamofire" ~> 4.7.2
github "antitypical/Result" ~> 4.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ struct RequestBehaviourGroup {
}
}


//MARK: Type erased Requests and Responses

public typealias AnyResponse = APIResponse<AnyResponseValue>
Expand Down
1 change: 1 addition & 0 deletions Specs/PetstoreTest/generated/Swift/Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

github "Alamofire/Alamofire" ~> 4.7.2
github "antitypical/Result" ~> 4.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ struct RequestBehaviourGroup {
}
}


//MARK: Type erased Requests and Responses

public typealias AnyResponse = APIResponse<AnyResponseValue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extension PetstoreTest.Fake {
假端點
偽のエンドポイント
가짜 엔드 포인트
*/
public enum TestEndpointParameters {

Expand Down
1 change: 1 addition & 0 deletions Specs/Rocket/generated/Swift/Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

github "Alamofire/Alamofire" ~> 4.7.2
github "antitypical/Result" ~> 4.0.0
1 change: 0 additions & 1 deletion Specs/Rocket/generated/Swift/Rocket.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Pod::Spec.new do |s|
s.authors = 'Yonas Kolb'
s.summary = 'An Orchestration Layer that takes ISL services and packages them in a more targeted way for front-end applications.
This in turn makes client integration easier and reduces the complexity and size of front-end applications.
Rocket is also customisable - allowing UI engineers to ‘remix’ the existing back-end services into something that
best suits the application they are developing.
'
Expand Down
1 change: 0 additions & 1 deletion Specs/Rocket/generated/Swift/Sources/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Foundation

/** An Orchestration Layer that takes ISL services and packages them in a more targeted way for front-end applications.
This in turn makes client integration easier and reduces the complexity and size of front-end applications.
Rocket is also customisable - allowing UI engineers to ‘remix’ the existing back-end services into something that
best suits the application they are developing.
*/
Expand Down
5 changes: 0 additions & 5 deletions Specs/Rocket/generated/Swift/Sources/Enums/FeatureFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
//

/** The set of opt in feature flags which cause breaking changes to responses.
While Rocket APIs look to avoid breaking changes under the active major version, the formats of responses
may need to evolve over this time.
These feature flags allow clients to select which response formats they expect and avoid breaking
clients as these formats evolve under the current major version.
### Flags
- `all` - Enable all flags. Useful for testing. _Don't use in production_.
- `idp` - Dynamic item detail pages with schedulable rows.
- `ldp` - Dynamic list detail pages with schedulable rows.
See the `feature-flags.md` for available flag details.
*/
public enum FeatureFlags: String, Codable {
Expand Down
3 changes: 0 additions & 3 deletions Specs/Rocket/generated/Swift/Sources/Models/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class Account: APIModel {
public var primaryProfileId: String

/** The active subscription code for an account.
The value of this should be passed to any endpoints accepting a `sub` query parameter.
*/
public var subscriptionCode: String
Expand All @@ -49,9 +48,7 @@ The value of this should be passed to any endpoints accepting a `sub` query para
/** The classification rating defining the minimum rating level a user should be
forced to enter the account pin code for playback. Anything at this rating
level or above will require the pin for playback.
e.g. AUOFLC-MA15+
If you want to disable this guard pass an empty string or `null`.
*/
public var minRatingPlaybackGuard: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,27 @@ public class AccountDevices: APIModel {

/** The maximum number of playback devices that can be registered
under an account at a single time.
If there is no maximum defined this value will be `-1`.
*/
public var maxRegistered: Int

/** Defines the start and end date of the current deregistration window along with calculated limits.
If undefined then there are no deregistration limits for a period.
For example given a deregistration period of 30 days, this sliding window will start on the
oldest deregistration of the last 30 days, and end 30 days from that deregistration date.
In this window there is a limit on how many devices can be deregistered in 30 days.
If exceeded then no more devices can be deregistered unless the oldest deregistration drops
off the 30 day window.
*/
public var deregistrationWindow: DeviceRegistrationWindow?

/** Defines the start and end date of the current registration window along with calculated limits.
If undefined then there are no registration limits for a period.
For example given a registration period of 30 days, this sliding window will start on the
oldest registration of the last 30 days, and end 30 days from that registration date.
In this window there is a limit on how many devices can be registered in 30 days.
If exceeded then no more devices can be registered unless one is deregistered or the
oldest registration drops off the 30 day window.
Deregistration also has potential limits which may prevent a device being deregistered.
In this case the user must wait until the oldest deregistered device is more than 30
days old.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class AccountTokenRequest: APIModel {
along with the token(s). This is only really intended for web based clients which
need to pass the cookies to a server to render a page based on the users
content filters, e.g subscription code.
If type `Session` the cookie will be session based.
If type `Persistent` the cookie will have a medium term lifespan.
If undefined no cookies will be set.
Expand All @@ -55,21 +54,18 @@ For each scope listed an Account and Profile token of that scope will be returne
along with the token(s). This is only really intended for web based clients which
need to pass the cookies to a server to render a page based on the users
content filters, e.g subscription code.
If type `Session` the cookie will be session based.
If type `Persistent` the cookie will have a medium term lifespan.
If undefined no cookies will be set.
*/
public var cookieType: CookieType?

/** The password associated with the account.
Either a pin or password should be supplied. If both are supplied the password will take precedence.
*/
public var password: String?

/** The pin associated with the account.
Either a pin or password should be supplied. If both are supplied the password will take precedence.
*/
public var pin: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public class AccountUpdateRequest: APIModel {
/** The classification rating defining the minimum rating level a user should be
forced to enter the account pin code for playback. Anything at this rating
level or above will require the pin for playback.
e.g. AUOFLC-MA15+
If you want to disable this guard pass an empty string or `null`.
*/
public var minRatingPlaybackGuard: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ public class DeviceRegistrationWindow: APIModel {
public var remaining: Int

/** The start date of the current period.
This is based on the earliest device de/registrations in the past N days, where
N is defined by `periodDays`.
If no device has been de/registered then start date will be from the current date.
*/
public var startDate: DateTime

/** The end date of the current period.
This is based on the value of `startDate` plus the number of days defined by `periodDays`.
*/
public var endDate: DateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class ItemDetail: ItemSummary {
public var credits: [Credit]?

/** An ordered list of custom name-value-pair item metadata.
Usually displayed on an item detail page.
*/
public var customMetadata: [ItemCustomMetadata]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Foundation
public class NavContent: APIModel {

/** The image type to target when rendering items of the list.
e.g wallpaper, poster, hero3x1, logo.
*/
public var imageType: String?
Expand Down
1 change: 0 additions & 1 deletion Specs/Rocket/generated/Swift/Sources/Models/NavEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class NavEntry: APIModel {
public var customFields: [String: Any]?

/** True if this is a featured menu item.
Featured menu items may have a more prominent presentation than others in the navigation.
*/
public var featured: Bool?
Expand Down
4 changes: 0 additions & 4 deletions Specs/Rocket/generated/Swift/Sources/Models/Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@ public class Page: PageSummary {
public var customFields: [String: Any]?

/** When the page represents the detail of an item this property will contain the item detail.
For clients consuming an item detail page, any page row entry of type `ItemDetailEntry`
should look to obtain its data from the contents of this property.
*Note that you have to be using feature flag `idp` to enable this
on item detail pages. See `feature-flags.md` for further details.*
*/
public var item: ItemDetail?

/** When the page represents the detail of a List this property will contain the list in question.
For clients consuming a list detail page, any page row entry of type `ListDetailEntry`
should look to obtain its data from the contents of this property.
*Note that you have to be using feature flag `ldp` to enable this
on list detail pages. See `feature-flags.md` for further details.*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class PageEntry: APIModel {
public var customFields: [String: Any]?

/** The images for the page entry if any.
For example the images of an `ImageEntry`.
*/
public var images: [String: URL]?
Expand Down
2 changes: 0 additions & 2 deletions Specs/Rocket/generated/Swift/Sources/Models/PageSummary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ public class PageSummary: APIModel {
public var template: String

/** True if this page is static and doesn't have any dynamic content to load.
Static pages don't need to go back to the page endpoint to load page content
instead the page summary loaded with the sitemap should be enough to determine
the page template type and render based on this.
*/
public var isStatic: Bool

/** True if this page is a system page type.
**DEPRECATED** This property doesn't have any real use in client applications
anymore so shouldn't be used. It especially shouldn't be used to determine if
a page is static or not. Use the `isStatic` property instead.
Expand Down
Loading

0 comments on commit c79543e

Please sign in to comment.