<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ivan Dachev</title>
    <description>The latest articles on DEV Community by Ivan Dachev (@idachev).</description>
    <link>https://dev.to/idachev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1968544%2Ff35d2e2b-69f4-4d82-a12c-0f96f63c6fe0.jpg</url>
      <title>DEV Community: Ivan Dachev</title>
      <link>https://dev.to/idachev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/idachev"/>
    <language>en</language>
    <item>
      <title>OpenAPI Trimmer Python Tool</title>
      <dc:creator>Ivan Dachev</dc:creator>
      <pubDate>Fri, 23 Aug 2024 09:34:22 +0000</pubDate>
      <link>https://dev.to/idachev/openapi-trimmer-python-tool-49j4</link>
      <guid>https://dev.to/idachev/openapi-trimmer-python-tool-49j4</guid>
      <description>&lt;h3&gt;
  
  
  Simplifying Your OpenAPI Files with OpenAPI Trimmer
&lt;/h3&gt;

&lt;p&gt;Managing large OpenAPI files can be a hassle, especially when you only need a small portion of the API for specific tasks. This is where &lt;strong&gt;OpenAPI Trimmer&lt;/strong&gt; comes in handy. It's a lightweight tool designed to trim down your OpenAPI files to include only the endpoints and data transfer objects (DTOs) you care about.&lt;/p&gt;

&lt;h4&gt;
  
  
  How Does It Work?
&lt;/h4&gt;

&lt;p&gt;Let's say you're working with a large OpenAPI file, but you only need the endpoints related to the Quotes API. You can easily extract just those endpoints and remove irrelevant DTOs with a single command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;openapi-trimmer &lt;span class="nt"&gt;-i&lt;/span&gt; openapi.yaml &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-p&lt;/span&gt; /v1/quotes,/v1/users &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-ec&lt;/span&gt; CompanyConfigDto,UpdateCompanyConfigDto
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;-i openapi.yaml&lt;/strong&gt;: Use your existing OpenAPI YAML file as input.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-p /v1/quotes,/v1/users&lt;/strong&gt;: Keep only the endpoints starting with &lt;code&gt;/v1/quotes&lt;/code&gt; and &lt;code&gt;/v1/users&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-ec CompanyConfigDto,UpdateCompanyConfigDto&lt;/strong&gt;: Exclude specific components, in this case, the &lt;code&gt;CompanyConfigDto&lt;/code&gt;, and &lt;code&gt;UpdateCompanyConfigDto&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The trimmed API definition will be saved as &lt;code&gt;openapi-trimmer.yaml&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Validation
&lt;/h4&gt;

&lt;p&gt;To ensure the integrity of your trimmed OpenAPI file, validate it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;swagger-cli validate ./openapi-trimmer.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This step helps catch any issues before you deploy or share the trimmed API file.&lt;/p&gt;

&lt;h4&gt;
  
  
  Installation
&lt;/h4&gt;

&lt;p&gt;You can install OpenAPI Trimmer directly from PyPi:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;openapi-trimmer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more details and the latest updates, visit the &lt;a href="https://pypi.org/project/openapi-trimmer/" rel="noopener noreferrer"&gt;OpenAPI Trimmer PyPi page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;GitHub repository: &lt;a href="https://github.com/idachev/openapi-trimmer" rel="noopener noreferrer"&gt;OpenAPI Trimmer on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Command-Line Options
&lt;/h4&gt;

&lt;p&gt;The OpenAPI Trimmer offers several options to customize its operation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;-h, --help&lt;/strong&gt;: Show help information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-v, --version&lt;/strong&gt;: Display the version number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-i INPUT, --input INPUT&lt;/strong&gt;: Specify the input YAML file (required).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-o OUTPUT, --output OUTPUT&lt;/strong&gt;: Define the output file name (optional; defaults to appending '-trimmed' to the input file).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-p PREFIXES, --prefixes PREFIXES&lt;/strong&gt;: List the paths to retain in the output (comma-separated).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;-ec EXCLUDE_COMPONENTS, --exclude-components EXCLUDE_COMPONENTS&lt;/strong&gt;: List the components to exclude (comma-separated).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;OpenAPI Trimmer is an essential tool for developers looking to streamline their OpenAPI files, making them more manageable and tailored to specific needs. Whether you're preparing API documentation or simplifying an API for internal use, OpenAPI Trimmer saves you time and effort by focusing only on what matters most to you.&lt;/p&gt;

</description>
      <category>openai</category>
      <category>python</category>
      <category>pip</category>
      <category>cli</category>
    </item>
  </channel>
</rss>
