Skip to content

Commit

Permalink
4.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed May 5, 2024
1 parent 5dd98a1 commit 0bd2b81
Show file tree
Hide file tree
Showing 29 changed files with 736 additions and 660 deletions.
2 changes: 1 addition & 1 deletion Example/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.70.0"),
.package(path: "../")
.package(path: "../"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion Example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Edit Scheme -> Options -> Use custom working directory

and open:
- Swagger: `http://127.0.0.1:8080/swagger/` (don't miss the trailing `/`)
- Stoplight: `http://127.0.0.1:8080/doc`
- Stoplight: `http://127.0.0.1:8080/stoplight`

## Requirements 📝

Expand Down
57 changes: 30 additions & 27 deletions Example/Sources/App/Controllers/OpenAPIController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,35 @@ struct OpenAPIController: RouteCollection {

// MARK: Internal

func boot(routes: RoutesBuilder) throws {

// generate OpenAPI documentation
routes.get("swagger", "swagger.json") { req in
req.application.routes.openAPI(
info: InfoObject(
title: "Swagger Petstore - OpenAPI 3.0",
description: "This is a sample Pet Store Server based on the OpenAPI 3.0.1 specification. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\nSome useful links:\n- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)",
termsOfService: URL(string: "http://swagger.io/terms/"),
contact: ContactObject(
email: "[email protected]"
),
license: LicenseObject(
name: "Apache 2.0",
url: URL(string: "http://www.apache.org/licenses/LICENSE-2.0.html")
),
version: Version(1, 0, 17)
),
externalDocs: ExternalDocumentationObject(
description: "Find out more about Swagger",
url: URL(string: "http://swagger.io")!
)
)
}
.excludeFromOpenAPI()
func boot(routes: RoutesBuilder) throws {

routes.stoplightDocumentation("docs", openAPIPath: "/swagger/swagger.json")
}
// generate OpenAPI documentation
routes.get("swagger", "swagger.json") { req in
req.application.routes.openAPI(
info: InfoObject(
title: "Swagger Petstore - OpenAPI 3.0",
description: "This is a sample Pet Store Server based on the OpenAPI 3.0.1 specification.",
termsOfService: URL(string: "http://swagger.io/terms/"),
contact: ContactObject(
email: "[email protected]"
),
license: LicenseObject(
name: "Apache 2.0",
url: URL(string: "http://www.apache.org/licenses/LICENSE-2.0.html")
),
version: Version(1, 0, 17)
),
externalDocs: ExternalDocumentationObject(
description: "Find out more about Swagger",
url: URL(string: "http://swagger.io")!
)
)
}
.excludeFromOpenAPI()

routes.stoplightDocumentation(
"stoplight",
openAPIPath: "/swagger/swagger.json"
)
}
}
2 changes: 1 addition & 1 deletion Example/Sources/App/Controllers/UserController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct UserController: RouteCollection {
.openAPI(
summary: "Logs out current logged in user session"
)
.response(description: "successful operation")
.response(description: "successful operation")

routes.group(":username") { routes in
routes.get { _ in
Expand Down
8 changes: 4 additions & 4 deletions Example/Sources/App/Models/Address.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import VaporToOpenAPI
@OpenAPIDescriptable
public struct Address: Codable, WithExample {

/// Street address
/// Street address
public var street: String?
/// City name
/// City name
public var city: String?
/// State name
/// State name
public var state: String?
/// Zip code
/// Zip code
public var zip: String?

public static let example = Address(
Expand Down
6 changes: 3 additions & 3 deletions Example/Sources/App/Models/ApiResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import VaporToOpenAPI
@OpenAPIDescriptable
public struct ApiResponse: Codable, Content, WithExample {

/// Response code
/// Response code
public var code: Int32?
/// Response type
/// Response type
public var type: String?
/// Response message
/// Response message
public var message: String?

public static var example = ApiResponse(
Expand Down
4 changes: 2 additions & 2 deletions Example/Sources/App/Models/Category.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import VaporToOpenAPI
/// Category
public struct Category: Codable, Identifiable, WithExample {

/// Unique identifier for the category
/// Unique identifier for the category
public var id: Int
/// Category name
/// Category name
public var name: String?

public static let example = Category(id: 1, name: "Dogs")
Expand Down
6 changes: 3 additions & 3 deletions Example/Sources/App/Models/Customer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import VaporToOpenAPI
/// Customer
public struct Customer: Codable, Identifiable, WithExample {

/// Customer identifier
/// Customer identifier
public var id: Int
/// Customer username
/// Customer username
public var username: String
/// Customer addresses list
/// Customer addresses list
public var address: [Address]

public static let example = Customer(
Expand Down
4 changes: 2 additions & 2 deletions Example/Sources/App/Models/LoginQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import VaporToOpenAPI
/// Login query
public struct LoginQuery: Codable, WithExample {

/// Username
/// Username
public var username: String?
/// Password
/// Password
public var password: String?

public static let example = LoginQuery(username: "Dan", password: "12345")
Expand Down
12 changes: 6 additions & 6 deletions Example/Sources/App/Models/Order.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import VaporToOpenAPI
/// Order
public struct Order: Codable, Equatable, Content, WithExample {

/// Unique identifier for the order
/// Unique identifier for the order
public var id: Int
/// Pet sold to
/// Pet sold to
public var petId: Int
/// Quantity sold
/// Quantity sold
public var quantity: Int32?
/// Estimated ship date
/// Estimated ship date
public var shipDate: Date?
/// Order Status
/// Order Status
public var status: OrderStatus
/// Is the order complete?
/// Is the order complete?
public var complete: Bool?

public static let example = Order(
Expand Down
4 changes: 2 additions & 2 deletions Example/Sources/App/Models/UpdatePetQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import VaporToOpenAPI
@OpenAPIDescriptable
public struct UpdatePetQuery: Codable, Equatable, WithExample {

/// Updated name of the pet
/// Updated name of the pet
public var name: String?
/// Updated status of the pet
/// Updated status of the pet
public var status: PetStatus?

public static var example = UpdatePetQuery(name: "Persey", status: .available)
Expand Down
2 changes: 1 addition & 1 deletion Example/Sources/App/Models/UploadImageQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import VaporToOpenAPI
@OpenAPIDescriptable
public struct UploadImageQuery: Codable, Equatable, WithExample {

/// Additional data to pass to server
/// Additional data to pass to server
public var additionalMetadata: String?

public static let example = UploadImageQuery(additionalMetadata: "png")
Expand Down
16 changes: 8 additions & 8 deletions Example/Sources/App/Models/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import VaporToOpenAPI
/// User model
public struct User: Codable, Content, Identifiable, WithExample {

/// Unique identifier for the user
/// Unique identifier for the user
public var id: Int
/// The name that needs to be fetched. Use user1 for testing.
/// The name that needs to be fetched. Use user1 for testing.
public var username: String
/// User's first name
/// User's first name
public var firstName: String?
/// User's last name
/// User's last name
public var lastName: String?
/// User's email
/// User's email
public var email: String?
/// User's password
/// User's password
public var password: String?
/// User's phone number
/// User's phone number
public var phone: String?
/// User Status
/// User Status
public var userStatus: Int32?

public static let example = User(
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/dankinsoid/SwiftOpenAPI.git", from: "2.19.5"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "0.10.3")
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "0.10.3"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/VaporToOpenAPI.git", from: "4.6.2")
.package(url: "https://github.com/dankinsoid/VaporToOpenAPI.git", from: "4.6.3")
],
targets: [
.target(name: "SomeProject", dependencies: ["VaporToOpenAPI"])
Expand Down
98 changes: 0 additions & 98 deletions Sources/VaporToOpenAPI/Elements.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/VaporToOpenAPI/Links.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public struct Link: Hashable {
self.location = location
}

@available(*, deprecated, message: "Use init with string instead")
@available(*, deprecated, message: "Use init with string instead")
public init<T: WithExample>(_ name: WritableKeyPath<T, some DetectableType>, in location: Location) {
self.init(T.codingKey(for: name), in: location)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/VaporToOpenAPI/OpenAPIValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public struct OpenAPIParameters {
guard let params = try? type.value.parameters(in: .query, schemas: &schemas) else {
continue
}
params.compactMap(\.object).forEach {
properties[$0.name] = $0
for param in params.compactMap(\.object) {
properties[param.name] = param
}
}
return OpenAPIParameters(value: .parameters(properties))
Expand Down
12 changes: 6 additions & 6 deletions Sources/VaporToOpenAPI/Route++.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ extension Route {
.set(\.links, to: links)
.set(\.tags, to: newTags)
.set(\.openAPIMethod, to: method)
.openAPI(custom: \.specificationExtensions) {
$0 = SpecificationExtensions(fields: extensions.fields.merging($0?.fields ?? [:]) { new, _ in new })
if $0?.fields.isEmpty == true {
$0 = nil
}
}
.openAPI(custom: \.specificationExtensions) {
$0 = SpecificationExtensions(fields: extensions.fields.merging($0?.fields ?? [:]) { new, _ in new })
if $0?.fields.isEmpty == true {
$0 = nil
}
}
._response(
spec: spec,
statusCode: statusCode,
Expand Down
Loading

0 comments on commit 0bd2b81

Please sign in to comment.