Videos
Check out our tutorial video series.
Automating API Client Generation and Distribution with OpenAPI, Gradle, and AWS S3: A Guide to Build and Distribute Type-Safe Clients via Maven.
Many teams use OpenAPI to document and consume API services. Using OpenAPI tools we can generate strongly typed clients in a wide range of languages. We can then call other services without needing to maintain type definitions in multiple projects. With Gradle and Spring we can automate the generation and publication of Swagger codegen clients and distribute the packages via AWS S3. This will give us a private artifact repository that we can connect to in calling services.
The first step in automating your API client generation is to annotate your API endpoints and generate an OpenAPI spec. In Spring we can use to describe our endpoints. In a
file add:
Then add annotations to your controllers:
Next we can use gradle to generate a spec:
Define a custom task to start Spring and write the OpenAPI spec to the build directory.
When we run an
file will be written to the
directory.
Now we can generate an OpenAPI client using a gradle task:
Run the command like so to write a client into the
directory. Next we will publish the client to maven via S3.
Create an S3 bucket to use as your maven repository.
Now we can publish to S3 with Gradle.
We can now use a gradle init script to patch the generated gradle client and add a publishing method for our S3 bucket.
Then to run:
After this we have shown how to describe your API, generate a client, and publish to S3.
Check out our tutorial video series.
Email and SMS guides for automation and testing.
View github project code for multiple languages.
Latest posts from the MailSlurp team.
Test, build, and automate messaging with a free MailSlurp account.