swagger-api / swagger-api/swagger-codegen

Allow package/folder overrides per language

Open
#5,081 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature: Codegen General: Suggestion help wanted
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Right now codegen allows configuration of a model package for java, which is usually left blank for other implementations. This works well but we would like to give the ability to better organize models. For example, in java we may want to introduce some package structure. In C++ we may want a folder structure.

These options are language-specific, and therefore should be configurable (or left out) for each language type. In addition, we'll need to standardize on how they're referenced, since "java" can cover many generators.

I propose that we first introduce an extension that looks roughly like this:

definitions:
  MyModel:
    x-codegen-class:
      # explicitly set the package/filename for this model
      java: io.swagger.client.mymodels.MyModel
      cpp: client/MyModel

where the key of the extension value will be specific to the programming language as opposed to the framework. Note, no suffix is supplied.

Next, when the model is processed, it will create the file in the appropriate location. This would need to be handled in the language-specific processing. For java, the io.swagger.client.mymodels will translate to src/*/java/io/swagger/client/mymodels/MyModel.java. For the C++ example, the .h and .cpp files will live in a client folder.

Finally, the import mappings (and includes) will need to be updated as well.

My guess is that this will change some of the CodegenConfig interfaces (many of the methods to get import mappings take a string, where you need a CodegenModel) so we should target 2.3.0 for this work.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CodegenConfig interfaces and the language-specific processing for Java and C++. Trace how model packages, filenames, import mappings, and includes are currently derived. Done means supporting language-specific package or folder overrides without suffixes, placing generated files correctly, and updating imports and includes consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, java
Domain
devtools, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.