OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.44k stars 6.48k forks source link

Subpackage for models #18015

Open adnsimona opened 7 months ago

adnsimona commented 7 months ago

Describe the solution you'd like

It would be nice to be able to set subpackage for generated model classes.

...
components:
  schemas:
...
    ClassToPlaceInSubPackage:
      type: object
      subpackage: sub.pkg
...

Now if the model package option of openapi generator was set to com.example.project.someapi.models, the ClassToPlaceInSubPackage would go to the package com.example.project.someapi.models.sub.pkg;.

TobseF commented 4 months ago

This would indeed help a lot. I'm maintaining an api which has about 50 model classes. In my Kotlin dto, the model classes are all separated into small packages. But the generated Typescipt model is thrown all together in one folder. This is not the kind I want to provide the model to other devs. And it also violates the Separation of Concerns (SoC) principle.

I want to group classes wich belogs each other. Otherwise its hart to understand a model. For example, an enum named Type doesn't make sense in a root folder. It may even collide with other types with the same name. But in a package named collection.book it may become expressive. Like a field has a class context, the class should have a package context.