Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !10961

[swift5] Refactor encodeToJSON

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/funzin/swift5/encodable-to-json into master 3 years ago
  • Overview 0
  • Commits 7
  • Pipelines 0
  • Changes 31

Created by: funzin

Refactor encodeToJSON Some types return self only so we can skip same code using protocol extension method. if type is UUID, Int16, Int32, we can return self. I checked correct judgment. Screen Shot 2021-11-25 at 20 49 09

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. 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.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Compare
  • master (base)

and
  • latest version
    0e424f46
    7 commits, 2 years ago

31 files
+ 219
- 585

    Preferences

    File browser
    Compare changes
modules/openapi-gen‎erator/…/…/…/swift5‎
Extension‎s.mustache‎ +9 -39
Models.‎mustache‎ +4 -0
samples/cli‎ent/petstore‎
‎c‎
Packin‎g.cmake‎ +24 -0
swi‎ft5‎
alamofireLibra‎ry/…/…/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
asyncAwaitLibra‎ry/…/…/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
combineLibrar‎y/…/…/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
default/PetstoreCli‎ent/Classes/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
deprecated/Petstor‎eClient/…/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
nonPublicApi/Petsto‎reClient/…/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
objcCompatibl‎e/…/…/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
oneOf/PetstoreClie‎nt/Classes/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
promisekitLibra‎ry/…/…/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
readonlyPropert‎ies/…/…/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
resultLibrary/Petst‎oreClient/…/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
rxswiftLibrar‎y/…/…/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
urlsessionLibrary‎/…/PetstoreClient‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
x-swift-hashab‎le/…/…/OpenAPIs‎
Extensio‎ns.swift‎ +9 -39
Models‎.swift‎ +4 -0
modules/openapi-generator/src/main/resources/swift5/Extensions.mustache
+ 9
- 39
  • View file @ 0e424f46

  • Edit in single-file editor

  • Open in Web IDE


@@ -11,33 +11,15 @@ import AnyCodable
import PromiseKit{{/usePromiseKit}}{{#useVapor}}
import Vapor{{/useVapor}}{{^useVapor}}
extension Bool: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension Float: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension Int: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension Bool: JSONEncodable {}
extension Float: JSONEncodable {}
extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Int64: JSONEncodable {}
extension Double: JSONEncodable {}
extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension UUID: JSONEncodable {}
extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue }
@@ -83,18 +65,6 @@ extension Date: JSONEncodable {
func encodeToJSON() -> Any {
return CodableHelper.dateFormatter.string(from: self)
}
}
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}{{/useVapor}}{{#generateModelAdditionalProperties}}
extension String: CodingKey {
modules/openapi-generator/src/main/resources/swift5/Models.mustache
+ 4
- 0
  • View file @ 0e424f46

  • Edit in single-file editor

  • Open in Web IDE


@@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any
}
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error)
}
samples/client/petstore/c/Packing.cmake 0 → 100644
+ 24
- 0
  • View file @ 0e424f46

  • Edit in single-file editor

  • Open in Web IDE

set(CPACK_PACKAGE_NAME lib${pkgName})
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_PACKAGE_DESCRIPTION_SUMMARY})
set(CPACK_PACKAGE_VENDOR ${PROJECT_PACKAGE_VENDOR})
set(CPACK_PACKAGE_CONTACT ${PROJECT_PACKAGE_CONTACT})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${PROJECT_PACKAGE_MAINTAINER})
set(CPACK_VERBATIM_VARIABLES YES)
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEB_COMPONENT_INSTALL YES)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE)
include(CPack)
\ No newline at end of file
samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift
+ 9
- 39
  • View file @ 0e424f46

  • Edit in single-file editor

  • Open in Web IDE


@@ -9,33 +9,15 @@ import Foundation
import AnyCodable
#endif
extension Bool: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension Float: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension Int: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
extension Int64: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int64) }
}
extension Double: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension String: JSONEncodable {
func encodeToJSON() -> Any { return self }
}
extension Bool: JSONEncodable {}
extension Float: JSONEncodable {}
extension Int: JSONEncodable {}
extension Int32: JSONEncodable {}
extension Int64: JSONEncodable {}
extension Double: JSONEncodable {}
extension String: JSONEncodable {}
extension URL: JSONEncodable {}
extension UUID: JSONEncodable {}
extension RawRepresentable where RawValue: JSONEncodable {
func encodeToJSON() -> Any { return self.rawValue }
@@ -83,18 +65,6 @@ extension Date: JSONEncodable {
}
}
extension URL: JSONEncodable {
func encodeToJSON() -> Any {
return self
}
}
extension UUID: JSONEncodable {
func encodeToJSON() -> Any {
return self.uuidString
}
}
extension String: CodingKey {
public var stringValue: String {
samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models.swift
+ 4
- 0
  • View file @ 0e424f46

  • Edit in single-file editor

  • Open in Web IDE


@@ -10,6 +10,10 @@ protocol JSONEncodable {
func encodeToJSON() -> Any
}
extension JSONEncodable {
func encodeToJSON() -> Any { self }
}
public enum ErrorResponse: Error {
case error(Int, Data?, URLResponse?, Error)
}
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
Client: Swift Enhancement: Code Cleanup
2
Client: Swift Enhancement: Code Cleanup
    Assign labels
  • Manage project labels

Milestone
5.3.1
5.3.1 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
Administrator
Reference: OpenAPITools/openapi-generator!10961
Source branch: github/fork/funzin/swift5/encodable-to-json

Menu

Explore Projects Groups Snippets