-
-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
When using OpenAPIParameters.all(of:...) to combine multiple query parameter types, nested schema definitions (like enums with custom openAPISchema) are referenced in parameters but not included in the OpenAPI components.schemas section, resulting in invalid OpenAPI specs with broken $ref links.
Here are some code from my project.
- Define an enum:
enum SortOption: String, Codable, CaseIterable, OpenAPIType {
case relevance
case count
static var openAPISchema: SchemaObject {
SchemaObject(
description: "Sort options for query results",
enum: allCases.map { AnyValue.string($0.rawValue) },
context: .string
)
}
}Side note: Can you elaborate how to deal with enums? I would assume the custom schema is not needed but sometimes I got error related to CodingKeys. So I added custom schema for them.
- Use this enum in a request DTO:
struct AppInfoQueryRequest: Content {
let query: String?
let sortBy: SortOption?
}- Register a route with combined query parameters:
appInfo
.get("search", use: search)
.openAPI(
summary: "Search for apps",
query: .all(of: .type(AppInfoQueryRequest.self), .type(PageRequest.self)),
response: .type(Page<AppInfoDTO>.self)
)- Generate and inspect the OpenAPI spec at
/swaggerendpoint
The generated OpenAPI spec should include the schema but this is what actually being generated:
{
"name": "sortBy",
"in": "query",
"schema": {
"$ref": "#/components/schemas/SortOption" // Correctly references the schema
}
}{
"components": {
"schemas": {
// but SortOption is missing!
}
}
}Metadata
Metadata
Assignees
Labels
No labels