swagger-api/swagger-codegen

Allow package/folder overrides per language

開放

#5,081 建立於 2017年3月15日

 (2 則留言) (0 個反應) (0 位負責人)HTML (5,474 個分叉)batch import
Feature: CodegenGeneral: Suggestionhelp wanted

倉庫指標

星標
 (12,701 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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.

貢獻者指南