Skip to content

[BUG] Swift: Date as Path parameter not correctly mapped to String #18074

@kalinjul

Description

@kalinjul

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When an Api Spec uses a Date as path parameter like /pets/{date} and enabling useCustomDateWithoutTime,
the method generated is something like open class func updateDate(date: OpenAPIDateWithoutTime) async throws {(which is correct).

However, the method fails to convert the date to a string correctly ("https:///pets/2024-03-11"), instead it calls the API like this:
https://<api-url>/pets/OpenAPIDateWithoutTime(wrappedDate%3A%202024-02-29%2023%3A00%3A00%20+0000,%20timezone%3A%20Europe/Berlin%20(fixed))"

openapi-generator version

Tested with version 7.3.0

OpenAPI declaration file content or url
{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Swagger Petstore",
    "license": {
      "name": "MIT"
    }
  },
  "servers": [
    {
      "url": "http://petstore.swagger.io/v1"
    }
  ],
  "paths": {
    "/pets/{date}": {
      "put": {
        "tags": [
          "date"
        ],
        "summary": "put date",
        "operationId": "updateDate",
        "parameters": [
          {
            "name": "date",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date",
              "example": "2022-12-06"
            },
            "example": "2022-12-06"
          }
        ],
        "responses": {
          "204": {
            "description": "Successful Operation"
          }
        }
      }
    }
  },

    
  "components": {
    "schemas": {

    }
  }
}
Generation Details

config.json:

{
   "mapFileBinaryToData": "false",
   "responseAs": "AsyncAwait",
   "useCustomDateWithoutTime": "true"
}

Steps to reproduce

Generate API:
openapi-generator-cli.jar generate -g swift5 -i sample.json -o out -c config.json

Use Api

Suggest a fix

I will post a PR with a suggestion

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions