-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with nested array of encodable objects #30
Comments
You have to register all objects. In your case let nested1 = NestedObject(version: "1.0", value: "Nested Object 1")
let test = TestObject(nested:nested1, nestedObjects: [nested1], nestedValues: ["Str1", "Str2"])
let openAPIBuilder = OpenAPIBuilder(
title: "Tasker server API",
version: "1.0.0",
description: "This is a sample server for task server application."
)
.add([
APIObject(object: test),
APIObject(object: nested1) // <- add also nested
]) Nested objects in |
I tried to register NestedObject as you suggested. But it still does not contain NestedObject. let nested = NestedObject(version: "1.0", value: "Nested Object 1")
let test = TestObject(nestedObjects: [nested])
let openAPIBuilder = OpenAPIBuilder(
title: "Tasker server API",
version: "1.0.0",
description: "This is a sample server for task server application."
)
.add([
APIObject(object: test),
APIObject(object: nested)
])
.add(APIController(name: "Test",
description: "Controller where we can manage test",
actions: [
APIAction(method: .get,
route: "/test",
summary: "Summary",
description: "Description",
responses: [
APIResponse(code: "200",
description: "Ok",
type: .object(TestObject.self))
],
authorization: false)
])
)
let openAPIDocument = openAPIBuilder.built()
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let jsonData = try! encoder.encode(openAPIDocument)
let jsonString = String(bytes: jsonData, encoding: .utf8) JSON: |
Yeah, I updated Swiftgger and now it works in most cases. struct NestedObject: Content {
var value: String
}
struct TestObject: Content {
var nestedObjects: [NestedObject?] // --> This line is changed in comparison to previous examples
} let nested = NestedObject(value: "Nested Object 1")
let test = TestObject(nestedObjects: [nested])
let openAPIBuilder = OpenAPIBuilder(
title: "Tasker server API",
version: "1.0.0",
description: "This is a sample server for task server application."
)
.add([
APIObject(object: nested),
APIObject(object: test)
])
.add(APIController(name: "Test",
description: "Controller where we can manage test",
actions: [
APIAction(method: .get,
route: "/test",
summary: "Summary",
description: "Description",
responses: [
APIResponse(code: "200",
description: "Ok",
type: .object(TestObject.self))
],
authorization: false)
])
)
let openAPIDocument = openAPIBuilder.built()
let data = try JSONEncoder().encode(openAPIDocument)
let serializedData = String(data: data, encoding: .utf8)!
return serializedData |
Hello!
Could you please to take a look at the following issue:
I have found that a collection of encodable objects is missing under Example Values. See image below:
And here is a code snippet to reproduce the issue:
The text was updated successfully, but these errors were encountered: