Skip to content

Add ability to prevent generation of deprecated APIs and components #776

Open
@edorphy

Description

@edorphy

Motivation

I'd like the ability to use a feature flag or some other construct to instruct the generator to ignore deprecated specification sections.

For a project that is using the generator net-new, this will immediately setup the project to use the modern API or replacement API when something is deprecated. Why generate deprecated source if it is known to be unnecessary from the start, right?

Proposed solution

I could see this happening via two different paths, either a modification to the configuration to add another check or a feature flag. Either way, it allows someone to opt-into the behavior so it would be backwards compatible with teams that generated in the past using the tool.

ignoreDeprecations: true

or by defining a new feature case: https://github.com/apple/swift-openapi-generator/blob/main/Sources/_OpenAPIGeneratorCore/FeatureFlags.swift

Alternatives considered

  1. Modify the OpenAPI spec file stripping out any deprecations
  2. Modify the generated source deleting any deprecations
  3. Using the filters which seems to be include behavior only, not exclude behavior so I don't think this would work

1 and 2 go against the nature of ''generating" from source, 3 doesn't seem to be possible.

Additional information

Similar to: #715

The intent behind this feature request is to prevent teams from calling deprecated methods to begin with. I believe this to be different than #715 because that one looks to prevent the deprecation indications from being emitted. I don't want the function, type, etc., to even exist.

Preventing deprecated API calls to any framework can be done via linters and other tools. However, the generated code still exists. While I don't expect someone to read all of the generated code, the fact that it exists allows a developer to go and read about it--no different than reading the original documentation or viewing the OpenAPI spec, yes, but this is just another point of visibility.

Plus on top of that, you can easily suppress using deprecated APIs in linters and then it becomes a team culture thing to not allow that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureNew feature.status/triageCollecting information required to triage the issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions