<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mike Mwita on Medium]]></title>
        <description><![CDATA[Stories by Mike Mwita on Medium]]></description>
        <link>https://medium.com/@MikeMwita?source=rss-6a897e711657------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*novUdZni7cs6YaiTxSd5kQ.jpeg</url>
            <title>Stories by Mike Mwita on Medium</title>
            <link>https://medium.com/@MikeMwita?source=rss-6a897e711657------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:17:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@MikeMwita/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Generating Go code from OpenAPI Specification Document]]></title>
            <link>https://medium.com/@MikeMwita/generating-go-code-from-openapi-specification-document-ae225e49e970?source=rss-6a897e711657------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae225e49e970</guid>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[gherkin]]></category>
            <category><![CDATA[openapi-specification]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[api-first]]></category>
            <dc:creator><![CDATA[Mike Mwita]]></dc:creator>
            <pubDate>Thu, 28 Sep 2023 12:54:24 GMT</pubDate>
            <atom:updated>2023-09-28T12:54:24.538Z</atom:updated>
            <content:encoded><![CDATA[<h4>Generating Go code from OpenAPI</h4><p>A step-by-step look at generating Go code from OpenAPI specification</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jYcOx5F5fIiojgQqzivBHA.png" /></figure><p><strong>Introduction</strong></p><p>As a back-end developer working on a rapidly evolving project. I wanted to have a taste of API&#39;s fast development approach. I discovered the oapi-codegen tool, which can generate API code based on an OpenAPI Specification file. After testing the tool and seeing its potential, I decided to write this article to share my experience and walk others through the process of generating code with oapi-codegen. The article will provide a step-by-step flow on how to generate the code.</p><h4>Prerequisites</h4><ul><li>Go 1.16+</li><li>Basic understanding of Go</li><li>OpenAPI beforehand knowledge</li></ul><p><strong>By the end of this article, you should be able to:</strong></p><ol><li>Install the oapi-codegen package</li><li>Use the oapi-codegen package to generate code</li><li>Understand how to use OpenAPI</li></ol><p><strong>What is OpenAPI Specification</strong></p><p>According to the OpenAPI documentation, the definition for OpenAPI specification is as follows,</p><blockquote>The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to HTTP APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined, a consumer can understand and interact with the remote service with a minimal amount of implementation logic.</blockquote><p>Basically, OpenAPI is a format that is used to provide a standard definition for RESTful APIs. It defines the structure and syntax of the RESTful APIs.</p><p><strong>Why Opt For OpenAPI</strong></p><ul><li>Design first approach-the API specification is designed before writing any code, this enables a proper organization of the API features and endpoints effectively.</li><li>There is independence -different teams are able to work independently as there is a common understanding of what the API is supposed to do. This is possible through a mock server.</li><li>Documentation-OpenAPI offers the choice of generating documentation automatically.</li><li>We can generate both the server code and client code which we can easily use to consume APIs that are exposed by other applications.</li></ul><p><strong>Creating the Project</strong></p><p>1. Navigate to the folder where you want to create a sample project.</p><p>2. Start the projects module using the go mod init command in the terminal:</p><pre>go mod init github.com/MikeMwita/article<br>   </pre><p><strong>Writing OpenAPI document</strong></p><p>This is a sample of the OpenAPI specification file we will use to generate the documentation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cb574150af5b0d6a70972981c5d5bb3/href">https://medium.com/media/7cb574150af5b0d6a70972981c5d5bb3/href</a></iframe><blockquote>You can install the Gherkin extension for YAML files in your preferred IDE’s marketplace. This will allow you to write better and structure your OpenAPI document effectively.</blockquote><p><strong>The file Components :</strong></p><p>The first section is basically the metadata contents of the file. This includes the title, description, and version of our API. The second section encompasses the server section. This is the local server that we will use for the development of the API. The preceding section is the path section. It lists the various endpoints of the API. This is a “/signup” endpoint that is a POST request. It allows users to signup for the API. The parameters required for the request body are name, email, password, and confirm password. After that, the endpoint returns a success message or an error message if a user cannot sign up.</p><p><strong>Oapi-codegen Installation</strong></p><p>To install Oapi-codegen :</p><p>Within the same terminal where you created the project,</p><ol><li>Navigate to the project’s directory</li><li>Copy and paste the following command:</li></ol><pre>go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest</pre><p>4. This command is going to install the oapi-codegen library on our machine. To confirm the installation, run the following command in your terminal :</p><pre>oapi-codegen -version</pre><p><strong>How to generate the code</strong></p><p>To generate the code, paste the following command within the same terminal:</p><pre>oapi-codegen --package=main --generate types,client openapi.yaml &gt; openapi.gen.go<br></pre><ul><li>oapi-codegeninitializes the code generation tool</li><li>--package=mainthis command specifies a package that contains generated code</li><li>--generate types,client shows the type of code to be generated, for this case we are generating the client code. which clients</li><li>openapi.yamlspecify the path to the OpenAPI specification file used to generate code.</li><li>openapi.gen.go is the file where the generated code will be stored.</li></ul><p>For the first case, we are generating the code for the client library that is useful for sending requests to the API endpoints and handles the corresponding responses.</p><p><strong>Let&#39;s go through the generated code</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b47833f464fa43b97054216bb53a57f/href">https://medium.com/media/7b47833f464fa43b97054216bb53a57f/href</a></iframe><p>This is a struct representing the JSONRequest body for the user&#39;s signup endpoint. The struct contains fields that represent the properties of the JSON request body of the OpenAPI document.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7066aa0a174585c269d52682ebce383e/href">https://medium.com/media/7066aa0a174585c269d52682ebce383e/href</a></iframe><p>The client struct is generated from the servers field of the OpenAPI specification document. It represents a client that makes API requests to the Signup endpoint.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3561ab9b205707d21289a2b4ad4b7ae1/href">https://medium.com/media/3561ab9b205707d21289a2b4ad4b7ae1/href</a></iframe><p>This code defines a “NewClient” function that creates a new object “client” using the server URL including any specification of the “ClientOption” function. The “NewClient” function basically provides an easier way of creating a client that is able to interact with the API described by the OpenAPI document.</p><p><strong>The client interface</strong></p><p>Once the server is operational, we will likely want to send requests to it. The client serves the purpose of initiating requests to the server and handling the responses returned by the server.</p><p>A client is therefore generated in tandem with the schema in the OpenAPI document. This client is helpful in converting objects to JSON, and also applies the same functions and types of request handlers that ensures a seamless integration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef72cde32af74d528d698c7ece234eaa/href">https://medium.com/media/ef72cde32af74d528d698c7ece234eaa/href</a></iframe><p><strong>Generating the server code only</strong></p><p>You might want to generate the server code only when you need to implement only the server-side operations of the API. This provides a foundation for handling incoming API requests and sending responses.</p><p>To generate the server code, navigate to the projects directory and paste the following command in the command line interface:</p><pre>oapi-codegen --package=main  --generate types,server openapi.yaml &gt; generatedserver.go<br></pre><blockquote>Remember to replace ‘openapi. yaml’ with your own OpenAPI file name and “exampleservercode” with your desired output file name when using the oapi-codegen command to generate the server code.</blockquote><p>Here is the output of the generated server code :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1d73f20cc45e220eae3df2bdfd83254/href">https://medium.com/media/c1d73f20cc45e220eae3df2bdfd83254/href</a></iframe><p><strong>Difference between the generated Client and Server code</strong></p><p>The generated client code can be used to make HTTP requests to the server as well as handle requests from the server while the server-generated code is useful in implementing the API endpoints that are specified in the OpenAPI specification document.</p><p><strong>Why opt for the oapi-codegen library?</strong></p><p>There are other code generators that we can use. They include the OpenAPI generator can also be used to generate both client and server code, Swagger Codegen, and Nswag.</p><p>However, in our case, we use the oapi-codegen library. This is because the oapi-codegen tool brings in several advantages when generating Go code. First, it automates the creation process thus enabling a faster development approach for the project. The code generated is of high quality as it is based on a standard specification. This is an open-source project and thus actively maintained, this provides for room improvement to the tool.</p><p><strong>Some Tips for Streamlining Your OpenAPI Workflow</strong></p><ul><li>Use tools like `gofmt` to properly format the generated code, this makes it easier to debug and also eliminates any formatting-related compiler warnings.</li><li>Utilize linters such as ` go lint ` and static analysis tools like `go vet` so as to check on the code quality and identify potential errors/bugs.</li></ul><p><strong>Conclusion</strong></p><p>In conclusion, it is clear that oapi-codegen is a very useful tool that generates Go code from OpenAPI specifications. Taking into account its flexibility and customization options, it enables developers to quickly generate high-quality code and streamline their workflow. The tool helps save time and focus on more important tasks of building and deploying your application.</p><p><strong><em>Main Takeaways</em></strong></p><ol><li>Generating code from OpenAPI specification enables an API-fast workflow approach for the task.</li><li>An oapi-codegen tool is an easy-to-use tool that is able to generate code with a few commands and within a shorter period of time. It only takes a few commands and that is how you get the generated code from the OpenAPI document.</li></ol><p><strong>Voila!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae225e49e970" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Git and GitHub]]></title>
            <link>https://medium.com/@MikeMwita/introduction-to-git-and-github-ed0b3344f7dd?source=rss-6a897e711657------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed0b3344f7dd</guid>
            <category><![CDATA[version-control-system]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[programmi]]></category>
            <dc:creator><![CDATA[Mike Mwita]]></dc:creator>
            <pubDate>Tue, 23 May 2023 16:36:03 GMT</pubDate>
            <atom:updated>2023-05-23T16:36:03.610Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pAkZNyJwzfqL9DKeKsKc1w.png" /><figcaption>Git and Github Logo image</figcaption></figure><p><strong>A comprehensive guide Git and GitHub</strong></p><p>Git and GitHub are essential tools for developers.</p><p><strong>What is Git</strong></p><blockquote>“Git is a free and open source distributed <strong>version control system</strong> designed to handle everything from small to very large projects with speed and efficiency”</blockquote><p>Git is a version control system- this means you are able to track changes in your code especially when working on a single project with a team. The changes made can be synched in each member&#39;s computer, making it easier to collaborate.</p><p><strong>Getting started with Git</strong></p><p><strong>Git</strong> is the <strong>tool</strong>, and <strong>GitHub</strong> is the <strong>service for projects that use Git</strong>.</p><p><strong>Git Working Areas</strong></p><p>Git maintains 3 local states for each file: <strong>working directory</strong>, <strong>staging area</strong>, and <strong>committed.</strong></p><p>Working directory — this is the local folder containing the project files on your machine.</p><p>The staging area acts as an intermediary between the working directory and the repository.</p><p>Repository — this is where your project is stored and you are able to access the complete history of your project.</p><p><strong>Getting Git on your machine</strong></p><p>In this tutorial, I will be using a Linux terminal Environment. The first step is to open a terminal interface and run the following command:</p><pre>sudo apt update<br>sudo apt upgrade<br>sudo apt install git</pre><p>What the above command does is that it fetches the necessary files and dependencies from the package repositories for use in Git.</p><p>To confirm a successful installation, you can execute the following command in your terminal:</p><pre>git --version</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*a8oVVTZoACF1LnKIp30-dw.png" /></figure><p>For Windows users, installing Git is a straightforward process, one needs to download the latest version from the official Git website by clicking <a href="https://git-scm.com/download/win">https://git-scm.com/download/win</a>. Follow through the Git installer steps to complete the installation.</p><p><strong>Git Configuration</strong></p><p>This is a one-time activity. You are expected to provide Git with your identity information like Username and email.</p><pre>git config --global user.name &quot;Your Name&quot;<br>git config --global user.email &quot;your-email@example.com&quot;</pre><h3><strong>Git Workflow</strong></h3><p>Below is a simple workflow illustrating the fundamental Git concepts and steps involved in day-to-day working with Git.</p><h4><strong>Step 1: Initialize a Local Repository</strong></h4><p>Open your local terminal and navigate to the project directory using the change directory(cd) command. The directory can be a simple folder on your local machine. Run <strong><em>git init</em></strong> command to initialize the repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*uewOmqUpKCYLNTjO3fz3uw.png" /></figure><h4>Step 2: Adding a New File to the Repository</h4><p>Open your terminal or alternatively use the command prompt to create a new file in the repository we have just created. For our example, we’ll use the touch filename command to create a simple file.</p><p>For this tutorial, we use the Vim text editor to add some lines of code to the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*NU1dYLLgeCTciqiNuHwBEw.png" /></figure><p>In order to view the status of the repository, run the following command in your terminal:</p><pre>git status</pre><p>Here is the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*5OU_mebWNlCtkyGr9nwU5A.png" /></figure><p>This shows that the main.go file is an untracked file.</p><h4><strong>Step 3: Adding the File to the Staging Environment</strong></h4><p>In order to ensure Git tracks the file, run the command git add &lt;file&gt; .</p><p>The command git add. tracks all the changes in the current working directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*3UmW3krsckYzIhNpH3QCbg.png" /></figure><p>As you can see in the image above, the file main.go has now moved to the changes to be committed section.</p><h4><strong>Step 4: Committing the changes</strong></h4><p>A commit is basically a snapshot of the current files. When we need to permanently change the changes to the repository, we run the below command:</p><pre>git commit -m &quot;Commit message&quot;</pre><p>This comes after all the files have been added to the staging Environment, that’s when you tell Git to package them to a commit message.</p><blockquote>The commit message should reflect the changes you have made. This includes a clear and concise message that entails a well-crafted description of your changes. This is helpful to other programmers to understand what you have been working on.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*xCnZ59MEEV-s6_WJ_hzVlg.png" /></figure><h4><strong>Step 5: Working on Branches</strong></h4><p>From the Official Git Documentation, a branch is defined as :</p><p>“A branch in Git is simply a lightweight movable pointer to one of these commits. Every time you commit, it moves forward automatically.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*iTLXWk0TCmTA9reQJDJgCg.png" /><figcaption>Git branch diagram: Atlassian.com</figcaption></figure><p>Imagine you are working on a project and you need to come up with a new feature but you are skeptical about making changes directly to the main project, this is where branches come in handy. A branch is a line of development.</p><p>Creating a branch will enable you to work on the new feature seamlessly. Once you are satisfied with the changes, you can merge the changes to the main branch.</p><p>To create a new branch, run the following command in your terminal:</p><pre>git checkout -b &lt;my-branch-name&gt;</pre><p>This command creates a new branch and straight away switches you to the new branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*9J6WZIyQmFsbPfAIcQZxSw.png" /></figure><p>In order to verify the name of the branch you are currently on, you can always use the command:</p><pre>git branch</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*BEo3OsE1siQUbfOmKoqPzA.png" /></figure><blockquote>The asterisk(*) symbol indicates the branch you are on.</blockquote><p>Other branch commands include:</p><ul><li>git merge destination-branch: applies changes from the current branch to the destination branch.</li><li>git branch -d existing-branch: Delete existing-branch</li></ul><p>Branches can be prefixed to provide additional context. Some of the common branch prefixes include:</p><ul><li>feature: e.g. feature/users-login</li><li>bugfix: e.g. bugfix/users-not-able-to-log-in</li><li>hotfix: Providing a quick fix in production e.g. hotfix/kafka-failing</li><li>release: Refers to a version delivered to the users. e.g release/2.1.0</li></ul><h4><strong>Step 6: Create a New Repository on GitHub</strong></h4><p><strong>What is GitHub?</strong></p><p>GitHub is a platform for hosting and collaborating on Git repositories. It is basically a hosting service for Git repositories.</p><p>Below is the definition of Github from Github&#39;s official Documentation:</p><blockquote>“GitHub is a <strong>web-based</strong> Git repository <strong>hosting service</strong>, which offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features.”</blockquote><p>This step requires you to log in to your Github Account and on the homepage, select ‘New Repository’.Thereafter choose a reflective name for your repository which is concise and easy to understand.</p><p>This repository will create a central location to store and maintain your code remotely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*PhPLo9-GB8wrAQiCcQR1DQ.png" /></figure><h4><strong>Step 7: Push Branch to Github</strong></h4><p>Before we can push the code from our local repository(Git) we need to connect it with the remote repository(Github). We do this by running the below command:</p><pre>git remote add origin  &lt;url&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*NxbdqLlkVbhlBRQJd2UXuQ.png" /></figure><p>This command adds a new repository called origin and associates with the URL which points to the GitHub remote repository.</p><p>We can now push the code to the remote repository using the push command below:</p><pre>git push -u origin &lt;branch-name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*ho-FD--5Srz-F0lOQ_qQsw.png" /></figure><p>We have successfully pushed our code to a new branch called pointers in the remote repository.</p><p>We can now go back to the Github website and reload the browser and we are able to see a notification that our branch has recent changes.</p><h4><strong>Step 8: Create a Pull Request</strong></h4><p>When working as a team on a project, Pull Requests are one of the most exciting phases of collaboration. They serve as formal notifications of what you have been able to implement. The person reviewing the project is able to review your changes and offer constructive feedback.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*etpRza5JcqhRel9QAYoaAw.png" /></figure><p>Here we are creating a Pull Request of our pointers branch, taking the base branch to be the <strong>develop</strong> branch. What this means is that after reviewing the code, our <strong>pointers</strong> branch code will be merged with the <strong>develop</strong> branch code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wsJV_HKy_KUThbw2Irnj5w.png" /></figure><p>The above interface allows you to write the PR title and a summary of the changes you have made. At the right-hand end, you are able to add Reviewers who will be notified of your PR request and be able to review your changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2tYECXbfs-PoIB1aDQx4sw.png" /></figure><p>At this point, we have successfully created the Pull Request and the Reviewer is able to after a successful review of your changes, merge the PR, and the Pull request is closed. You can choose to keep or delete the branch thereafter.</p><h4><strong>Step 8: Bringing Back the Changes</strong></h4><p>This step is always important especially when working as a team. You need to update your local machine with changes made by other team members. You want to have the latest and updated work.</p><p>Run the following command in your terminal:</p><pre>git fetch --all</pre><p>This command retrieves the latest changes from all the remote branches in your repository. This allows you to stay in sync with the latest changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*2Sg1PvzanNv8lsvdDKe2cg.png" /></figure><p>Thereafter, you can fetch and merge the changes on your machine. We use the below command:</p><pre>git pull </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*g_GoQ50oCRv3gs624xyF-Q.png" /></figure><p>In order to see all the commits made you can use the git log command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*_wPucT4gFsAkU6YJgK6o5w.png" /></figure><p><strong>Step 11: Embrace Your Git Mastery</strong></p><p>There is more to Git beyond what has been covered in this article. While the article lays emphasis on the essential aspects of day-to-day operations, there is much more to explore.</p><p>For a more in-depth understanding of Git’s capabilities, I recommend checking out the following resources:</p><ul><li><a href="https://git-scm.com/docs">Reference</a></li><li><a href="https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud">Learn Git with Bitbucket Cloud | Atlassian Git Tutorial</a></li></ul><p>https://education.github.com/git-cheat-sheet-education.pdf</p><p><strong>Git With It!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed0b3344f7dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>