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

[SWIFT4] Value of type XX has no member 'map' #1456

Open
Sal0g opened this issue Nov 15, 2018 · 2 comments
Open

[SWIFT4] Value of type XX has no member 'map' #1456

Sal0g opened this issue Nov 15, 2018 · 2 comments

Comments

@Sal0g
Copy link

Sal0g commented Nov 15, 2018

Description

When using using Objc compatible code, the produced code is not valid in Swift 3/4.

Using openapi-generator Version 3.3.2

with the command:

openapi-generator generate \
	-i ./openAPI-3.yaml \
	--config ./api-generation-config.json \
	-g swift4 \

and the config file api-generation-config.json:

{
...
"objcCompatible":"true",
"podswift_version":"4.0"
}

and the yaml:

definitions:
  ModelA:
    required:
      - intA
    properties:
      intA:
        type: integer
        format: int64
      name:
        type: string

produces this code:

public struct ModelA: Codable {

    public var intA: Int64
    public var intANum: NSNumber? {
        get {
            return intA.map({ return NSNumber(value: $0) })
        }
    }
    public var name: String?

    public init(intA: Int64, name: String?) {
        self.intA = intA
        self.name = name
    }
}

resulting in the error:
- ERROR | xcodebuild: ModelA.swift: error: value of type 'Int64' has no member 'map'

This occurs for type Int64 and Bool.

@wing328
Copy link
Member

wing328 commented Nov 20, 2018

@Sal0g thanks for reporting the issue. Is it correct to say that it works fine with Int32 but not Int64 for Integer type?

@Sal0g
Copy link
Author

Sal0g commented Nov 21, 2018

Yes, it seems that Int32 in the yaml definition is getting translated into Int/Int? whereas Int64 gets translated into Int64 in the generated Swift code.

Sal0g pushed a commit to Sal0g/openapi-generator that referenced this issue Dec 5, 2018
- Models: Expose non-optional variables to @objc. Otherwise e.g. Int64 is not visible in objc
- Models: Try avoiding generated code that has boolVariable.map ({ return NSNumber(value: $0) }) as map does not exist for Bool in Swift (see Issue OpenAPITools#1456)
- API: Avoid Void? arguments with @objc, as they are not available in objc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants