Skip to content
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

[Cleanup] Make Config's namingStrategy and accessModifier params consistent #713

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/_OpenAPIGeneratorCore/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public struct Config: Sendable {
access: AccessModifier,
additionalImports: [String] = [],
filter: DocumentFilter? = nil,
namingStrategy: NamingStrategy = Config.defaultNamingStrategy,
namingStrategy: NamingStrategy,
nameOverrides: [String: String] = [:],
featureFlags: FeatureFlags = []
) {
Expand Down
6 changes: 5 additions & 1 deletion Tests/OpenAPIGeneratorCoreTests/Parser/Test_YamsParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ final class Test_YamsParser: Test_Core {
try YamsParser()
.parseOpenAPI(
.init(absolutePath: URL(fileURLWithPath: "/foo.yaml"), contents: Data(yaml.utf8)),
config: .init(mode: .types, access: Config.defaultAccessModifier),
config: .init(
mode: .types,
access: Config.defaultAccessModifier,
namingStrategy: Config.defaultNamingStrategy
),
diagnostics: PrintingDiagnosticCollector()
)
}
Expand Down
20 changes: 18 additions & 2 deletions Tests/OpenAPIGeneratorCoreTests/Parser/Test_validateDoc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ final class Test_validateDoc: Test_Core {
paths: [:],
components: .init(schemas: ["myImperfectSchema": schemaWithWarnings])
)
let diagnostics = try validateDoc(doc, config: .init(mode: .types, access: Config.defaultAccessModifier))
let diagnostics = try validateDoc(
doc,
config: .init(
mode: .types,
access: Config.defaultAccessModifier,
namingStrategy: Config.defaultNamingStrategy
)
)
XCTAssertEqual(diagnostics.count, 1)
}

Expand All @@ -53,7 +60,16 @@ final class Test_validateDoc: Test_Core {
],
components: .noComponents
)
XCTAssertThrowsError(try validateDoc(doc, config: .init(mode: .types, access: Config.defaultAccessModifier)))
XCTAssertThrowsError(
try validateDoc(
doc,
config: .init(
mode: .types,
access: Config.defaultAccessModifier,
namingStrategy: Config.defaultNamingStrategy
)
)
)
}

func testValidateContentTypes_validContentTypes() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class Test_isSchemaSupported: XCTestCase {

var translator: any FileTranslator {
TypesFileTranslator(
config: .init(mode: .types, access: Config.defaultAccessModifier),
config: .init(
mode: .types,
access: Config.defaultAccessModifier,
namingStrategy: Config.defaultNamingStrategy
),
diagnostics: PrintingDiagnosticCollector(),
components: .init(schemas: [
"Foo": .string, "MyObj": .object, "MyObj2": .object,
Expand Down
4 changes: 2 additions & 2 deletions Tests/OpenAPIGeneratorReferenceTests/CompatabilityTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fileprivate extension CompatibilityTest {
for mode in GeneratorMode.allCases {
group.addTask {
let generator = makeGeneratorPipeline(
config: Config(mode: mode, access: .public),
config: Config(mode: mode, access: .public, namingStrategy: .defensive),
diagnostics: diagnosticsCollector
)
return try assertNoThrowWithValue(generator.run(input))
Expand All @@ -265,7 +265,7 @@ fileprivate extension CompatibilityTest {
} else {
outputs = try GeneratorMode.allCases.map { mode in
let generator = makeGeneratorPipeline(
config: Config(mode: mode, access: .public),
config: Config(mode: mode, access: .public, namingStrategy: .defensive),
diagnostics: diagnosticsCollector
)
return try assertNoThrowWithValue(generator.run(input))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5868,7 +5868,7 @@ extension SnippetBasedReferenceTests {
func makeTypesTranslator(openAPIDocumentYAML: String) throws -> TypesFileTranslator {
let document = try YAMLDecoder().decode(OpenAPI.Document.self, from: openAPIDocumentYAML)
return TypesFileTranslator(
config: Config(mode: .types, access: .public),
config: Config(mode: .types, access: .public, namingStrategy: .defensive),
diagnostics: XCTestDiagnosticCollector(test: self),
components: document.components
)
Expand Down Expand Up @@ -5901,7 +5901,12 @@ extension SnippetBasedReferenceTests {
components: OpenAPI.Components = .noComponents
) throws -> TypesFileTranslator {
TypesFileTranslator(
config: Config(mode: .types, access: accessModifier, featureFlags: featureFlags),
config: Config(
mode: .types,
access: accessModifier,
namingStrategy: .defensive,
featureFlags: featureFlags
),
diagnostics: XCTestDiagnosticCollector(test: self, ignoredDiagnosticMessages: ignoredDiagnosticMessages),
components: components
)
Expand All @@ -5915,17 +5920,17 @@ extension SnippetBasedReferenceTests {
let collector = XCTestDiagnosticCollector(test: self, ignoredDiagnosticMessages: ignoredDiagnosticMessages)
return (
TypesFileTranslator(
config: Config(mode: .types, access: .public, featureFlags: featureFlags),
config: Config(mode: .types, access: .public, namingStrategy: .defensive, featureFlags: featureFlags),
diagnostics: collector,
components: components
),
ClientFileTranslator(
config: Config(mode: .client, access: .public, featureFlags: featureFlags),
config: Config(mode: .client, access: .public, namingStrategy: .defensive, featureFlags: featureFlags),
diagnostics: collector,
components: components
),
ServerFileTranslator(
config: Config(mode: .server, access: .public, featureFlags: featureFlags),
config: Config(mode: .server, access: .public, namingStrategy: .defensive, featureFlags: featureFlags),
diagnostics: collector,
components: components
)
Expand Down
Loading