OpenAPITools / OpenAPITools/openapi-generator

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

Open
#1,456 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Swift Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the swift4 generation path invoked by -g swift4, using the shown objcCompatible configuration and OpenAPI input. Reproduce the generated ModelA code and inspect the handling of Int64 and Bool properties. Done means the generated Swift 3/4 code builds without the reported map errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.