Skip to content
GitLab
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
  • Issues
  • #6614
Closed
Open
Issue created Jun 10, 2020 by Administrator@rootContributor3 of 6 checklist items completed3/6 checklist items

[BUG] [Swift] Number without specified type doesn't set x-swift-optional-scalar to true

Created by: marekpridal

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I need to generate obj-c accessible models and there is a problem in interoperability with some nullable types which cannot be represented in obj-c. Swift5ClientCodegen does support that but there is a problem if in OpenAPI declaration is missing format and only specify type. Then it's generated into Double? but postProcessModelProperty function does not trigger x-swift-optional-scalar to true. It can definitely be fixed on declaration side but client Codegen should expected it, too.

    @Override
    public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
        super.postProcessModelProperty(model, property);

        boolean isSwiftScalarType = property.isInteger || property.isLong || property.isFloat
                || property.isDouble || property.isBoolean;
        if ((!property.required || property.isNullable) && isSwiftScalarType) {
            // Optional scalar types like Int?, Int64?, Float?, Double?, and Bool?
            // do not translate to Objective-C. So we want to flag those
            // properties in case we want to put special code in the templates
            // which provide Objective-C compatibility.
            property.vendorExtensions.put("x-swift-optional-scalar", true);
        }
    }
openapi-generator version

4.3.1

OpenAPI declaration file content or url
    "GpsCoordinatesTO": {
      "type": "object",
      "properties": {
        "gpsX": {
          "type": "number",
          "format": "double"
        },
        "gpsY": {
          "type": "number"
        }
      },
      "title": "GpsCoordinatesTO"
    }

-->

Command line used for generation

openapi-generator generate -i swagger.json -g swift5 --additional-properties=library=urlsession,objcCompatible=true -o swift/ --skip-validate-spec

Steps to reproduce

Generate client from declaration which includes snippet above.

Suggest a fix

Update postProcessModelProperty function to handle only number because it's generated into Swift as Double? which cannot be represented in obj-c.

Assignee
Assign to
Time tracking