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
  • #1424
Closed
Open
Issue created Nov 13, 2018 by Administrator@rootContributor

[SWIFT4] Dates Are Inconsistently Encoded

Created by: james-rantmedia

Description

The generated code for GET requests that have URL Query Parameters that are dates currently encodes the date to JSON and inserts it as a query parameter.

The problem with this is that it is possible for the encoded date to contain a + character, which is a valid character in a query parameter, but not as an encoded space, as intended.

My problem example:

I have a date with a timezone component, like 2018-11-13T13:20:14.421+01:00. Adding this date to a URL's query results in: https://example.com?date=2018-11-13T13:20:14.421+01:00. The + is not encoded by URLQueryItem because it is a valid character.

However, when the server receives the request and decodes the query parameters, the result is 2018-11-13T13:20:14.421 01:00. The + was decoded to a space. This is unintentional, and the server responds with HTTP 400 Bad Request.

openapi-generator version

3.3.2

Steps to reproduce
  • Generate code for Swift4 from an OpenAPI Spec that has a GET request with URL query parameters, one of which is a Date.
  • Call the generated request method passing a date that has a positive timezone adjustment, eg 2018-11-13T13:20:14.421+01:00
Related issues/PRs

I will submit a PR to address this issue and update this issue.

Suggest a fix/enhancement

Modify the template for API classes to include a URL encoding step for dates added as query parameters. Eg:

{{#queryParams}}
{{> _param}}{{#isDateTime}}.addingPercentEncoding(withAllowedCharacters: CharacterSet(charactersIn: "1234567890T.-")){{/isDateTime}}{{#hasMore}}, {{/hasMore}}
{{/queryParams}}
Assignee
Assign to
Time tracking