Swagger-codegen : Can manual changes in the generated models be preserved? - spring-boot

With Swagger as i understand one cannot pass/specify things like Jackson annotations for fields when specifying the models in the swagger definition yaml.
Therefore, is there a way to manually make these changes in the generated model files & request swagger (swagger-codegen) to try & preserve those when regenerating the models?
I tried doing this & see that by default it just overwrites the files completely, i couldn't find any setting for this in the codegen configuration.
Can someone suggest any idea on how to go about this?
Thanks

You can use custom templates with the -t option, e.g.
java -jar swagger-codegen-cli.jar generate -i https://raw.githubusercontent.com/swagger-api/swagger-codegen/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l csharp -o C:\test\csharp-client -t C:\workspace\csharp-custom-templates
where C:\workspace\csharp-custom-templates stores the templates with your changes.

Related

OpenAPI generate spring from swagger with "oneof" property

I read already this thread:
How to use OpenAPI "oneOf" property with openapi-generator-maven-plugin when generating Spring code
But I still cant find a good working solution to generate Spring capable models from Swagger file with "oneof" properties.
I tried:
java -jar .\openapi-generator-cli.jar generate -i ./swagger.json -o ./spring-gen -g spring -c .\spring-config.json
with spring-config.json:
{
"legacyDiscriminatorBehavior":false
}
Did I miss something to get it working?
Is there a better/easy solution to get the models?
Open for any hints and thanks in advance!
Kind regards
Gregor

How to generate swagger code gen for a spring boot project

I need help in getting clarification for below mentioned points
I have a swagger json. From this I want to generate Model separately by passing java as language. api and invoker clsses by passing spring as language and want to add model jar as dependency. Because I want to use model for different projects commonly. So I want to include a build task to generate model jar every time to get latest models from json. and will issue swagger code gen command with spring as language while trying to create project. Is this correct way of handling. If not can someone let me know best of handling this.
How to handle versioning from swagger.
I am new in using swagger and spring. Please suggest me best to go
I do something similar. I have my models in a separate project which is then a dependency for a bunch of API projects. This is because the APIs sometimes call each other, so need to know about each others objects.
What I do is:
Swagger structure:
In the models project I have a swagger containing just the definitions (empty object as paths)
In the API projects I have a swagger which references the definitions in the models project
Build process
Build the models project first with generateApis = false
Build the APIs with typeMappings and ImportMappings in the config, telling them to take all the models in common from that namespace
I use the maven plugin to run the codegen. I have a pretty hacky bash script that updates the type mappings in the pom when I have added new objects to the models

How can I directly add properties from a Spring Boot property source to the environment

I have a Spring Boot property source file containing a set of arbitrary properties. I would like to get all of those properties and add them to the environment.
I tried injecting the Environment into the class, and I am able to use that to get known properties. But I am not sure how to get all properties from there.'
If course I can use a traditional Properties.load() but is there a Spring way to do that?
Have you tried #PropertySource anotation?
I wouldn't recommend using PropertySource because you can't configure the precedence of the properties that you add. You may want that these properties can be overridden in some way, maybe? Or you may want that these properties take precedence over others. For this, I recommend you implement an EnvironmentPostProcessor.
There is a sample in this university session at Devoxx where we showcase how to read a file from the home directory and add it after command line properties. You could do pretty much the same thing and order them the way you want.
The sample app is available here if you want to give that a try.
If you put your properties into the "application.properties" (or any of the other places described here), the properties are automatically available in Spring's Environment.
One way to access the properties then is simply to #Autowire the Environment into the class where you want to access it.

Axis 1.4.1 wsdl2Java Locator classes

I spend a good amount of time on rest services but not so much on SOAP services. So this might be a stupid question, but i am going to ask it anyway.
I am building my wsdl files with wsdl2java (axis 1.4.1). The sample code I was given has a Service Locator class in the generated client code. I am trying to figure out if I need to build this class after my client is built or if I am doing something wrong in my wsdl2java command
wsdl2java.bat --test-case --generate-all --unpack-classes -uri file.wsdl -o src
Try adding -W -a to the cmd line parameters. I was having problems with missing classes ( still am actually ), but those parameters created most of the missing classes. I'll update the answer when i resolve my last missing class.
Here is the axis wsdl2java reference http://axis.apache.org/axis/java/reference.html
Just found that also adding -w parameter fixed my last issue.

Maven Grails web.xml

Might be a stupid question, but in my current maven project i do not have a web.xml in my /web-app/WEB-INF folder.
There is no web-xml in my project and never has been, im trying to add it but my application is non-responsive to anything written in the web.xml. What am i missing?, iv tried specifying the path to it through the config.groovy like:
grails.project.web.xml="web-app/WEB-INF/web.xml"
Am i missing something? Do i need to specify the web.xml in some other config file in order to make my project utilize it ?
Run
grails install-templates
to copy templates that Grails uses for all code generation activities (including "web.xml").
"web.xml" file will be created in "src/templates/war" directory.
You may be able to get away with something similar to this https://stackoverflow.com/a/5891646/107847. It doesn't install separate web.xml but does allow you add what ever content you need or edit any of the generated content.

Resources