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
  • #12130
Closed
Open
Issue created Apr 13, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Swift] Generating standalone Swift models should not conform them to JSONEncodable

Created by: stjernegard

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

Swift models when generated without API or supporting files, should not conform to protocols defined only in those supporting files. Currently the swift5 generator outputs models conforming to a JSONEncodable protocol, which isn't defined in the output.

openapi-generator version

The problem was introduced in release v5.4.0 with commit https://github.com/OpenAPITools/openapi-generator/commit/febf49662a4d4fda5dbeed4888a1840db801177d and exists in 6.0.0 and in the current master branch.

OpenAPI declaration file content or url
---
openapi: '3.0.0'
paths:
  /:
    get:
      responses:
        200:
          description: OK
      description: Dummy endpoint

info:
  title: MyModel
  version: '1.0.0'

components:
  schemas:
    mymodel:
      type: object
      properties:
        name:
          type: string
Generation Details
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v5.4.0 generate \
    -i /local/mymodel.yaml \
    -g swift5 \
    -o /local/out \
    --global-property=models,modelDocs=false
Steps to reproduce
  • Save the above YAML file as mymodel.yaml
  • Run the above docker command
Related issues/PRs

There doesn't seem to be any other reports of the same bug. I tried searching all open and closed issues for JSONEncodable, but found nothing relevant.

Suggest a fix

The protocol conformance could be only added if the protocol itself is also being generated.

Assignee
Assign to
Time tracking