Skip to content

Commit

Permalink
[Cleanup] Make Config's namingStrategy and accessModifier params cons…
Browse files Browse the repository at this point in the history
…istent (#713)

### Motivation

A missed fixup from #708:
#708 (comment)

### Modifications

Removed the default from Config.init and forced all callers to make a
choice on the naming strategy, just like for accessModifier.

### Result

Consistent handling of these two parameters.

### Test Plan

Tests passed locally.
  • Loading branch information
czechboy0 authored Jan 6, 2025
1 parent f3c32cc commit 84b693f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
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

0 comments on commit 84b693f

Please sign in to comment.