Skip to content

Commit

Permalink
[swift5] Define models and Configuration classes under namespace
Browse files Browse the repository at this point in the history
When swiftUseApiNamespace is set, API classes get defined under the
projectName namespace. This does the same for models and the
Configuration class. Plus adding a deprecation warning when using the
un-namespaced variants.
  • Loading branch information
aymanbagabas committed May 30, 2021
1 parent b2f0033 commit 92ddcdb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@

import Foundation

{{#swiftUseApiNamespace}}
@available(*, deprecated, renamed: "{{projectName}}.Configuration")
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} typealias Configuration = {{projectName}}.Configuration

extension {{projectName}} {
{{/swiftUseApiNamespace}}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class Configuration {
// This value is used to configure the date formatter that is used to serialize dates into JSON format.
// You must set it prior to encoding any dates, and it will only be read once.
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
}
{{#swiftUseApiNamespace}}
}
{{/swiftUseApiNamespace}}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ import Foundation
#if canImport(AnyCodable)
import AnyCodable
#endif
{{#description}}

{{#swiftUseApiNamespace}}
@available(*, deprecated, renamed: "{{projectName}}.{{classname}}")
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} typealias {{classname}} = {{projectName}}.{{classname}}

extension {{projectName}} {
{{/swiftUseApiNamespace}}

{{#description}}
/** {{description}} */{{/description}}{{#isDeprecated}}
@available(*, deprecated, message: "This schema is deprecated."){{/isDeprecated}}{{#vendorExtensions.x-is-one-of-interface}}
{{> modelOneOf}}{{/vendorExtensions.x-is-one-of-interface}}{{^vendorExtensions.x-is-one-of-interface}}{{#isArray}}
{{> modelArray}}{{/isArray}}{{^isArray}}{{#isEnum}}
{{> modelEnum}}{{/isEnum}}{{^isEnum}}
{{> modelObject}}{{/isEnum}}{{/isArray}}{{/vendorExtensions.x-is-one-of-interface}}{{/model}}{{/models}}
{{#swiftUseApiNamespace}}
}
{{/swiftUseApiNamespace}}

0 comments on commit 92ddcdb

Please sign in to comment.