@@ -65,7 +65,7 @@ public void serialize(Boolean value, JsonGenerator gen, SerializerProvider seria
6565
6666 private String implPackage ;
6767 protected String sourceFolder ;
68- protected boolean libraryMode = false ;
68+ protected boolean isLibrary = false ;
6969
7070 private static final String BASE_CLASS_SUFFIX = "base" ;
7171 private static final String SERVER_PORT = "serverPort" ;
@@ -74,8 +74,7 @@ public void serialize(Boolean value, JsonGenerator gen, SerializerProvider seria
7474 private static final String DEFAULT_PACKAGE_NAME = "openapi_server" ;
7575 private static final String DEFAULT_SOURCE_FOLDER = "src" ;
7676 private static final String DEFAULT_PACKAGE_VERSION = "1.0.0" ;
77- private static final String LIBRARY_MODE = "libraryMode" ;
78- private static final String DEFAULT_LIBRARY_MODE = "false" ;
77+ private static final String IS_LIBRARY = "isLibrary" ;
7978
8079 @ Override
8180 public CodegenType getTag () {
@@ -87,8 +86,8 @@ public String getHelp() {
8786 return "Generates a Python FastAPI server (beta). Models are defined with the pydantic library" ;
8887 }
8988
90- public void setLibraryMode (final boolean mode ) {
91- this .libraryMode = mode ;
89+ public void setIsLibrary (final boolean isLibrary ) {
90+ this .isLibrary = isLibrary ;
9291 }
9392
9493 public void setImplPackage (final String implPackage ) {
@@ -124,7 +123,6 @@ public PythonFastAPIServerCodegen() {
124123 additionalProperties .put (CodegenConstants .SOURCE_FOLDER , DEFAULT_SOURCE_FOLDER );
125124 additionalProperties .put (CodegenConstants .PACKAGE_NAME , DEFAULT_PACKAGE_NAME );
126125 additionalProperties .put (CodegenConstants .FASTAPI_IMPLEMENTATION_PACKAGE , DEFAULT_PACKAGE_NAME .concat (".impl" ));
127- additionalProperties .put (LIBRARY_MODE , DEFAULT_LIBRARY_MODE );
128126
129127 languageSpecificPrimitives .add ("List" );
130128 languageSpecificPrimitives .add ("Dict" );
@@ -163,9 +161,9 @@ public PythonFastAPIServerCodegen() {
163161 "python package name for the implementation code (convention: snake_case)." ,
164162 implPackage );
165163
166- addSwitch (LIBRARY_MODE ,
167- "whether to generate minimal python code to be published as a separate library" ,
168- libraryMode );
164+ addSwitch (IS_LIBRARY ,
165+ "whether to generate minimal python code to be published as a separate library or not " ,
166+ isLibrary );
169167 }
170168
171169 @ Override
@@ -176,7 +174,7 @@ public void processOpts() {
176174 convertPropertyToStringAndWriteBack (CodegenConstants .PACKAGE_NAME , this ::setPackageName );
177175 convertPropertyToStringAndWriteBack (CodegenConstants .SOURCE_FOLDER , this ::setSourceFolder );
178176 convertPropertyToStringAndWriteBack (CodegenConstants .FASTAPI_IMPLEMENTATION_PACKAGE , this ::setImplPackage );
179- convertPropertyToBooleanAndWriteBack (LIBRARY_MODE , this ::setLibraryMode );
177+ convertPropertyToBooleanAndWriteBack (IS_LIBRARY , this ::setIsLibrary );
180178
181179 modelPackage = packageName + "." + modelPackage ;
182180 apiPackage = packageName + "." + apiPackage ;
@@ -185,7 +183,7 @@ public void processOpts() {
185183 supportingFiles .add (new SupportingFile ("openapi.mustache" , "" , "openapi.yaml" ));
186184 supportingFiles .add (new SupportingFile ("main.mustache" , String .join (File .separator , new String []{sourceFolder , packageName .replace ('.' , File .separatorChar )}), "main.py" ));
187185
188- if (!this .libraryMode ) {
186+ if (!this .isLibrary ) {
189187 supportingFiles .add (new SupportingFile ("docker-compose.mustache" , "" , "docker-compose.yaml" ));
190188 supportingFiles .add (new SupportingFile ("Dockerfile.mustache" , "" , "Dockerfile" ));
191189 }
@@ -200,12 +198,15 @@ public void processOpts() {
200198 namespacePackagePath .append (File .separator ).append (tmp );
201199 supportingFiles .add (new SupportingFile ("__init__.mustache" , namespacePackagePath .toString (), "__init__.py" ));
202200 }
201+
203202 supportingFiles .add (new SupportingFile ("__init__.mustache" , StringUtils .substringAfter (modelFileFolder (), outputFolder ), "__init__.py" ));
204203 supportingFiles .add (new SupportingFile ("__init__.mustache" , StringUtils .substringAfter (apiFileFolder (), outputFolder ), "__init__.py" ));
205- supportingFiles .add (new SupportingFile ("__init__.mustache" , StringUtils .substringAfter (apiImplFileFolder (), outputFolder ), "__init__.py" ));
206204
205+ if (!this .isLibrary ) {
206+ supportingFiles .add (new SupportingFile ("__init__.mustache" , StringUtils .substringAfter (apiImplFileFolder (), outputFolder ), "__init__.py" ));
207+ }
208+
207209 supportingFiles .add (new SupportingFile ("conftest.mustache" , testPackage .replace ('.' , File .separatorChar ), "conftest.py" ));
208-
209210 supportingFiles .add (new SupportingFile ("gitignore.mustache" , "" , ".gitignore" ));
210211 supportingFiles .add (new SupportingFile ("pyproject_toml.mustache" , "" , "pyproject.toml" ));
211212 supportingFiles .add (new SupportingFile ("setup_cfg.mustache" , "" , "setup.cfg" ));
0 commit comments