swagger-codegen-generators icon indicating copy to clipboard operation
swagger-codegen-generators copied to clipboard

added useFqn parameter to generate fully qualified model class names (Java)

Open frode-carlsen opened this issue 4 years ago • 2 comments

This resolves #1001 by adding an additional property useFqn that will take the assigned schema name as the basis for the generated package namespace of the model files. Any modelPackage already set (or default io.swagger.model) will be prepended to the package namespace.

frode-carlsen avatar Dec 28 '21 08:12 frode-carlsen

This currently only supports the generated Java code, but could relatively easily be extended to the other language templates.

As an asside, a couple of refactorings ought be done to swagger-codegen to improve this. If this seems a viable PR then I'd be happy to submit a PR for that too:

  • DefaultGenerator#processModels only processes one model at a time atm. The templates are complicated to support multiple models when only one is present at a time. Propose simplifying this method signature to only take one definition at a time if possible
  • I've reused CodegenModel#xmlNamespace field for this case to better support generated import statement. This should be generalized in swagger-codegen to a namespace field or similar

frode-carlsen avatar Dec 28 '21 08:12 frode-carlsen

@frantuma @HugoMario would it be possible to get feedback on this PR? This would be very helpful for generating code from larger OpenAPI specs.

frode-carlsen avatar Jan 16 '22 11:01 frode-carlsen