|
1 | 1 | import XCTest |
| 2 | +import Foundation |
| 3 | +import OpenAPI |
| 4 | +import SymbolKit |
| 5 | +import Yams |
2 | 6 | @testable import OpenAPItoSymbolGraph |
3 | 7 | @testable import OpenAPI |
4 | 8 | @testable import DocC |
@@ -132,32 +136,47 @@ final class PetstoreTests: XCTestCase { |
132 | 136 | type: string |
133 | 137 | """ |
134 | 138 |
|
135 | | - // Create parser and converter |
136 | 139 | let parser = YAMLParser() |
137 | | - let converter = OpenAPItoSymbolGraph() |
| 140 | + let converter = OpenAPIDocCConverter() |
138 | 141 |
|
139 | | - // Parse and convert |
140 | 142 | let document = try parser.parse(yamlString) |
141 | | - let markdown = try converter.convert(document) |
| 143 | + let symbolGraph = converter.convert(document) |
142 | 144 |
|
143 | | - // Verify markdown content |
144 | | - XCTAssertTrue(markdown.contains("# Swagger Petstore")) |
145 | | - XCTAssertTrue(markdown.contains("## Overview")) |
146 | | - XCTAssertTrue(markdown.contains("3 Endpoints")) |
147 | | - XCTAssertTrue(markdown.contains("4 Schemas")) |
| 145 | + // MARK: - SymbolGraph Assertions |
| 146 | + XCTAssertEqual(symbolGraph.module.name, "Swagger Petstore") |
| 147 | + |
| 148 | + // Count specific symbol kinds |
| 149 | + let operationSymbols = symbolGraph.symbols.values.filter { $0.kind.identifier == .method } |
| 150 | + // Refined schema filter: only count structs with 1 path component (SchemaName) |
| 151 | + let topLevelSchemaSymbols = symbolGraph.symbols.values.filter { $0.kind.identifier == .struct && $0.pathComponents.count == 1 } |
| 152 | + |
| 153 | + XCTAssertEqual(operationSymbols.count, 3, "Incorrect number of operation symbols") |
| 154 | + XCTAssertEqual(topLevelSchemaSymbols.count, 4, "Incorrect number of top-level schema symbols") // Expect 4: Pet, NewPet, Pets, Error |
| 155 | + |
| 156 | + // Check specific symbols |
| 157 | + let listPetsOpIdentifier1 = "operation:listPets" |
| 158 | + let listPetsOpIdentifier2 = "operation:get:/pets" |
| 159 | + let listPetsOp = symbolGraph.symbols.values.first { $0.identifier.precise == listPetsOpIdentifier1 || $0.identifier.precise == listPetsOpIdentifier2 } |
| 160 | + XCTAssertNotNil(listPetsOp, "List pets operation missing") |
148 | 161 |
|
149 | | - // Verify specific endpoint |
150 | | - XCTAssertTrue(markdown.contains("## GET /pets")) |
151 | | - XCTAssertTrue(markdown.contains("Returns all pets from the system that the user has access to")) |
| 162 | + XCTAssertNotNil(symbolGraph.symbols.values.first { $0.identifier.precise.hasSuffix("schema:Pet") }, "Pet schema missing") |
| 163 | + XCTAssertNotNil(symbolGraph.symbols.values.first { $0.identifier.precise.hasSuffix("schema:NewPet") }, "NewPet schema missing") |
| 164 | + XCTAssertNotNil(symbolGraph.symbols.values.first { $0.identifier.precise.hasSuffix("schema:Pets") }, "Pets schema missing") |
| 165 | + XCTAssertNotNil(symbolGraph.symbols.values.first { $0.identifier.precise.hasSuffix("schema:Error") }, "Error schema missing") |
152 | 166 |
|
153 | | - // Verify parameters |
154 | | - XCTAssertTrue(markdown.contains("limit")) |
155 | | - XCTAssertTrue(markdown.contains("How many items to return at one time (max 100)")) |
| 167 | + // Check specific doc comments |
| 168 | + XCTAssertEqual(listPetsOp?.docComment?.lines.first?.text, "Returns all pets from the system that the user has access to", "List pets description mismatch") |
156 | 169 |
|
157 | | - // Verify schemas |
158 | | - XCTAssertTrue(markdown.contains("### Pet")) |
159 | | - XCTAssertTrue(markdown.contains("### NewPet")) |
160 | | - XCTAssertTrue(markdown.contains("### Pets")) |
161 | | - XCTAssertTrue(markdown.contains("### Error")) |
| 170 | + // Check a relationship (Example: operation -> path) |
| 171 | + let pathPetsSymbol = symbolGraph.symbols.values.first { $0.identifier.precise == "path:/pets" } |
| 172 | + XCTAssertNotNil(pathPetsSymbol, "Path symbol /pets missing") |
| 173 | + |
| 174 | + // Find relationship with OPERATION as source and PATH as target |
| 175 | + let listPetsRelationship = symbolGraph.relationships.first { |
| 176 | + $0.source == listPetsOp?.identifier.precise && // Source is Operation |
| 177 | + $0.target == pathPetsSymbol?.identifier.precise && // Target is Path |
| 178 | + $0.kind == SymbolKit.SymbolGraph.Relationship.Kind.memberOf |
| 179 | + } |
| 180 | + XCTAssertNotNil(listPetsRelationship, "Relationship from listPets operation to /pets path missing") |
162 | 181 | } |
163 | 182 | } |
0 commit comments