In no time we’ll see the whole world getting to adopt the code that’s been generated by AI/ML models for the requirements that we have in hand. At the moment, most of these applications are still in their nascent stages and the research is heading towards a direction where it will be complementing human software developers on writing code. Meanwhile, we should also equip ourselves to use the current available tools to move fast.
We, at TechConative thought we would be sharing our learnings with our community under the title Fast-track your software development, a blog series which can potentially save development, testing and deployment stages of software delivery.
While one side of the world is developing applications to generate the code based on the requirements, the other side still contemplates on development paradigms to choose with. For e.g. Should I choose Code-First or Design-First for my application. Number of blogs has been published in the past, and I assume this debate will go for a while and the opinion differs based on the scenario from which we’re coming.
Assume you have come to a conclusion and decided to go with Design-First approach and the next potential question that can hit your mind is “Is rapid development possible now?”. The answer to this your question is yes, and in fact you would have already guessed it from the title of this blog we’ll walk you through on how to fast-track your development by leveraging on OpenAPI code gen in this blog.
target
folder, so they are transient and not tracked as part of version control.build
in the pom.xml
(maven project),<build> <plugins> <plugin> <groupId>org.openapitools</groupId> <artifactId>openapi-generator-maven-plugin</artifactId> <!-- RELEASE_VERSION --> <version>5.4.0</version> <!-- /RELEASE_VERSION --> <executions> <execution> <goals> <goal>generate</goal> </goals> <configuration> <inputSpec>${project.basedir}/api/sample-api-generator-v1.yaml</inputSpec> <generatorName>spring</generatorName> <configOptions> <apiPackage>com.techconative.openapispec.blog.api</apiPackage> <modelPackage>com.techconative.openapispec.blog.model</modelPackage> <serializableModel>true</serializableModel> <snapshotVersion>true</snapshotVersion> <interfaceOnly>true</interfaceOnly> <skipDefaultInterface>true</skipDefaultInterface> <useTags>true</useTags> </configOptions> <typeMappings> <typeMapping>OffsetDateTime=Date</typeMapping> </typeMappings> <importMappings> <importMapping>java.time.OffsetDateTime=java.util.Date</importMapping> </importMappings> </configuration> </execution> </executions> </plugin> </plugins> </build>
typeMapping
that will help you to customize the type of object that you need to map in java.mvn clean compile
will generate the code as configured.target
directory, just write you controller class and extends the
API generated using OpenAPI.@RestController public class UserRestController implements GithubApi{ @Override public ResponseEntity<List<RepositoryVO>> getReposForUser(String userid) { // Your actual logic goes here return null; }
You can find sample project here which generates a Class from OAS.
The produced API classes are located in the target folder as shown below.
We would love to hear from you! Reach us @
info@techconative.com