[Swift] property, parameter name mapping support#16207
Merged
Conversation
4brunu
reviewed
Jul 28, 2023
4brunu
reviewed
Jul 28, 2023
Comment on lines
+16
to
+19
| internal var type: String? | ||
| internal var type: String? | ||
| internal var type: String? | ||
| internal var type: String? |
Contributor
There was a problem hiding this comment.
@wing328 all the properties have the same name, this won't compile
Member
Author
There was a problem hiding this comment.
yes, this won't compile without using the mapping option, e.g.
generatorName: swift5
outputDir: samples/client/petstore/swift5/nonPublicApi
inputSpec: modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/swift5
generateAliasAsModel: true
additionalProperties:
podAuthors: ""
podSummary: PetstoreClient
sortParamsByRequiredFlag: false
nonPublicApi: true
projectName: PetstoreClient
podHomepage: https://github.com/openapitools/openapi-generator
nameMappings:
_type: underscoreType
type_: typeWithUnderscore
-type: dashType
parameterNameMappings:
_type: underscoreType
type_: typeWithUnderscore
-type: dashTypeI removed the files as these files are not supposed to be included. You can refer to the diff in the description to understand the change before and after using nameMappings, parameterNameMappings in the config.
Member
Author
There was a problem hiding this comment.
And this is what the schema looks like that will result in naming collisions:
components:
schemas:
PropertyNameMapping:
properties:
http_debug_operation:
type: string
_type:
type: string
type:
type: string
type_:
type: string
-type:
type: string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tested locally and the diff looks like:
internal struct PropertyNameMapping: Codable, JSONEncodable, Hashable { internal var httpDebugOperation: String? + internal var underscoreType: String? internal var type: String? - internal var type: String? - internal var type: String? - internal var type: String? + internal var typeWithUnderscore: String? + internal var dashType: String? - internal init(httpDebugOperation: String? = nil, type: String? = nil, type: String? = nil, type: String? = nil, type: String? = nil) { + internal init(httpDebugOperation: String? = nil, underscoreType: String? = nil, type: String? = nil, typeWithUnderscore: String? = nil, dashType: String? = nil) { self.httpDebugOperation = httpDebugOperation + self.underscoreType = underscoreType self.type = type - self.type = type - self.type = type - self.type = type + self.typeWithUnderscore = typeWithUnderscore + self.dashType = dashType } internal enum CodingKeys: String, CodingKey, CaseIterable { case httpDebugOperation = "http_debug_operation" - case type = "_type" + case underscoreType = "_type" case type - case type = "type_" - case type = "-type" + case typeWithUnderscore = "type_" + case dashType = "-type" } // Encodable protocol methods @@ -39,10 +39,10 @@ internal struct PropertyNameMapping: Codable, JSONEncodable, Hashable { internal func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(httpDebugOperation, forKey: .httpDebugOperation) + try container.encodeIfPresent(underscoreType, forKey: .underscoreType) try container.encodeIfPresent(type, forKey: .type) - try container.encodeIfPresent(type, forKey: .type) - try container.encodeIfPresent(type, forKey: .type) - try container.encodeIfPresent(type, forKey: .type) + try container.encodeIfPresent(typeWithUnderscore, forKey: .typeWithUnderscore) + try container.encodeIfPresent(dashType, forKey: .dashType) } }PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.For Windows users, please run the script in Git BASH.
master(6.3.0) (minor release - breaking changes with fallbacks),7.0.x(breaking changes without fallbacks)FYI @jgavris (2017/07) @ehyche (2017/08) @Edubits (2017/09) @jaz-ah (2017/09) @4brunu (2019/11) @dydus0x14 (2023/06)