Skip to content

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

@stjernegard

Description

@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 febf496 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions