Comments (4)
You have to register all objects. In your case NestedObject
and TestObject
.
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 OpenAPI
definition are added as a reference (name of the type, not real objects).
from swiftgger.
I tried to register NestedObject as you suggested. But it still does not contain NestedObject.
Here is the code I tried:
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:
json.txt
from swiftgger.
I've copy&paste your code and I've different result.
Are you sure that you are using latest Swiftgger version (2.0.0-rc1)?
from swiftgger.
Yeah, I updated Swiftgger and now it works in most cases.
However i am seeing the same issue with array of nested optional objects ( [NestedObject?] ).
Could you please to take a look the issue with the following code?
And confirm whether this works. Or maybe I am doing something wrong again?
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
from swiftgger.
Related Issues (19)
- Compile error: "Reference to member 'value' cannot be resolved without a contextual type" HOT 1
- Numbers(e.g. Integers or Floats) with Quotes/Doublequotes in examples
- Authorization header HOT 2
- Place OpenAPI on my server HOT 6
- Classes and Struct to APIObject HOT 5
- Parameter error: "😱 Could not render this component, see the console." HOT 8
- CamelCase to snake_case HOT 6
- Incorrect example value under Request Body HOT 6
- New version of Swiftgger built with swift 5.2 HOT 2
- Swiftgger upgrade issue
- Issue with plain text in 'Example Value' field HOT 1
- Dictionary object HOT 3
- Update APIResponse type
- APIObject Decimal and [[[T]]]
- OpenAPISecurityScheme: APIAuthorizationType produces a foreign "in" parameterLocation
- Custom Schema name HOT 9
- Nested Objects HOT 1
- Make OpenAPIDocument Decodable also
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftgger.