mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-03-30 11:18:38 -07:00
53 lines
1.3 KiB
Swift
53 lines
1.3 KiB
Swift
//
|
|
// OpenAPITests.swift
|
|
// JSONAPIOpenAPITests
|
|
//
|
|
// Created by Mathew Polzin on 1/25/19.
|
|
//
|
|
|
|
import XCTest
|
|
import JSONAPI
|
|
import JSONAPIOpenAPI
|
|
|
|
class OpenAPITests: XCTestCase {
|
|
|
|
func test_placeholder() {
|
|
|
|
let schemaInfo = OpenAPISchema.Info(title: "Cool API", version: "0.1.0")
|
|
|
|
let personResponse = OpenAPIResponse(description: "Successfully created a Person",
|
|
content: [
|
|
.json: .init(schema: .init(JSONReference.node(.init(type: \.schemas, selector: "person"))))
|
|
])
|
|
|
|
let schemaPaths: [OpenAPISchema.PathComponents: OpenAPIPathItem] = [
|
|
.init(["api","people"]):
|
|
.operations(
|
|
.init(parameters: [],
|
|
post: OpenAPIPathItem.PathProperties.Operation(
|
|
summary: "",
|
|
operationId: "createPerson",
|
|
parameters: [],
|
|
responses: [
|
|
.status(code: 200): .init(personResponse)
|
|
]
|
|
)
|
|
)
|
|
)
|
|
]
|
|
|
|
let schemaComponents = OpenAPIComponents(schemas: ["person": .reference(.file("filename"))],
|
|
parameters: [:])
|
|
|
|
let openAPISchema = OpenAPISchema(info: schemaInfo,
|
|
paths: schemaPaths,
|
|
components: schemaComponents)
|
|
|
|
let encoder = JSONEncoder()
|
|
encoder.outputFormatting = .prettyPrinted
|
|
|
|
print(String(data: try! encoder.encode(openAPISchema), encoding: .utf8)!)
|
|
}
|
|
|
|
}
|