Skip to content

Commit

Permalink
3.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Dec 1, 2023
1 parent be76b18 commit 92cdfd7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 55 deletions.
16 changes: 12 additions & 4 deletions Package.swift
Expand Up @@ -13,14 +13,15 @@ let package = Package(
.watchOS(.v6),
],
products: [
.library(name: "SwiftOpenAPI", targets: ["SwiftOpenAPI"]),
.library(name: "SwiftOpenAPI", targets: ["SwiftOpenAPI", "SwiftOpenAPIDescriptable"]),
],
dependencies: [
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "0.10.3"),
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.2")
],
targets: [
.target(name: "SwiftOpenAPI", dependencies: ["SwiftOpenAPIMacros"]),
.target(name: "SwiftOpenAPI", dependencies: []),
.target(name: "SwiftOpenAPIDescriptable", dependencies: ["SwiftOpenAPI", "SwiftOpenAPIMacros"]),
.macro(
name: "SwiftOpenAPIMacros",
dependencies: [
Expand All @@ -32,10 +33,17 @@ let package = Package(
name: "SwiftOpenAPITests",
dependencies: [
"SwiftOpenAPI",
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "CustomDump", package: "swift-custom-dump"),
],
exclude: ["Mocks/"]
),
.testTarget(
name: "SwiftOpenAPIMacroTests",
dependencies: [
"SwiftOpenAPIDescriptable",
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
.product(name: "CustomDump", package: "swift-custom-dump"),
]
),
]
)
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -13,7 +13,7 @@ The main accent in the library is on simplifying the syntax: the active use of l
## Short example
```swift
try OpenAPIObject(
openapi: "3.0.11",
openapi: "3.0.12",
info: InfoObject(
title: "Example API",
version: "0.1.0"
Expand Down Expand Up @@ -163,7 +163,7 @@ import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/SwiftOpenAPI.git", from: "3.0.11")
.package(url: "https://github.com/dankinsoid/SwiftOpenAPI.git", from: "3.0.12")
],
targets: [
.target(name: "SomeProject", dependencies: ["SwiftOpenAPI"])
Expand Down
48 changes: 0 additions & 48 deletions Sources/SwiftOpenAPI/OpenAPIDescriptable.swift
@@ -1,5 +1,4 @@
import Foundation
import SwiftOpenAPIMacros

public protocol OpenAPIDescriptable {

Expand All @@ -12,50 +11,3 @@ public extension OpenAPIDescriptable {
nil
}
}

/// `OpenAPIAutoDescriptable`: An automatic implementation macro for the `OpenAPIDescriptable` protocol.
///
/// This macro facilitates the automatic implementation of the `OpenAPIDescriptable` protocol
/// for any Swift type, utilizing both standard comments (`//`) and documentation comments (`///`)
/// for the type and its stored properties. It's particularly useful for generating comprehensive
/// OpenAPI documentation directly from your source code.
///
/// - Parameters:
/// - codingKeys: The Bool value indicating whether to use a `CodingKeys` enum for properties names.
/// When `true`, the property names are extracted from the `CodingKeys` enum, only stored properties are collected.
/// When `false`, the property names are used directly, all properties are collected including computed, lazy and with attributes.
/// Defaults to `true`.
/// - docCommentsOnly: The Bool value indicating whether to use only documentation comments (`///` and `/**`). Defaults to `false`.
/// - includeAttributes: The Bool value indicating whether to include properties with attributes. Defaults to `false`. The property is ignored when `codingKeys` is `false`.
///
/// Features:
/// - Automatically extracts and synthesizes descriptions from comments on types and stored properties.
/// - Simplifies the process of conforming to `OpenAPIDescriptable` by generating necessary implementation details.
///
/// - Warning: By default this macro does not process properties with attributes, as it's currently not feasible
/// to distinguish between stored and computed properties in such cases.
/// You can override this behavior by setting the `includeAttributes` parameter to `true` or `codingKeys` to `false`.
///
/// Example:
/// ```swift
/// /// Description of MyType.
/// @OpenAPIAutoDescriptable
/// struct MyType: Codable {
///
/// /// Description of myProperty.
/// var myProperty: String
/// }
/// ```
///
/// The `OpenAPIAutoDescriptable` significantly reduces the need for boilerplate code in
/// API documentation, streamlining the process of maintaining up-to-date and accurate OpenAPI docs.
@attached(member, conformances: OpenAPIDescriptable, names: arbitrary)
@attached(extension, conformances: OpenAPIDescriptable, names: arbitrary)
public macro OpenAPIAutoDescriptable(
codingKeys: Bool = true,
docCommentsOnly: Bool = false,
includeAttributes: Bool = false
) = #externalMacro(
module: "SwiftOpenAPIMacros",
type: "OpenAPIDescriptionMacro"
)
50 changes: 50 additions & 0 deletions Sources/SwiftOpenAPIDescriptable/File.swift
@@ -0,0 +1,50 @@
import Foundation
import SwiftOpenAPI
import SwiftOpenAPIMacros

/// `OpenAPIAutoDescriptable`: An automatic implementation macro for the `OpenAPIDescriptable` protocol.
///
/// This macro facilitates the automatic implementation of the `OpenAPIDescriptable` protocol
/// for any Swift type, utilizing both standard comments (`//`) and documentation comments (`///`)
/// for the type and its stored properties. It's particularly useful for generating comprehensive
/// OpenAPI documentation directly from your source code.
///
/// - Parameters:
/// - codingKeys: The Bool value indicating whether to use a `CodingKeys` enum for properties names.
/// When `true`, the property names are extracted from the `CodingKeys` enum, only stored properties are collected.
/// When `false`, the property names are used directly, all properties are collected including computed, lazy and with attributes.
/// Defaults to `true`.
/// - docCommentsOnly: The Bool value indicating whether to use only documentation comments (`///` and `/**`). Defaults to `false`.
/// - includeAttributes: The Bool value indicating whether to include properties with attributes. Defaults to `false`. The property is ignored when `codingKeys` is `false`.
///
/// Features:
/// - Automatically extracts and synthesizes descriptions from comments on types and stored properties.
/// - Simplifies the process of conforming to `OpenAPIDescriptable` by generating necessary implementation details.
///
/// - Warning: By default this macro does not process properties with attributes, as it's currently not feasible
/// to distinguish between stored and computed properties in such cases.
/// You can override this behavior by setting the `includeAttributes` parameter to `true` or `codingKeys` to `false`.
///
/// Example:
/// ```swift
/// /// Description of MyType.
/// @OpenAPIAutoDescriptable
/// struct MyType: Codable {
///
/// /// Description of myProperty.
/// var myProperty: String
/// }
/// ```
///
/// The `OpenAPIAutoDescriptable` significantly reduces the need for boilerplate code in
/// API documentation, streamlining the process of maintaining up-to-date and accurate OpenAPI docs.
@attached(member, conformances: OpenAPIDescriptable, names: arbitrary)
@attached(extension, conformances: OpenAPIDescriptable, names: arbitrary)
public macro OpenAPIAutoDescriptable(
codingKeys: Bool = true,
docCommentsOnly: Bool = false,
includeAttributes: Bool = false
) = #externalMacro(
module: "SwiftOpenAPIMacros",
type: "OpenAPIDescriptionMacro"
)
Expand Up @@ -4,7 +4,8 @@ import SwiftSyntaxMacros
import SwiftSyntaxMacrosTestSupport
import XCTest
import SwiftOpenAPIMacros
@testable import SwiftOpenAPI
import SwiftOpenAPI
@testable import SwiftOpenAPIDescriptable

let testMacros: [String: Macro.Type] = [
"OpenAPIDescriptionMacro": OpenAPIDescriptionMacro.self
Expand Down

0 comments on commit 92cdfd7

Please sign in to comment.