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
  • Merge requests
  • !12882

Fix npe when unwrapping optional in swift 5 client, if web server returns no data and client should return nil

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/locosmac/master into master Jul 15, 2022
  • Overview 8
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: locosmac

When calling an api that returns an optional result, the generated swift 5 client with url session implementation tries to unwrap nil and crashes, in cases where the called endpoint actually returns no data. I think that this is due to the fact that it is never possible to cast Optional < T >.none to T. The solution implemented here is stolen from https://stackoverflow.com/questions/41492153/how-to-produce-a-nil-of-a-generic-type and it works for me.

You can reproduce this, for example, using the MoWeSta Api (https://www.mowesta.com/api/mowesta.json) using the api call that returns the nearest weather station for a city (/cities/{id}/station). If you call this with a city id that does not lie near Germany (e.g. Essen in Belgium, id: 81211), the api responds with 201 (success, no data) and no data (i.e. no weather station). As a result, the client will try to return a nil value which will cause the process to crash.

With the change applied, the client works as expected.

@jgavris (2017/07) @ehyche (2017/08) @Edubits (2017/09) @jaz-ah (2017/09) @d-date (2018/03)

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.1.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/locosmac/master