<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Swift Architecture and OpenAPI</title>
<link>https://aleahim.com/</link>
<description>Building a full OpenAPI workflow on top of the Extreme Packaging architecture.</description>
<language>en-US</language>
<atom:link href="https://aleahim.com/collections/openapi/feed.xml" rel="self" type="application/rss+xml"/>
<item>
<title>Validations Are Values</title>
<link>https://aleahim.com/blog/validations-are-values/</link>
<guid isPermaLink="true">https://aleahim.com/blog/validations-are-values/</guid>
<pubDate>Sat, 13 Jun 2026 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>Most validation code is one giant function that walks a tree and appends to an error array through a forest of if statements. OpenAPIKit showed me a better way, a validation is a small composable value, the description states the correct state, and every error already knows where it lives</description>
<content:encoded><![CDATA[<h1>Validations Are Values</h1>
<p>Here is the validation function almost everyone writes the first time. You have a parsed model. You want to check it. So you write this:</p>
<pre><code class="language-swift"><span class="tok-keyword">func</span> <span class="tok-function">validate</span>(_ document<span class="tok-operator">:</span> <span class="tok-type">Document</span>) <span class="tok-keyword">throws</span> {
    <span class="tok-keyword">var</span> errors<span class="tok-operator">:</span> [<span class="tok-type">String</span>] <span class="tok-operator">=</span> []
    <span class="tok-keyword">if</span> document<span class="tok-operator">.</span>servers<span class="tok-operator">.</span>is<span class="tok-type">Empty</span> {
        errors<span class="tok-operator">.</span><span class="tok-function">append</span>(<span class="tok-string">"document has no servers"</span>)
    }
    <span class="tok-keyword">for</span> (path, item) <span class="tok-keyword">in</span> document<span class="tok-operator">.</span>paths {
        <span class="tok-keyword">for</span> (method, operation) <span class="tok-keyword">in</span> item<span class="tok-operator">.</span>operations {
            <span class="tok-keyword">if</span> operation<span class="tok-operator">.</span>responses<span class="tok-operator">.</span>is<span class="tok-type">Empty</span> {
                errors<span class="tok-operator">.</span><span class="tok-function">append</span>(<span class="tok-string">"\(method) \(path) has no responses"</span>)
            }
            <span class="tok-keyword">for</span> variable <span class="tok-keyword">in</span> operation<span class="tok-operator">.</span>server<span class="tok-operator">?</span><span class="tok-operator">.</span>url<span class="tok-type">Template</span><span class="tok-operator">.</span>variables <span class="tok-operator">?</span><span class="tok-operator">?</span> [] {
                <span class="tok-keyword">if</span> <span class="tok-operator">!</span>operation<span class="tok-operator">.</span>server<span class="tok-operator">!</span><span class="tok-operator">.</span>variables<span class="tok-operator">.</span>keys<span class="tok-operator">.</span><span class="tok-function">contains</span>(variable) {
                    errors<span class="tok-operator">.</span><span class="tok-function">append</span>(<span class="tok-string">"\(path) uses undefined variable \(variable)"</span>)
                }
            }
        }
    }
    <span class="tok-comment">// ... three hundred more lines ...</span>
    <span class="tok-keyword">if</span> <span class="tok-operator">!</span>errors<span class="tok-operator">.</span>is<span class="tok-type">Empty</span> { <span class="tok-keyword">throw</span> <span class="tok-type">ValidationError</span>(errors) }
}</code></pre>
<p>It works. It also rots. Every new rule is another branch wedged into the same traversal. The error strings drift out of sync with the checks. Nobody can test a single rule in isolation, because there is no single rule, there is only the function. You cannot turn one check off without commenting out code. And the location of each failure is whatever you remembered to interpolate into the string, which is to say, inconsistent and usually wrong.</p>
<p>I stopped writing validators like this when I read <a href="https://github.com/mattpolzin/OpenAPIKit">Matt Polzin’s OpenAPIKit</a>. His validation layer is the cleanest I have seen in Swift, and the core idea is one sentence:</p>
<p><strong>A validation is not code you run. It is a value you build.</strong></p>
<p>Once you take that seriously, everything else follows. This post is the whole idiom, distilled from how OpenAPIKit actually does it. I now hold every validation layer I write to it.</p>
<h2>What OpenAPIKit is</h2>
<p><a href="https://github.com/mattpolzin/OpenAPIKit">OpenAPIKit</a> is a Swift library for reading, writing, and validating <a href="https://openapis.org">OpenAPI</a> documents. OpenAPI is the specification format that describes an HTTP API: its paths, operations, request and response bodies, schemas, servers, and components. The documents are usually written as large YAML or JSON files.</p>
<p>OpenAPIKit gives you three things, layered cleanly on top of each other:</p>
<ol><li><p><strong>A typed model of the entire OpenAPI specification.</strong> Every construct in the spec, <code>OpenAPI.Document</code>, <code>OpenAPI.PathItem</code>, <code>Operation</code>, <code>Response</code>, <code>Server</code>, <code>JSONSchema</code>, and the rest, is a real Swift type. Not a <code>[String: Any]</code> you index into and pray. A real type with real fields, so the compiler knows the shape of an OpenAPI document.</p></li><li><p><strong><code>Codable</code> conformance over that model.</strong> Because the model is <code>Codable</code>, you decode a YAML or JSON spec straight into <code>OpenAPI.Document</code> and encode it back out. The decoder is where the first wall of correctness lives: a document that is not even shaped like OpenAPI fails to decode at all. This is the “parse first” pass.</p></li><li><p><strong>A validation subsystem over the decoded model.</strong> This is the part this post is about. Once you have a decoded <code>OpenAPI.Document</code>, you run a <code>Validator</code> over it to catch the semantic errors that decoding alone cannot: a <code>$ref</code> that points at a component that does not exist, an operation with no responses, a server URL template that uses a variable nobody defined. These are valid OpenAPI <em>syntax</em> describing an invalid <em>document</em>.</p></li></ol>
<p>The validation code lives under <code>Sources/OpenAPIKit/Validator/</code>. The files worth reading are <code>Validation.swift</code> (the atom), <code>Validator.swift</code> (the engine and the default set), <code>Validation+Builtins.swift</code> (the shipped rules), and <code>ReferenceValidations.swift</code> (the reference-resolution rules). The tests under <code>Tests/OpenAPIKitTests/Validator/</code> are as instructive as the source, and I will come back to them.</p>
<p>How you actually use it is three lines:</p>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">OpenAPIKit</span>
<span class="tok-keyword">import</span> <span class="tok-type">Yams</span>

<span class="tok-keyword">let</span> document <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-type">YAMLDecoder</span>()<span class="tok-operator">.</span><span class="tok-function">decode</span>(<span class="tok-type">OpenAPI</span><span class="tok-operator">.</span><span class="tok-type">Document</span><span class="tok-operator">.</span><span class="tok-keyword">self</span>, from<span class="tok-operator">:</span> yaml<span class="tok-type">String</span>)
<span class="tok-keyword">try</span> document<span class="tok-operator">.</span><span class="tok-function">validate</span>()   <span class="tok-comment">// throws a ValidationErrorCollection if anything is wrong</span></code></pre>
<p>The first line is the parse pass. The second is the validate pass. Everything below is how that second line is built, and why it is built the way it is.</p>
<h2>Parse first, validate second</h2>
<p>The first move happens before any validation runs at all. Parsing and validation are two passes, not one.</p>
<p>The parser’s job is to turn bytes into a well typed value and to make as many illegal states as it can simply unrepresentable. An enum cannot hold a case that does not exist. A non-optional field cannot be missing. By the time you have a parsed <code>Document</code>, a whole category of “errors” is gone, because the type system refused to let them exist.</p>
<p>Validation runs <em>after</em> that, over the already typed value. It catches only what the types cannot or should not enforce: a server template that references a variable nobody defined, an operation with zero responses, a reference that points at a component that is not in the document. These are not type errors. They are semantic ones. They need their own pass.</p>
<p>If you find yourself validating inside the parser, stop. Parse to a clean value. Then validate the value.</p>
<h2>A validation is a small struct of closures</h2>
<p>Here is the atom. A <code>Validation</code> over some subject type carries three things:</p>
<ul><li><p>a <strong>description</strong> string,</p></li><li><p>a <strong>check</strong> that produces errors,</p></li><li><p>a <strong>predicate</strong> that decides whether this rule even applies here.</p></li></ul>
<p>That is it. No inheritance, no protocol with ten requirements. A plain value you can build, store in an array, pass around, and combine.</p>
<p>The simplest one reads almost like English:</p>
<pre><code class="language-swift"><span class="tok-keyword">public</span> <span class="tok-keyword">static</span> <span class="tok-keyword">var</span> operations<span class="tok-type">ContainResponses</span><span class="tok-operator">:</span> <span class="tok-type">Validation</span><span class="tok-operator">&lt;</span><span class="tok-type">Operation</span><span class="tok-operator">&gt;</span> {
    <span class="tok-operator">.</span><span class="tok-keyword">init</span>(
        description<span class="tok-operator">:</span> <span class="tok-string">"Operations contain at least one response"</span>,
        check<span class="tok-operator">:</span> \<span class="tok-operator">.</span>responses<span class="tok-operator">.</span>count <span class="tok-operator">&gt;</span> <span class="tok-number">0</span>
    )
}</code></pre>
<p>Look at what is not there. There is no traversal. This rule does not know how to find <code>Operation</code> values in a document, and it does not care. It only knows what a correct <code>Operation</code> looks like. The machinery finds every operation in the tree and offers each one to this rule. Dispatch is directed by the subject type: a <code>Validation&lt;Operation&gt;</code> fires on operations, wherever they appear, and is invisible to everything else.</p>
<h2>The description states the correct state, never the failure</h2>
<p>Read that description again: “Operations contain at least one response.” Positive. It describes the world when the rule is satisfied, not the world when it breaks.</p>
<p>This is deliberate, and it is one of my favorite details. You write the description once, phrased positively. When the rule fails, the framework derives the failure message by prefixing <code>"Failed to satisfy: "</code>. So you get:</p>
<blockquote><p>Failed to satisfy: Operations contain at least one response</p></blockquote>
<p>One source of truth, two readings. You never write the failure phrasing by hand, so the check and its message can never drift apart. Compare that to the if-tree above, where <code>if responses.isEmpty</code> and the string <code>"has no responses"</code> are two independent things you have to keep in agreement forever.</p>
<p>The description does more than format messages. It is the rule’s <strong>identity</strong>. Because rules are removed by matching their description, the description must be unique and stable. Which leads to the next piece.</p>
<h2>Every error knows where it lives</h2>
<p>An error is a reason plus a location:</p>
<pre><code class="language-swift"><span class="tok-type">ValidationError</span>(reason<span class="tok-operator">:</span> <span class="tok-string">"Server Object does not define the variable 'x'"</span>, at<span class="tok-operator">:</span> context<span class="tok-operator">.</span>coding<span class="tok-type">Path</span>)</code></pre>
<p>You supply the reason. You do <em>not</em> supply the location by hand. The traversal fills in the coding path as it walks, so by the time your check runs, <code>context.codingPath</code> already says exactly where in the tree you are. The rendered message comes out consistent every time:</p>
<blockquote><p>… at path: .paths./hello/world.get.servers</p></blockquote>
<p>or, at the top:</p>
<blockquote><p>… at root of document</p></blockquote>
<p>No more interpolating <code>\(path).\(method)</code> into strings and getting it subtly wrong. The path is bookkeeping the framework owns, not you.</p>
<h2>Application is predicate gated</h2>
<p>Every validation has a <code>when:</code> predicate that runs before the check, with the full context in hand. The default is “always.” But when a rule should only apply to a subset, you scope it with the predicate, not with an <code>if</code> inside the check body.</p>
<p>This matters because it keeps the check pure. The check answers “is this value correct,” full stop. The predicate answers “does this rule even apply here,” separately. A rule that only applies to OpenAPI 3.1 documents, or only to operations at a certain path, or only when some other field is present, says so in <code>when:</code> and keeps its check clean. Conditionals do not leak into the logic that decides pass or fail.</p>
<h2>Two shapes, by how a value can fail</h2>
<p>There are two ways to author the check, and the choice is mechanical.</p>
<p>If a value can fail <strong>one way</strong>, use the Bool form. You give a positive description and a predicate; <code>false</code> yields exactly one error, auto-formatted from the description. That <code>operationsContainResponses</code> rule above is this form. It is the dominant case.</p>
<p>If a single value can fail in <strong>several places at once</strong>, use the multi-error form and return one <code>ValidationError</code> per offender:</p>
<pre><code class="language-swift"><span class="tok-keyword">public</span> <span class="tok-keyword">static</span> <span class="tok-keyword">var</span> server<span class="tok-type">VariablesAreDefined</span><span class="tok-operator">:</span> <span class="tok-type">Validation</span><span class="tok-operator">&lt;</span><span class="tok-type">Server</span><span class="tok-operator">&gt;</span> {
    <span class="tok-operator">.</span><span class="tok-keyword">init</span>(
        description<span class="tok-operator">:</span> <span class="tok-string">"All server template variables are defined"</span>,
        check<span class="tok-operator">:</span> { context <span class="tok-keyword">in</span>
            context<span class="tok-operator">.</span>subject<span class="tok-operator">.</span>url<span class="tok-type">Template</span><span class="tok-operator">.</span>variables
                <span class="tok-operator">.</span>filter { <span class="tok-operator">!</span>context<span class="tok-operator">.</span>subject<span class="tok-operator">.</span>variables<span class="tok-operator">.</span><span class="tok-function">contains</span>(key<span class="tok-operator">:</span> $<span class="tok-number">0</span>) }
                <span class="tok-operator">.</span>map { name <span class="tok-keyword">in</span>
                    <span class="tok-type">ValidationError</span>(
                        reason<span class="tok-operator">:</span> <span class="tok-string">"Server Object does not define the variable '\(name)'"</span>,
                        at<span class="tok-operator">:</span> context<span class="tok-operator">.</span>coding<span class="tok-type">Path</span>
                    )
                }
        }
    )
}</code></pre>
<p>A server with three undefined variables produces three errors, each with its own reason and its own path. You do not collapse them into one “server is invalid” message, because then you would lose two thirds of the information about what to fix. The rule emits one error per problem.</p>
<h2>A default set you can add to and subtract from</h2>
<p>You ship two validators: a populated one with a curated default set, and a <code>blank</code> one with nothing. Builders are fluent and chainable. You compose your actual policy from the defaults, plus your own rules, minus the ones you do not want:</p>
<pre><code class="language-swift"><span class="tok-keyword">let</span> validator <span class="tok-operator">=</span> <span class="tok-type">Validator</span>()                       <span class="tok-comment">// the defaults</span>
    <span class="tok-operator">.</span><span class="tok-function">validating</span>(<span class="tok-operator">.</span>operations<span class="tok-type">ContainResponses</span>)      <span class="tok-comment">// add a builtin by name</span>
    <span class="tok-operator">.</span><span class="tok-function">validating</span>(my<span class="tok-type">CustomRule</span>)                      <span class="tok-comment">// add your own</span>
    <span class="tok-operator">.</span><span class="tok-function">withoutValidating</span>(<span class="tok-string">"All server template variables are defined"</span>)  <span class="tok-comment">// remove one by its description</span></code></pre>
<p>This is why descriptions have to be unique and stable: the description <em>is</em> the removal key. <code>withoutValidating</code> matches on it. Rename a rule’s description and you have quietly changed its identity.</p>
<p>When strictness comes in grades, you model the grades as whole-set swaps on the validator, not as flags threaded through individual rules. OpenAPIKit does lenient reference checks by default, swaps in the strict set with <code>validatingAllReferencesFoundInComponents()</code>, and clears them with <code>skippingReferenceValidations()</code>. Three named configurations, not a <code>strict: Bool</code> smuggled into every check.</p>
<h2>The combinator algebra</h2>
<p>Because validations and their checks are values, you combine them with an algebra instead of nesting <code>if</code> statements. These are the moves I reach for:</p>
<ul><li><p><strong><code>&amp;&amp;</code> / <code>||</code></strong> combine checks. <code>&amp;&amp;</code> concatenates both error lists; <code>||</code> short-circuits and only fails if both sides fail.</p></li><li><p><strong>comparison operators</strong> (<code>==</code>, <code>&gt;</code>, <code>&gt;=</code>, and friends) lift a key path and a literal into a predicate, so <code>check: \.responses.count &gt; 0</code> is a real expression, not a closure you wrote by hand.</p></li><li><p><strong><code>take(\.path) { value in ... }</code></strong> digs to a value and runs arbitrary logic past simple equality.</p></li><li><p><strong><code>lift(\.child, into: ...)</code></strong> runs child-typed validations against a child value while keeping the parent’s path and document. This is the key compositional move for nested structure.</p></li><li><p><strong><code>unwrap(\.optional, into:description:)</code></strong> unwraps an optional, erroring if nil, otherwise running child validations on the unwrapped value.</p></li><li><p><strong><code>lookup</code> / <code>unwrapAndLookup</code></strong> resolve a reference against the document’s component store, error if it is not found, otherwise validate the resolved value.</p></li><li><p><strong><code>all(validations...)</code></strong> applies many validations to the same context.</p></li></ul>
<p>So a compound rule reads declaratively:</p>
<pre><code class="language-swift">check<span class="tok-operator">:</span> \<span class="tok-operator">.</span>response<span class="tok-type">Outcomes</span><span class="tok-operator">.</span>count <span class="tok-operator">&gt;</span><span class="tok-operator">=</span> <span class="tok-number">1</span>
    <span class="tok-operator">&amp;</span><span class="tok-operator">&amp;</span> { $<span class="tok-number">0.</span>subject<span class="tok-operator">.</span>response<span class="tok-type">Outcomes</span><span class="tok-operator">.</span>all<span class="tok-type">Satisfy</span> { $<span class="tok-number">0.</span>status <span class="tok-operator">=</span><span class="tok-operator">=</span> <span class="tok-number">200</span> } }</code></pre>
<p>You are describing what correct looks like by composing pieces, not writing a traversal.</p>
<h2>Test the rules, the machinery, and the set</h2>
<p>The test style mirrors the philosophy, and OpenAPIKit’s bar here is the part most people skip. There are three layers to it.</p>
<p><strong>Every rule gets a failing and a succeeding test.</strong> Not just “here is a broken document, does it throw.” Also “here is a document that <em>almost</em> trips the rule but does not.” The succeeding fixture is a near miss, the value sitting exactly at the boundary the rule guards. A rule tested only in its failing direction is untested, because nothing proves it stays quiet on valid input. Assert the thrown collection’s exact count, each reason (including the <code>"Failed to satisfy: "</code> prefix), and each coding path:</p>
<pre><code class="language-swift"><span class="tok-keyword">func</span> <span class="tok-function">test_serverCountCheckFails</span>() {
    <span class="tok-keyword">let</span> document <span class="tok-operator">=</span> <span class="tok-comment">// ... seed the failing case</span>
    <span class="tok-keyword">let</span> validator <span class="tok-operator">=</span> <span class="tok-type">Validator</span><span class="tok-operator">.</span>blank
        <span class="tok-operator">.</span><span class="tok-function">validating</span>(<span class="tok-string">"All server arrays have more than 1 server"</span>, check<span class="tok-operator">:</span> \[<span class="tok-type">Server</span>]<span class="tok-operator">.</span>count <span class="tok-operator">&gt;</span> <span class="tok-number">1</span>)
    <span class="tok-type">XCTAssertThrowsError</span>(<span class="tok-keyword">try</span> document<span class="tok-operator">.</span><span class="tok-function">validate</span>(using<span class="tok-operator">:</span> validator)) { error <span class="tok-keyword">in</span>
        <span class="tok-keyword">let</span> error <span class="tok-operator">=</span> error <span class="tok-keyword">as</span><span class="tok-operator">?</span> <span class="tok-type">ValidationErrorCollection</span>
        <span class="tok-type">XCTAssertEqual</span>(error<span class="tok-operator">?</span><span class="tok-operator">.</span>values<span class="tok-operator">.</span>count, <span class="tok-number">1</span>)
        <span class="tok-type">XCTAssertEqual</span>(error<span class="tok-operator">?</span><span class="tok-operator">.</span>values<span class="tok-operator">.</span>first<span class="tok-operator">?</span><span class="tok-operator">.</span>reason,
                       <span class="tok-string">"Failed to satisfy: All server arrays have more than 1 server"</span>)
        <span class="tok-type">XCTAssertEqual</span>(error<span class="tok-operator">?</span><span class="tok-operator">.</span>values<span class="tok-operator">.</span>first<span class="tok-operator">?</span><span class="tok-operator">.</span>coding<span class="tok-type">Path</span><span class="tok-operator">.</span><span class="tok-function">map</span>(\<span class="tok-operator">.</span>string<span class="tok-type">Value</span>),
                       [<span class="tok-string">"paths"</span>, <span class="tok-string">"/hello/world"</span>, <span class="tok-string">"get"</span>, <span class="tok-string">"servers"</span>])
    }
}</code></pre>
<p><strong>The machinery gets its own negative tests.</strong> The type-erased wrapper that filters by runtime type has to be proven correct on its own: an optional subject yields no errors, a wrong type yields no errors, a false predicate yields no errors. And one positive control, the same value of the same type appearing twice yields two errors, to prove those negatives are not vacuously passing.</p>
<p><strong>The configuration is pinned.</strong> A test asserts the exact, ordered list of active rule descriptions for every validator configuration. <code>blank</code> is empty. The full default set is pinned description by description. This means you cannot add, remove, or reword a rule without a test failing first, which forces every such change to be deliberate rather than accidental.</p>
<p>The point of all this is that a validator can pass every test it ships and still be incomplete, if some field of the input model never got a rule at all. So the final discipline is a coverage law: keep a registry of every field the model can carry, and a meta-test that fails if any field lacks either a validation or an explicit “unsupported, and here is why” classification. Silent gaps get caught mechanically, not in review.</p>
<h2>Why I hold everything to this now</h2>
<p>I do not treat this as an OpenAPI trick. I treat it as the standard for any validation layer over any parsed model: a config, a manifest, an HTML tree, a schema, a feature model. One framework, parameterized over both the subject and the document, reused by every layer instead of copied per layer. Each rule a named, removable, isolation-testable value with a positive description. Errors that carry their own location. Combinators instead of conditionals.</p>
<p>The if-tree at the top of this post produces correct results. That is not the bar. The bar is whether you can add a rule without touching a three-hundred-line function, turn one off by name, test it alone, and trust that its failure message points at the right place. The if-tree fails all four. Validations as values pass all four, and they do it because the design made the right thing the easy thing.</p>
<p>Parse first. Then build your validations as values.</p>
<hr>
<p>Credit where it is due: this entire idiom is <a href="https://github.com/mattpolzin/OpenAPIKit">Matt Polzin’s</a>. Go read <code>Sources/OpenAPIKit/Validator/</code>. It is some of the most quietly excellent Swift in the ecosystem.</p>]]></content:encoded>
</item>
<item>
<title>OpenAPIDoctor WebAssembly readiness</title>
<link>https://aleahim.com/blog/openapi-doctor-webassembly-readiness/</link>
<guid isPermaLink="true">https://aleahim.com/blog/openapi-doctor-webassembly-readiness/</guid>
<pubDate>Fri, 05 Jun 2026 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>A first compiler-grounded check of whether OpenAPIDoctor can become a local-first browser tool.</description>
<content:encoded><![CDATA[<h1>OpenAPIDoctor WebAssembly readiness</h1>
<p>I want OpenAPIDoctor to become a no-backend browser tool.</p>
<p>The product shape is right. A user should be able to paste or upload an OpenAPI
spec, run the same strict Swift validator locally in the browser, see structured
diagnostics, repair the safe cases, and download the fixed spec. No upload. No
server. No account.</p>
<p>The only honest way to test that idea is to ask the compiler.</p>
<h2>What I tested</h2>
<p>Native build first:</p>
<pre><code class="language-bash">swift build</code></pre>
<p>That passed with Apple Swift 6.2.</p>
<p>Then I tested the installed WASI SDK:</p>
<pre><code class="language-bash">swift build \
  <span class="tok-operator">-</span><span class="tok-operator">-</span>target OpenAPIDoctor \
  <span class="tok-operator">-</span><span class="tok-operator">-</span>swift<span class="tok-operator">-</span>sdk <span class="tok-number">6.2</span><span class="tok-operator">-</span>RELEASE<span class="tok-operator">-</span>wasm<span class="tok-number">32</span><span class="tok-operator">-</span>unknown<span class="tok-operator">-</span>wasip<span class="tok-number">1</span> \
  <span class="tok-operator">-</span><span class="tok-operator">-</span>scratch<span class="tok-operator">-</span>path <span class="tok-operator">/</span>tmp<span class="tok-operator">/</span>openapidoctor<span class="tok-operator">-</span>wasm<span class="tok-operator">-</span>library</code></pre>
<p>And the CLI shape:</p>
<pre><code class="language-bash">swift build \
  <span class="tok-operator">-</span><span class="tok-operator">-</span>product openapi<span class="tok-operator">-</span>doctor \
  <span class="tok-operator">-</span><span class="tok-operator">-</span>swift<span class="tok-operator">-</span>sdk <span class="tok-number">6.2</span><span class="tok-operator">-</span>RELEASE<span class="tok-operator">-</span>wasm<span class="tok-number">32</span><span class="tok-operator">-</span>unknown<span class="tok-operator">-</span>wasip<span class="tok-number">1</span> \
  <span class="tok-operator">-</span><span class="tok-operator">-</span>scratch<span class="tok-operator">-</span>path <span class="tok-operator">/</span>tmp<span class="tok-operator">/</span>openapidoctor<span class="tok-operator">-</span>wasm<span class="tok-operator">-</span>cli</code></pre>
<p>Both failed before OpenAPIDoctor itself compiled.</p>
<h2>The blocker</h2>
<p>The first blocker is <code>Yams</code>, specifically its embedded <code>CYaml</code> C target:</p>
<pre><code class="language-text">error<span class="tok-operator">:</span> unable to create target<span class="tok-operator">:</span>
<span class="tok-string">'No available targets are compatible with triple "wasm32-unknown-wasip1"'</span></code></pre>
<p>I confirmed it directly by building <code>Yams</code> for the same SDK. It fails in the C
parser files: <code>parser.c</code>, <code>reader.c</code>, <code>writer.c</code>, <code>api.c</code>, <code>emitter.c</code>, and
<code>scanner.c</code>.</p>
<p>I also tried a tiny C compile with the same target:</p>
<pre><code class="language-bash">clang <span class="tok-operator">-</span><span class="tok-operator">-</span>target<span class="tok-operator">=</span>wasm<span class="tok-number">32</span><span class="tok-operator">-</span>unknown<span class="tok-operator">-</span>wasip<span class="tok-number">1</span></code></pre>
<p>That failed with the same target-support error. So the current local toolchain
cannot compile the C YAML dependency to WASI.</p>
<h2>What this means</h2>
<p>OpenAPIDoctor is not WebAssembly-ready as it exists today.</p>
<p>That does not kill the idea. It narrows the work.</p>
<p>The core shape is still good:</p>
<ul><li><p><code>Validator.validate(yaml:)</code> already accepts an in-memory string.</p></li><li><p><code>Repairer.repair(yaml:)</code> already returns repaired YAML in memory.</p></li><li><p>The native CLI is just a composition layer around those APIs.</p></li><li><p>The right browser boundary is a WASI command: <code>stdin</code> in, diagnostics or files
out.</p></li></ul>
<p>The weak point is YAML infrastructure.</p>
<p>OpenAPIDoctor imports <code>Yams</code> in the validator, repairer, and synthesizer. It also
uses <code>Stitcher</code> for multi-file refs, and Stitcher depends on Yams too. That means
a browser build needs a YAML path that can cross to WASI.</p>
<h2>The next path</h2>
<p>There are three practical options.</p>
<ol><li><p>Test again inside the Linux SwiftWasm toolchain we use for the TileDown
playground builds. If that environment can compile C targets to WASI, then the
next blocker will be runtime behavior.</p></li><li><p>Replace or isolate the YAML layer behind a WebAssembly-friendly interface.
Single-file diagnosis could start with a smaller path before multi-file repair.</p></li><li><p>Add an OpenAPIDoctor WASI wrapper only after the dependency question is settled.
The wrapper should read the spec from <code>stdin</code> and write JSON diagnostics to
<code>stdout</code>.</p></li></ol>
<p>The browser product should not use custom JavaScript exports. The better pattern
is the same one that already works for the PDF playground:</p>
<pre><code class="language-text">stdin <span class="tok-operator">+</span> argv <span class="tok-operator">+</span> preopened files<span class="tok-operator">/</span>directories <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> stdout or output files</code></pre>
<p>That keeps the Swift code shaped like a normal command-line program and lets the
browser provide an in-memory filesystem.</p>
<h2>Current verdict</h2>
<p>OpenAPIDoctor is product-ready as a local-first browser idea, but not yet
compiler-ready for WebAssembly.</p>
<p>The first concrete task is not UI. It is a dependency build proof for
<code>OpenAPIKit</code>, <code>Yams</code>, and <code>Stitcher</code> under WASI. Only after that should the web
tool be wrapped as a TileDown WASM tile or a standalone site.</p>]]></content:encoded>
</item>
<item>
<title>Why I built OpenAPIDoctor</title>
<link>https://aleahim.com/blog/why-i-built-openapi-doctor/</link>
<guid isPermaLink="true">https://aleahim.com/blog/why-i-built-openapi-doctor/</guid>
<pubDate>Thu, 14 May 2026 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>OpenAPIKit&apos;s strict parser meets real-world specs. A typed diagnosis CLI with auto-repair, proven across 594 YAML files.</description>
<content:encoded><![CDATA[<h1>Why I built OpenAPIDoctor</h1>
<h2>“The given data was not valid YAML.”</h2>
<p>The first time I saw this error, the YAML was fine.</p>
<p>I had pasted ten kilobytes of perfectly formed OpenAPI into a generator, watched it crash, and squinted at a stack trace that very confidently told me my document was malformed. It wasn’t. The document was a well-indented, schema-valid spec that someone had hand-edited the week before. The actual problem was a single stray key on a <code>Tag</code> object, eleven levels down, which <code>OpenAPIKit</code> had quietly rejected and which <code>Yams</code> had then wrapped in a <code>DecodingError.dataCorrupted</code> carrying a debug message that had nothing to do with the actual cause. The real error lived in <code>Context.underlyingError</code>, three more layers in.</p>
<p>I lost an afternoon to that error. Then I lost a morning to it again, a week later, on a different spec. Then I built OpenAPIDoctor.</p>
<h2>What spec-first Swift gets you, and what it costs</h2>
<p>When you generate Swift code from an OpenAPI document, the document is no longer documentation that lags behind the code. It <em>is</em> the code. Apple’s <a href="https://github.com/apple/swift-openapi-generator"><code>swift-openapi-generator</code></a> reads the spec, runs it through <a href="https://github.com/mattpolzin/OpenAPIKit"><code>mattpolzin/OpenAPIKit</code></a>, and emits typed Swift clients and servers from what it finds. Spec parses cleanly, the generated code compiles. Spec has any structural issue OpenAPIKit doesn’t like, the generator either fails outright or emits code that won’t compile.</p>
<p>That contract is what makes spec-first Swift worth doing. It is also what makes the spec a load-bearing artifact that nobody can afford to hand-edit carelessly. Which, of course, everybody does.</p>
<p>OpenAPIKit is a strict parser by design. It does not silently round-trip unknown keys, because that would let bugs through into your generated client. The trouble is that real-world specs accumulate small violations the moment more than one person edits them, or the moment anyone copy-pastes a fragment from another tool. A short, honest taxonomy:</p>
<ul><li><p>A <code>Tag</code> object carrying a <code>slug:</code> field. Not part of the spec. Strict parser rejects it.</p></li><li><p>A <code>Parameter</code> with stray <code>email:</code> and <code>phone:</code> keys left behind by a half-finished refactor. Strict parser rejects them.</p></li><li><p><code>nullable: true</code> on a spec that has been migrated to OpenAPI 3.1, where the keyword is no longer valid. Strict parser rejects it.</p></li><li><p>A response body declaring <code>application/x-www-form-urlencoded</code>, which the Swift OpenAPI runtime cannot serve. Parser accepts it; the runtime explodes downstream and writes you a different kind of letter.</p></li></ul>
<p>Each violation is small. None is the sort of structural problem a code review catches. All of them surface as <code>InconsistencyError</code> from OpenAPIKit, which is the right thing for OpenAPIKit to do. The wrong thing is what tends to happen next: the caller gets a stack trace, fixes the first key by hand, runs the generator again, hits the next key, fixes that, runs again. On a single-file spec it is tedious. On a spec split across folders with shared schemas it is a half-day exercise that involves opening seventeen files and remembering which one you were in.</p>
<p>There are excellent OpenAPI linters in the JavaScript world. They are also not OpenAPIKit. If I lint with one tool and generate with another, I am postponing the failure, not preventing it. The validator had to be OpenAPIKit, end of debate.</p>
<h2>What I wanted</h2>
<p>The shape was small and specific:</p>
<ol><li><p>Validate using the exact parser the generator uses. No second source of truth for “valid.”</p></li><li><p>Surface every failure as a typed value, not a stack trace.</p></li><li><p>Auto-repair the mechanical violations, with an audit trail of what changed.</p></li><li><p>Stop on the violations that need human judgement, and say clearly which ones.</p></li><li><p>Handle multi-file specs cleanly. Everything serious lives in more than one file.</p></li><li><p>Exit with codes a shell pipeline can use.</p></li></ol>
<p>That list looks obvious in hindsight. It mostly is. The interesting part is what stands between you and it.</p>
<h2>What OpenAPIDoctor does</h2>
<p>OpenAPIDoctor is a Swift package and CLI built on <code>OpenAPIKit</code> and <code>Yams</code>. Three pieces, in increasing order of how much fun they were to write:</p>
<ul><li><p>A <strong>Validator</strong> that decodes the spec through OpenAPIKit and categorises every result.</p></li><li><p>A <strong>SpecLoader</strong> that handles multi-file specs.</p></li><li><p>A <strong>Repairer</strong> that runs validate, fix, revalidate in a loop until the spec is clean or it hits something it cannot touch.</p></li></ul>
<p>Every result comes back as a <code>DiagnosisKind</code>. Six cases. Only one is auto-repairable:</p>
<ul><li><p><code>.ok</code>: spec parses cleanly. Go home.</p></li><li><p><code>.vendorExtensionPrefix(codingPath, invalidKeys, subjectName)</code>: an extensible OpenAPI object carries keys that are not in the type’s documented set and do not start with <code>x-</code>. The diagnosis carries the exact coding path and the exact keys to strip. <code>isAutoRepairable == true</code>.</p></li><li><p><code>.inconsistency(codingPath, details, subjectName)</code>: every other <code>InconsistencyError</code> from OpenAPIKit. Unsupported <code>openapi:</code> version, malformed <code>$ref:</code> pointing at a component that does not exist. Needs a human.</p></li><li><p><code>.decodingError(codingPath, details)</code>: Foundation-level type mismatch or missing required field. No <code>title:</code> on <code>info:</code>. Wrong type for <code>version:</code>. Needs a human.</p></li><li><p><code>.fileError(details)</code>: the file is not there or cannot be read. Needs a different human.</p></li><li><p><code>.unknown(details)</code>: escape hatch. Nobody is happy about this case existing, but the alternative is lying.</p></li></ul>
<p>Having these as typed values changes how you write callers. You can pattern-match. You can ask <code>diagnosis.kind.isAutoRepairable</code> and route accordingly. From the CLI it looks like this:</p>
<pre><code class="language-bash"><span class="tok-property">$</span> openapi<span class="tok-operator">-</span>doctor my<span class="tok-operator">-</span>spec<span class="tok-operator">.</span>yaml
{<span class="tok-string">"status"</span><span class="tok-operator">:</span><span class="tok-string">"ok"</span>}</code></pre>
<pre><code class="language-bash"><span class="tok-property">$</span> openapi<span class="tok-operator">-</span>doctor stray<span class="tok-operator">-</span>tag<span class="tok-operator">-</span>keys<span class="tok-operator">.</span>yaml
{<span class="tok-string">"codingPath"</span><span class="tok-operator">:</span>[<span class="tok-string">"tags"</span>,<span class="tok-string">"Index 0"</span>],<span class="tok-string">"invalidKeys"</span><span class="tok-operator">:</span>[<span class="tok-string">"slug"</span>,<span class="tok-string">"timezone"</span>],<span class="tok-string">"kind"</span><span class="tok-operator">:</span><span class="tok-string">"vendor-extension-prefix"</span>,<span class="tok-string">"status"</span><span class="tok-operator">:</span><span class="tok-string">"inconsistency"</span>,<span class="tok-string">"subject"</span><span class="tok-operator">:</span><span class="tok-string">"Vendor Extension"</span>}</code></pre>
<p>One line of JSON on stdout, always. Exit code 0 for clean, 1 for “fixable, try <code>--fix</code>”, 2 for “you need to edit this, or the file is missing.” Nothing to parse, nothing to grep through.</p>
<h2>The seams of the abstraction</h2>
<p>If you have read this far, you might enjoy the parts that didn’t come out as cleanly as the API suggests.</p>
<p><strong>OpenAPIKit tells you which keys are invalid in English.</strong> The error message contains a sentence like <code>Invalid properties: [slug, timezone]</code>. There is no <code>[String]</code> accessor for those keys; they live inside the human-readable <code>details</code> string, sitting between two brackets, separated by commas. So OpenAPIDoctor parses them back out:</p>
<pre><code class="language-swift"><span class="tok-keyword">guard</span> <span class="tok-keyword">let</span> open<span class="tok-type">Range</span> <span class="tok-operator">=</span> details<span class="tok-operator">.</span><span class="tok-function">range</span>(of<span class="tok-operator">:</span> <span class="tok-string">"Invalid properties: ["</span>) <span class="tok-keyword">else</span> { <span class="tok-keyword">return</span> [] }
<span class="tok-keyword">let</span> after <span class="tok-operator">=</span> details[open<span class="tok-type">Range</span><span class="tok-operator">.</span>upper<span class="tok-type">Bound</span><span class="tok-operator">.</span><span class="tok-operator">.</span><span class="tok-operator">.</span>]
<span class="tok-keyword">guard</span> <span class="tok-keyword">let</span> close<span class="tok-type">Range</span> <span class="tok-operator">=</span> after<span class="tok-operator">.</span><span class="tok-function">range</span>(of<span class="tok-operator">:</span> <span class="tok-string">"]"</span>) <span class="tok-keyword">else</span> { <span class="tok-keyword">return</span> [] }
<span class="tok-keyword">return</span> after[<span class="tok-operator">.</span><span class="tok-operator">.</span><span class="tok-operator">&lt;</span>close<span class="tok-type">Range</span><span class="tok-operator">.</span>lower<span class="tok-type">Bound</span>]
    <span class="tok-operator">.</span><span class="tok-function">split</span>(separator<span class="tok-operator">:</span> <span class="tok-string">","</span>)
    <span class="tok-operator">.</span>map { $<span class="tok-number">0.</span><span class="tok-function">trimmingCharacters</span>(<span class="tok-keyword">in</span><span class="tok-operator">:</span> <span class="tok-operator">.</span>whitespaces) }
    <span class="tok-operator">.</span>filter { <span class="tok-operator">!</span>$<span class="tok-number">0.</span>is<span class="tok-type">Empty</span> }</code></pre>
<p>This is honest engineering, not clever engineering. If OpenAPIKit ever exposes the rejected keys as structured data, this disappears in one commit. Until then, the seam is here and visible.</p>
<p><strong>Same applies to the classification.</strong> A vendor-extension-prefix violation is identified by <code>details.contains("vendor extension property")</code>. A substring match against an error message. I am aware of how that looks. I am also aware that it has worked perfectly across 594 spec files and counting.</p>
<p><strong>OpenAPIKit reports array positions as strings.</strong> A coding path looks like <code>["tags", "Index 0", "slug"]</code>. The <code>"Index 0"</code> segment is a literal string, not an integer wrapped in <code>Any</code>. The walker that descends into the YAML to delete keys has to parse that string back into an <code>Int</code>:</p>
<pre><code class="language-swift"><span class="tok-keyword">static</span> <span class="tok-keyword">func</span> <span class="tok-function">parseIndex</span>(_ segment<span class="tok-operator">:</span> <span class="tok-type">String</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Int</span><span class="tok-operator">?</span> {
    <span class="tok-keyword">guard</span> segment<span class="tok-operator">.</span><span class="tok-function">hasPrefix</span>(<span class="tok-string">"Index "</span>) <span class="tok-keyword">else</span> { <span class="tok-keyword">return</span> <span class="tok-literal">nil</span> }
    <span class="tok-keyword">return</span> <span class="tok-type">Int</span>(segment<span class="tok-operator">.</span><span class="tok-function">dropFirst</span>(<span class="tok-string">"Index "</span><span class="tok-operator">.</span>count))
}</code></pre>
<p>Small, dumb, real. If you have ever shipped a tool that runs against someone else’s API, you know that almost all of the work is small and dumb and real.</p>
<p><strong>The 3.0 / 3.1 sniff.</strong> OpenAPIKit splits its Document types: <code>OpenAPIKit.OpenAPI.Document</code> is 3.1, <code>OpenAPIKit30.OpenAPI.Document</code> is 3.0. If you point the 3.1 decoder at a 3.0 spec, you get the immortal error <code>"Failed to parse Document Version 3.0.x as one of OpenAPIKit's supported options."</code> So OpenAPIDoctor scans the raw YAML for the <code>openapi:</code> line, picks a decoder, and only parses once. Cheap, deterministic, no second source of truth for what version the spec is.</p>
<p><strong>Yams.dump doesn’t preserve key order.</strong> A comment in the Repairer is candid about it: <em>“preserves enough of the structure for our auto-repair use case (the spec is regenerated on every round anyway). Stable key ordering isn’t guaranteed.”</em> In the auto-repair flow this doesn’t matter, because the source of truth after a repair is the repaired YAML, and you read what was just written. In a workflow that diffs the result against the original, you’ll see ordering churn. That tradeoff is documented in the code, not hidden in a footnote.</p>
<h2>Repair, round by round</h2>
<p>The Repairer is my favourite part. It runs as a loop, capped at thirty rounds: validate, fix, revalidate, until either the spec is clean or it hits a diagnosis that is not auto-repairable. Each round removes exactly the keys OpenAPIKit reported, at exactly the coding path it reported them. No regex matches against the YAML, no guessing. A recursive walker descends to the target, deletes the listed keys from the dict at the leaf, and rebuilds the tree from the bottom up.</p>
<pre><code class="language-bash"><span class="tok-property">$</span> openapi<span class="tok-operator">-</span>doctor <span class="tok-operator">-</span><span class="tok-operator">-</span>fix multi<span class="tok-operator">-</span>stray<span class="tok-operator">.</span>yaml
<span class="tok-comment"># stderr: one JSON per round, streamed as it happens</span>
<span class="tok-comment"># {"removedKeys":["slug"],"round":1,...}</span>
<span class="tok-comment"># {"removedKeys":["timezone","region"],"round":2,...}</span>
<span class="tok-comment"># stdout: aggregate result</span>
{<span class="tok-string">"finalDiagnosis"</span><span class="tok-operator">:</span><span class="tok-string">"ok"</span>,<span class="tok-string">"roundsApplied"</span><span class="tok-operator">:</span><span class="tok-number">2</span>,<span class="tok-string">"status"</span><span class="tok-operator">:</span><span class="tok-string">"repaired"</span>,<span class="tok-string">"totalRemovedKeys"</span><span class="tok-operator">:</span><span class="tok-number">3</span>,<span class="tok-operator">.</span><span class="tok-operator">.</span><span class="tok-operator">.</span>}</code></pre>
<p>The 30-round cap is not arbitrary, but it is generous. The worst-shaped spec I have thrown at it cleared in five. The cap is there so that if the validator and the YAML ever disagree about shape and the loop starts looking like progress that isn’t, the tool stops with a real diagnosis instead of running forever.</p>
<p>For a destructive-free survey of how broken a spec is, there’s a dry-run mode that uses the same loop but discards the repaired YAML, keeping only the list of diagnoses found along the way:</p>
<pre><code class="language-bash"><span class="tok-property">$</span> openapi<span class="tok-operator">-</span>doctor <span class="tok-operator">-</span><span class="tok-operator">-</span>all my<span class="tok-operator">-</span>spec<span class="tok-operator">.</span>yaml <span class="tok-number">2</span><span class="tok-operator">&gt;</span><span class="tok-operator">/</span>tmp<span class="tok-operator">/</span>diagnoses<span class="tok-operator">.</span>jsonl
{<span class="tok-string">"diagnosesFound"</span><span class="tok-operator">:</span><span class="tok-number">3</span>,<span class="tok-string">"fixableDiagnoses"</span><span class="tok-operator">:</span><span class="tok-number">2</span>,<span class="tok-string">"status"</span><span class="tok-operator">:</span><span class="tok-string">"ok"</span>,<span class="tok-string">"terminalKind"</span><span class="tok-operator">:</span><span class="tok-string">"ok"</span>}</code></pre>
<p>Internally, <code>--all</code> and <code>--fix</code> share the strip implementation. The Validator’s <code>collectAll</code> reaches into <code>Repairer.stripKeys</code> directly. One source of truth for “how do you remove a vendor extension key from a YAML tree.” That is the kind of taste that doesn’t show up in the README, which is exactly why I am putting it here.</p>
<p><code>--output &lt;path&gt;</code> writes the repaired YAML to a side file and leaves the source untouched, useful for diffing before-and-after in CI. <code>--corpus &lt;dir&gt;</code> walks a directory of specs and reports per-file results with an aggregate summary, useful when you have inherited a folder of half-maintained specs and want a triage report before you touch anything.</p>
<h2>The 594-file corpus</h2>
<p>Multi-file specs are where the interesting bugs live. A serious API spans folders: a <code>finance</code> service that pulls <code>../core/parameters/id.yml</code>; an <code>analytics</code> service that pulls <code>../core/schemas/apiError.yml</code>; a <code>ledger</code> service that references both. <code>OpenAPIKit</code> expects one document. Without help, every external <code>$ref</code> would dangle.</p>
<p>The loader delegates to <a href="https://codeberg.org/OpenAPIHQ/Stitcher">Stitcher</a>, a separate library I published in November 2025 for exactly this problem. OpenAPIDoctor followed in May 2026 and took Stitcher as a dependency rather than re-implementing the resolver, which is the right division of labour: cross-file <code>$ref</code> resolution is a generic problem; OpenAPI validation is a specific one. Two libraries, two responsibilities, one composes the other.</p>
<p>To prove the two pieces actually agree about what “valid” means on the shape of spec I care about, the test suite drives an anonymised real-world corpus through the validator: <strong>594 YAML files across 22 services</strong>, of which <strong>146 contain at least one cross-folder <code>../</code> reference</strong>, all OpenAPI 3.0.3, the kind of layout you only get when humans have been editing for a year. The test asserts every entry point validates cleanly. When it does, I know Stitcher’s merged output and OpenAPIKit’s strict parser agree, in detail, across the whole tree, every commit.</p>
<p>You can flip Stitcher off with <code>--no-resolve-refs</code>, which loads the spec file as-is. Useful when the referenced files are not on disk, or when you want to isolate a problem to a single file and stop wondering if the resolver is the one lying to you.</p>
<h2>Where it fits</h2>
<p>OpenAPIDoctor is one stage in a longer code-generation pipeline I run. Specs come in. Validation happens. Generation happens. Swift compiles. There is nothing exotic about that flow except the requirement that every stage produces something the next stage can use, without surprises.</p>
<p>OpenAPIDoctor’s contract is the simplest in the chain. After it runs, the spec is either clean, or the caller knows exactly what is wrong with it, whether a tool can fix it, and where in the document the problem lives. That contract is what lets the rest of the pipeline be boring. Boring pipelines are the only kind that ship.</p>
<h2>Where to find it</h2>
<p><a href="https://codeberg.org/OpenAPIHQ/OpenAPIDoctor">codeberg.org/OpenAPIHQ/OpenAPIDoctor</a>, tagged at <code>1.0.0</code>. MIT licensed. Library for embedding in your own pipeline, CLI for the shell:</p>
<pre><code class="language-swift"><span class="tok-operator">.</span><span class="tok-keyword">package</span>(url<span class="tok-operator">:</span> <span class="tok-string">"https://codeberg.org/Mihaela/OpenAPIDoctor"</span>, from<span class="tok-operator">:</span> <span class="tok-string">"1.0.0"</span>),</code></pre>
<p>If you generate Swift from OpenAPI on anything bigger than a toy spec, you probably want this somewhere upstream of the generator. And if you ever see <em>“The given data was not valid YAML.”</em> in a stack trace, you now know two things: it is lying to you, and somebody already wrote the tool that tells you the truth.</p>]]></content:encoded>
</item>
<item>
<title>Building a Concurrency-Safe Bearer Token Middleware for Swift OpenAPI Clients</title>
<link>https://aleahim.com/blog/token-middleware/</link>
<guid isPermaLink="true">https://aleahim.com/blog/token-middleware/</guid>
<pubDate>Sat, 08 Nov 2025 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>Elegant, Thread-Safe Authentication for OpenAPI Runtime</description>
<content:encoded><![CDATA[<p>Authentication is one of those things that every API client needs, yet implementing it cleanly and safely can be surprisingly tricky—especially in Swift’s modern concurrency world. Today, I’m sharing a lightweight middleware solution that handles Bearer token authentication for OpenAPI-generated Swift clients in a thread-safe, composable way.</p>
<h2>The Problem</h2>
<p>When working with OpenAPI Runtime in Swift, you often need to:</p>
<ul><li><p>Inject an <code>Authorization: Bearer &lt;token&gt;</code> header into API requests</p></li><li><p>Update tokens dynamically (after login, token refresh, etc.)</p></li><li><p>Skip authentication for certain endpoints (like login or public routes)</p></li><li><p>Ensure thread-safety in concurrent environments</p></li></ul>
<p>While this sounds straightforward, getting it right with Swift 6’s strict concurrency checking requires careful design. You need proper actor isolation, Sendable conformance, and a clean API that doesn’t fight the type system.</p>
<h2>The Solution: BearerTokenAuthenticationMiddleware</h2>
<p>I built <code>BearerTokenAuthenticationMiddleware</code>—a minimal, zero-dependency package that solves these problems elegantly. Here’s what makes it special:</p>
<h3>1. Actor-Isolated Token Storage</h3>
<p>The heart of the middleware is a private <code>TokenStorage</code> actor that manages the authentication token:</p>
<pre><code class="language-swift"><span class="tok-keyword">private</span> <span class="tok-keyword">actor</span> <span class="tok-type">TokenStorage</span> {
    <span class="tok-keyword">var</span> token<span class="tok-operator">:</span> <span class="tok-type">String</span><span class="tok-operator">?</span>

    <span class="tok-keyword">func</span> <span class="tok-function">getToken</span>() <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">String</span><span class="tok-operator">?</span> {
        token
    }

    <span class="tok-keyword">func</span> <span class="tok-function">setToken</span>(_ new<span class="tok-type">Token</span><span class="tok-operator">:</span> <span class="tok-type">String</span><span class="tok-operator">?</span>) {
        token <span class="tok-operator">=</span> new<span class="tok-type">Token</span>
    }
}</code></pre>
<p>This ensures that token reads and writes are <strong>never concurrent</strong>, eliminating race conditions completely.</p>
<h3>2. Clean, Composable API</h3>
<p>Setting up the middleware is straightforward:</p>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">OpenAPIRuntime</span>
<span class="tok-keyword">import</span> <span class="tok-type">BearerTokenAuthMiddleware</span>

<span class="tok-keyword">let</span> auth<span class="tok-type">Middleware</span> <span class="tok-operator">=</span> <span class="tok-type">BearerTokenAuthenticationMiddleware</span>(
    initial<span class="tok-type">Token</span><span class="tok-operator">:</span> <span class="tok-string">"my-secret-token"</span>
)

<span class="tok-keyword">let</span> client <span class="tok-operator">=</span> <span class="tok-type">Client</span>(
    server<span class="tok-type">URL</span><span class="tok-operator">:</span> <span class="tok-type">URL</span>(string<span class="tok-operator">:</span> <span class="tok-string">"https://api.example.com"</span>)<span class="tok-operator">!</span>,
    transport<span class="tok-operator">:</span> <span class="tok-type">AsyncHTTPClientTransport</span>(),
    middlewares<span class="tok-operator">:</span> [auth<span class="tok-type">Middleware</span>]
)</code></pre>
<p>Every request now automatically includes <code>Authorization: Bearer my-secret-token</code>.</p>
<h2>Wrapping Up</h2>
<p>Building authentication middleware might seem like boilerplate, but doing it right—especially with modern Swift concurrency—requires thoughtful design. <code>BearerTokenAuthenticationMiddleware</code> provides:</p>
<ul><li><p>Thread-safe token management via actors</p></li><li><p>Selective authentication with operation-level control</p></li><li><p>Dynamic token updates</p></li><li><p>Zero dependencies</p></li><li><p>Clean composition with other middlewares</p></li></ul>
<p><strong>Repository</strong>: <a href="https://codeberg.org/OpenAPIHQ/BearerTokenAuthMiddleware">codeberg.org/OpenAPIHQ/BearerTokenAuthMiddleware</a></p>]]></content:encoded>
</item>
<item>
<title>From ExtremePackaging to OpenAPI Integration</title>
<link>https://aleahim.com/blog/extreme-packaging-open-a-p-i/</link>
<guid isPermaLink="true">https://aleahim.com/blog/extreme-packaging-open-a-p-i/</guid>
<pubDate>Tue, 23 Sep 2025 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>Building a Full OpenAPI Workflow on Top of the Extreme Packaging Architecture</description>
<content:encoded><![CDATA[<p>When I first published <a href="https://codeberg.org/Mihaela/ExtremePackaging">ExtremePackaging</a>, the goal was simple — to prove that <strong>highly modular Swift architectures</strong> can scale across platforms while keeping build times fast, dependencies isolated, and the mental model crystal clear.</p>
<p>But then came the next step: <em>Could this same architecture host a complete OpenAPI workflow — with generated clients, servers, and full middleware integration — without losing its elegance?</em></p>
<p>That’s how the new reference implementation, <strong>swift-openapi-extremepackaging-example</strong>, was born.</p>
<hr>
<h2>🧩 The Foundation — ExtremePackaging</h2>
<p>The original ExtremePackaging repository introduced a clean, layered structure:</p>
<ul><li><p><strong>Shared packages</strong> for models and protocols</p></li><li><p><strong>Independent feature modules</strong> for UI, data, and networking</p></li><li><p><strong>No cross-package leaks</strong></p></li><li><p><strong>Unified Xcode workspace</strong> that felt like a monolith but built like microservices</p></li></ul>
<p>The guiding philosophy: <em>Each feature should be an island, communicating only through well-defined contracts.</em></p>
<p>That foundation made it ideal for integrating OpenAPI-generated code — which naturally fits into modular boundaries like <code>SharedApiModels</code>, <code>ApiClient</code>, and <code>ApiServer</code>.</p>
<hr>
<h2>🚀 Evolving Toward OpenAPI</h2>
<p>The OpenAPI version added an entire new layer of automation and functionality — transforming a static architecture into a <strong>living, self-describing API ecosystem</strong>.</p>
<h3>1. OpenAPI Schema &amp; Code Generation</h3>
<p>At the heart of the project is the <strong>OpenAPI specification (<code>openapi.yaml</code>)</strong> — defining endpoints, models, and responses for a DummyJSON-compatible API.</p>
<p>Newly introduced elements:</p>
<ul><li><p>🧱 Full schema definitions for <code>Users</code>, <code>Posts</code>, <code>Products</code>, <code>Todos</code>, and <code>Carts</code></p></li><li><p>🧩 Error schemas (404, validation, authentication)</p></li><li><p>⚙️ Integration with <strong>Swift OpenAPI Generator</strong></p></li><li><p>🔁 Automatic generation of clients, models, and server stubs</p></li><li><p>📦 Separation of generated code into <code>SharedApiModels</code></p></li></ul>
<p>This turned the architecture into a self-contained API ecosystem — one that can <strong>generate, serve, and consume</strong> its own endpoints.</p>
<hr>
<h3>2. API Server Implementation</h3>
<p>A complete <strong>Vapor-based local server</strong> (<code>ApiServer</code>) was added to simulate real-world backend behavior:</p>
<ul><li><p>17 endpoints fully implemented from the OpenAPI spec</p></li><li><p>Realistic mock data mirroring DummyJSON</p></li><li><p>Pagination and validation logic</p></li><li><p>Centralized error responses</p></li><li><p>🖥️ Prefixed logging for easy tracing in the console</p></li></ul>
<p>The server runs locally at <code>http://localhost:8080</code>, serving as both a mock backend and a test harness for the generated client.</p>
<hr>
<h3>3. Enhanced API Client Architecture</h3>
<p>The client evolved from a simple abstraction into a <strong>fully concurrent, actor-based networking layer</strong>.</p>
<h4>Highlights</h4>
<ul><li><p><code>ApiClient</code> actor manages shared state safely across async contexts</p></li><li><p>Middleware chain introduced: <strong>Logging → Authentication → Correction</strong></p></li><li><p>Runtime environment switching between <code>.production</code>, <code>.local</code>, and <code>.mock</code></p></li><li><p>Shared singleton <code>ApiClientState</code> stores token, settings, and preferences</p></li></ul>
<p>Example flow:</p>
<pre><code class="language-swift"><span class="tok-keyword">try</span> <span class="tok-keyword">await</span> <span class="tok-type">ApiClient</span><span class="tok-operator">.</span><span class="tok-function">initializeShared</span>(environment<span class="tok-operator">:</span> <span class="tok-operator">.</span>production)
<span class="tok-keyword">let</span> client <span class="tok-operator">=</span> <span class="tok-type">ApiClient</span><span class="tok-operator">.</span>shared<span class="tok-operator">!</span>
<span class="tok-keyword">let</span> auth <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-keyword">await</span> client<span class="tok-operator">.</span><span class="tok-function">login</span>(username<span class="tok-operator">:</span> <span class="tok-string">"emilys"</span>, password<span class="tok-operator">:</span> <span class="tok-string">"emilyspass"</span>)
<span class="tok-keyword">await</span> <span class="tok-type">ApiClient</span><span class="tok-operator">.</span><span class="tok-function">setToken</span>(auth<span class="tok-operator">.</span>access<span class="tok-type">Token</span>)
<span class="tok-keyword">let</span> users <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-keyword">await</span> client<span class="tok-operator">.</span><span class="tok-function">getUsers</span>(limit<span class="tok-operator">:</span> <span class="tok-number">10</span>)</code></pre>
<p>A clear separation between environment configuration and runtime state ensures deterministic, thread-safe behavior.</p>
<hr>
<h3>4. Middleware Integration</h3>
<p>The client leverages two reusable middlewares from sibling packages:</p>
<ul><li><p><strong><a href="https://codeberg.org/OpenAPIHQ/OpenAPILoggingMiddleware">OpenAPILoggingMiddleware</a></strong>
Provides structured, console + JSON logging with full request/response capture.</p></li><li><p><strong><a href="https://codeberg.org/OpenAPIHQ/BearerTokenAuthMiddleware">BearerTokenAuthMiddleware</a></strong>
Manages JWT token injection with a concurrency-safe actor and public operation rules.</p></li></ul>
<p>Together, they demonstrate the power of <strong>middleware chaining</strong> in OpenAPI Runtime — clean, modular extensions without inheritance or global state.</p>
<hr>
<h3>5. YAMLMerger — The Key to Structured API Specs</h3>
<p>The project uses <strong><a href="https://git.aleahim.com/NodetteHQ/YamlMerger">YamlMerger</a></strong> — a Swift package that merges multiple YAML files into a single combined OpenAPI specification.
If your project doesn’t already include an <code>openapi.yaml</code>, YamlMerger ensures you have one — and helps you maintain a <strong>structured, predictable folder layout</strong> under <code>Tests/</code> or <code>Sources/SharedApiModels/schemas/</code>.</p>
<h4>🧠 Why It Must Be Copied into the Project</h4>
<p>YamlMerger cannot simply be added as a SwiftPM dependency for build-time merging because of <strong>SPM’s read-only resolution model</strong>:</p>
<ol><li><p>Swift Package Manager stores dependencies in a <strong>cached, read-only</strong> location (<code>.build/checkouts/</code>).</p></li><li><p>The OpenAPI generator, however, needs <strong>write access</strong> to output the merged <code>openapi.yaml</code> file directly into your source tree.</p></li><li><p>SPM build scripts are not allowed to write to source folders outside their sandboxed build directory.</p></li></ol>
<p>✅ <strong>Solution:</strong> Copy the YamlMerger executable directly into your project (e.g. <code>Tools/YamlMerger/</code>) and call it from a pre-build script or CI pipeline.
This guarantees write permissions and makes the tool available to everyone checking out the repo.</p>
<h4>🧩 What It Does</h4>
<p>YamlMerger scans subdirectories (01 → 08) and merges YAML fragments in deterministic order:</p>
<ol><li><p>Folders are processed numerically.</p></li><li><p><code>__*.yaml</code> files merge first within each folder.</p></li><li><p>Remaining files merge alphabetically.</p></li><li><p>The final output is a complete OpenAPI spec, suitable for Swift OpenAPI Generator.</p></li></ol>
<h4>🧱 Example Schema Layout</h4>
<pre><code>Schema/
├── 01_Info/
├── 02_Servers/
├── 03_Tags/
├── 04_Paths/
├── 05_Webhooks/
├── 06_Components/
├── 07_Security/
└── 08_ExternalDocs/</code></pre>
<p>Each folder corresponds to a section of the OpenAPI spec, allowing multiple developers to work on different endpoints, schemas, or components without conflicts.</p>
<h4>⚙️ Typical Workflow</h4>
<pre><code class="language-bash"><span class="tok-comment"># Merge schemas before build</span>
<span class="tok-operator">.</span><span class="tok-operator">/</span>Tools<span class="tok-operator">/</span>YamlMerger merge   <span class="tok-operator">-</span><span class="tok-operator">-</span>input Sources<span class="tok-operator">/</span>SharedApiModels<span class="tok-operator">/</span>schemas<span class="tok-operator">/</span>   <span class="tok-operator">-</span><span class="tok-operator">-</span>output Sources<span class="tok-operator">/</span>SharedApiModels<span class="tok-operator">/</span>openapi<span class="tok-operator">.</span>yaml</code></pre>
<p>You can run this manually, in a pre-build phase, or as part of CI/CD automation.</p>
<h4>💡 Pro Tip</h4>
<p>If your project starts <strong>without</strong> an <code>openapi.yaml</code>, placing schema fragments in structured folders under <code>Tests/</code> ensures your API structure remains organized — even before full code generation.
YamlMerger gives your tests (and your teammates) a <strong>shared, visual map</strong> of your API’s evolving shape.</p>
<hr>
<h3>6. Test Coverage Expansion</h3>
<p>Two new test suites validate both local and production APIs:</p>
<ul><li><p>🧪 <code>ApiClientLocalTests.swift</code> — 25 tests targeting the local Vapor server</p></li><li><p>🌐 <code>ApiClientProductionTests.swift</code> — 29 integration tests against DummyJSON API</p></li></ul>
<p>Tests cover:</p>
<ul><li><p>Authentication and token persistence</p></li><li><p>Pagination behavior</p></li><li><p>Error responses and invalid IDs</p></li><li><p>Concurrent request handling</p></li></ul>
<p>Together they form a <strong>54-test safety net</strong> proving both architecture and OpenAPI compliance.</p>
<hr>
<h2>🧠 Architecture Snapshot</h2>
<pre><code>Packages/
├── Sources/
│   ├── ApiClient/
│   ├── ApiServer/
│   └── SharedApiModels/
└── Tests/
    └── ApiClientTests/</code></pre>
<p>Each target is self-contained — just like in the original ExtremePackaging — but now with full OpenAPI integration, client/server symmetry, and end-to-end testability.</p>
<hr>
<h2>⚡ Key Improvements Over ExtremePackaging</h2>
<table><thead><tr><th>Area</th><th>Before</th><th>After</th></tr></thead><tbody><tr><td>API Definition</td><td>Manual protocol layer</td><td>Generated OpenAPI spec</td></tr><tr><td>Networking</td><td>Custom client</td><td>Actor-based client w/ middlewares</td></tr><tr><td>Server</td><td>None</td><td>Vapor mock server (17 endpoints)</td></tr><tr><td>Authentication</td><td>Static token</td><td>BearerTokenAuthMiddleware</td></tr><tr><td>Logging</td><td>Simple print logs</td><td>Structured OpenAPILoggingMiddleware</td></tr><tr><td>Testing</td><td>Minimal unit tests</td><td>Full integration tests (54 total)</td></tr><tr><td>Schema Management</td><td>Handwritten</td><td>Modular YAML + YamlMerger</td></tr><tr><td>Tooling</td><td>Swift only</td><td>Swift + OpenAPI toolchain</td></tr></tbody></table>
<hr>
<h2>🧭 Lessons Learned</h2>
<ol><li><p><strong>OpenAPI fits perfectly into modular Swift architectures</strong> — generated code belongs in its own layer, and SwiftPM makes that separation effortless.</p></li><li><p><strong>Actors are the future of shared state</strong> — simple, safe, and transparent.</p></li><li><p><strong>Middleware &gt; Managers</strong> — function composition scales better than class hierarchies.</p></li><li><p><strong>Automation beats documentation</strong> — with OpenAPI, the spec <em>is</em> the documentation.</p></li></ol>
<hr>
<h2>💬 Closing Thoughts</h2>
<p>This evolution of ExtremePackaging into a full OpenAPI reference app is more than a demo — it’s a <strong>blueprint for modular API-driven development in Swift</strong>.</p>
<p>From YAML schemas to live servers and typed clients, everything now exists in one unified, testable ecosystem — powered by Apple’s official OpenAPI tools and guided by the ExtremePackaging philosophy.</p>
<p>👉 Explore the project: <a href="https://codeberg.org/Mihaela/swift-openapi-extremepackaging-example">swift-openapi-extremepackaging-example</a></p>
<hr>
<p><em>“Architecture should scale not by adding layers, but by removing assumptions.”</em></p>]]></content:encoded>
</item>
<item>
<title>Introducing OpenAPILoggingMiddleware</title>
<link>https://aleahim.com/blog/logging-middleware/</link>
<guid isPermaLink="true">https://aleahim.com/blog/logging-middleware/</guid>
<pubDate>Tue, 16 Sep 2025 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>Elegant, Structured Request Logging for OpenAPI-Driven Swift Servers</description>
<content:encoded><![CDATA[<h2>Introduction</h2>
<p>In the world of <strong>OpenAPI-driven Swift servers</strong>, visibility is everything.
You can’t fix what you can’t see — and you can’t optimize what you don’t understand.</p>
<p>When I started building modular, OpenAPI-first architectures in Swift, one thing stood out: <strong>logging was either overwhelming or absent</strong>.
Either you got a raw dump of everything (headers, binary data, and stack traces), or you got nothing at all. Neither is particularly helpful when debugging or tracing an issue across microservices.</p>
<p>Frameworks like <strong>OpenAPIRuntime</strong> and <strong>OpenAPIVapor</strong> provide a strong foundation, but they deliberately avoid opinions about logging. They leave that up to you.
And that’s where most developers end up adding scattered <code>print()</code> statements or ad-hoc <code>logger.info()</code> calls inside handlers just to see what’s going on.</p>
<p>That’s not clean architecture. It’s noise.</p>
<p>So I built <strong>OpenAPILoggingMiddleware</strong>, a small, composable middleware that gives you <em>just enough visibility</em> — not too much, not too little — when working with OpenAPI-based servers.</p>
<hr>
<h2>The Problem: Logging in a Generated World</h2>
<p>OpenAPI code generation has revolutionized how backend systems are written. You define your contracts, generate both server and client, and everything should “just work.”
But once requests start flowing, visibility often becomes a blind spot.</p>
<p>If you’ve ever tried debugging an OpenAPI-generated Swift server, you might recognize these problems:</p>
<ul><li><p>Middleware logs every byte of the body, even binary data.</p></li><li><p>Multi-part and SSE requests produce unreadable noise.</p></li><li><p>Response logs are buried under system output.</p></li><li><p>There’s no consistent way to see request duration or endpoint performance.</p></li><li><p>You can’t easily toggle verbosity levels or redact sensitive data.</p></li></ul>
<p>You end up either drowning in log output or adding <code>print</code> calls just to survive the debugging process.</p>
<p>This middleware solves that.</p>
<hr>
<h2>The Solution: A Lightweight Logging Layer</h2>
<p><code>OpenAPILoggingMiddleware</code> sits quietly in the pipeline — between your generated routes and the transport layer.
It listens to every incoming request and outgoing response, measures duration, and prints a <strong>structured summary</strong> of what happened.</p>
<p>At its core, the idea is simple:</p>
<blockquote><p>Log exactly what you’d want to see if you were reading someone else’s code.</p></blockquote>
<p>Here’s how it looks in your Vapor or OpenAPI setup:</p>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">OpenAPILoggingMiddleware</span>

app<span class="tok-operator">.</span>middleware<span class="tok-operator">.</span><span class="tok-function">use</span>(<span class="tok-type">OpenAPILoggingMiddleware</span>(level<span class="tok-operator">:</span> <span class="tok-operator">.</span>info))</code></pre>
<p>That one line transforms your debugging experience.</p>
<hr>
<h2>Under the Hood</h2>
<p>The middleware implements the <code>OpenAPIMiddleware</code> protocol, which lets it intercept the lifecycle of each OpenAPI operation — before the request is handled and after the response is sent.</p>
<p>Here’s a conceptual overview:</p>
<pre><code class="language-swift"><span class="tok-keyword">public</span> <span class="tok-keyword">struct</span> <span class="tok-type">OpenAPILoggingMiddleware</span><span class="tok-operator">:</span> <span class="tok-type">OpenAPIMiddleware</span> {
    <span class="tok-keyword">public</span> <span class="tok-keyword">func</span> <span class="tok-function">intercept</span>(
        _ request<span class="tok-operator">:</span> <span class="tok-type">Request</span>,
        operation<span class="tok-type">ID</span><span class="tok-operator">:</span> <span class="tok-type">String</span>,
        next<span class="tok-operator">:</span> (<span class="tok-type">Request</span>) <span class="tok-keyword">async</span> <span class="tok-keyword">throws</span> <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Response</span>
    ) <span class="tok-keyword">async</span> <span class="tok-keyword">throws</span> <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Response</span> {
        <span class="tok-keyword">let</span> start <span class="tok-operator">=</span> <span class="tok-type">Date</span>()
        <span class="tok-keyword">let</span> response <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-keyword">await</span> <span class="tok-function">next</span>(request)
        <span class="tok-keyword">let</span> duration <span class="tok-operator">=</span> <span class="tok-type">Date</span>()<span class="tok-operator">.</span><span class="tok-function">timeIntervalSince</span>(start) <span class="tok-operator">*</span> <span class="tok-number">1000</span>

        <span class="tok-function">print</span>(<span class="tok-string">"[\(request.method)] \(request.url.path) -&gt; \(response.status.code) [\(Int(duration)) ms]"</span>)
        <span class="tok-keyword">return</span> response
    }
}</code></pre>
<p>Of course, the real implementation handles errors, structured formatting, and configurable verbosity, but the essence is the same:
it’s a <em>transparent layer of introspection</em> that doesn’t alter your data flow.</p>
<hr>
<h2>Logging Philosophy</h2>
<p>There’s a fine balance between too much and too little information.</p>
<p>Traditional logging tools either <strong>dump everything</strong> (which nobody reads) or <strong>show too little</strong> (which leaves you guessing).
<code>OpenAPILoggingMiddleware</code> follows a <em>minimalist</em> principle inspired by Apple’s own frameworks — log what matters, hide what doesn’t.</p>
<p>It’s designed around three key ideas:</p>
<ol><li><p><strong>Contextual logging</strong> — every entry includes method, path, status, and duration.</p></li><li><p><strong>Progressive verbosity</strong> — higher log levels show headers and bodies.</p></li><li><p><strong>Human readability first</strong> — logs are meant to be scanned, not parsed by machines.</p></li></ol>
<p>Here’s an example of what a single request looks like in <code>.info</code> mode:</p>
<pre><code class="language-text">[<span class="tok-type">POST</span>] <span class="tok-operator">/</span>mocks<span class="tok-operator">/</span>messages<span class="tok-operator">/</span>agent<span class="tok-operator">-</span><span class="tok-function">responses</span> (<span class="tok-number">200</span> <span class="tok-type">OK</span>)
<span class="tok-type">Duration</span><span class="tok-operator">:</span> <span class="tok-number">123</span> ms
<span class="tok-type">Body</span><span class="tok-operator">:</span> {<span class="tok-string">"message"</span><span class="tok-operator">:</span><span class="tok-string">"You shall not pass!"</span>}</code></pre>
<p>And at <code>.debug</code> level, you get more detail:</p>
<pre><code class="language-text">[<span class="tok-type">POST</span>] <span class="tok-operator">/</span>mocks<span class="tok-operator">/</span>messages<span class="tok-operator">/</span>agent<span class="tok-operator">-</span>responses
<span class="tok-type">Headers</span><span class="tok-operator">:</span>
  <span class="tok-type">Content</span><span class="tok-operator">-</span><span class="tok-type">Type</span><span class="tok-operator">:</span> application<span class="tok-operator">/</span>json
  <span class="tok-type">Authorization</span><span class="tok-operator">:</span> <span class="tok-type">Bearer</span> <span class="tok-type">Gandalf</span><span class="tok-operator">-</span><span class="tok-type">Was</span><span class="tok-operator">-</span><span class="tok-type">Here</span><span class="tok-number">-1</span>
<span class="tok-type">Duration</span><span class="tok-operator">:</span> <span class="tok-number">123</span> ms
<span class="tok-type">Body</span><span class="tok-operator">:</span> {<span class="tok-string">"message"</span><span class="tok-operator">:</span><span class="tok-string">"You shall not pass!"</span>}</code></pre>
<p>Readable. Structured. Useful.</p>
<hr>
<h2>Why Not Just Use Vapor’s Logger?</h2>
<p>That’s a valid question.</p>
<p>Vapor already includes a powerful logging system based on SwiftLog, so why add another layer?
Because Vapor’s logger is <strong>request-agnostic</strong> — it’s not aware of OpenAPI operations, generated endpoints, or typed models.</p>
<p><code>OpenAPILoggingMiddleware</code> is <strong>contract-aware</strong>.
It sits in the OpenAPI pipeline, so it can access the operation ID, typed body, and structured response — all without touching your route handlers. That distinction is crucial for OpenAPI-based architectures, where most of your server logic is generated.</p>
<hr>
<h2>Integration Examples</h2>
<p>Adding it to a Vapor-based OpenAPI server is trivial:</p>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">Vapor</span>
<span class="tok-keyword">import</span> <span class="tok-type">OpenAPIRuntime</span>
<span class="tok-keyword">import</span> <span class="tok-type">OpenAPIVapor</span>
<span class="tok-keyword">import</span> <span class="tok-type">OpenAPILoggingMiddleware</span>

<span class="tok-keyword">let</span> app <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-type">Application</span>(<span class="tok-operator">.</span><span class="tok-function">detect</span>())

<span class="tok-keyword">let</span> server <span class="tok-operator">=</span> <span class="tok-keyword">try</span><span class="tok-operator">!</span> <span class="tok-type">MyOpenAPIServer</span>(app<span class="tok-operator">:</span> app)

app<span class="tok-operator">.</span>middleware<span class="tok-operator">.</span><span class="tok-function">use</span>(<span class="tok-type">OpenAPILoggingMiddleware</span>(level<span class="tok-operator">:</span> <span class="tok-operator">.</span>info))
<span class="tok-keyword">try</span> app<span class="tok-operator">.</span><span class="tok-function">run</span>()</code></pre>
<p>If you’re using <code>OpenAPIRuntime</code> directly (without Vapor), it’s equally simple:</p>
<pre><code class="language-swift"><span class="tok-keyword">var</span> server <span class="tok-operator">=</span> <span class="tok-keyword">try</span> <span class="tok-type">OpenAPIServer</span>()
server<span class="tok-operator">.</span>middleware<span class="tok-operator">.</span><span class="tok-function">append</span>(<span class="tok-type">OpenAPILoggingMiddleware</span>(level<span class="tok-operator">:</span> <span class="tok-operator">.</span>debug))
<span class="tok-keyword">try</span> server<span class="tok-operator">.</span><span class="tok-function">start</span>()</code></pre>
<p>No configuration files. No dependencies. It just works.</p>
<hr>
<h2>Extensibility and Customization</h2>
<p>Logging needs vary between environments.
In development, you might want to see every detail. In production, you want concise summaries. The middleware supports multiple log levels, allowing you to tailor verbosity to your needs:</p>
<ul><li><p><code>.error</code> — log only failed requests.</p></li><li><p><code>.info</code> — log all requests with method, path, duration, and status.</p></li><li><p><code>.debug</code> — include headers and bodies.</p></li></ul>
<p>In future releases, I plan to add <strong>filters</strong> and <strong>formatters</strong> — so you could, for instance, redact specific headers (<code>Authorization</code>, <code>Cookie</code>) or export logs in JSON format for ingestion into a centralized system.</p>
<p>Example:</p>
<pre><code class="language-swift"><span class="tok-keyword">let</span> middleware <span class="tok-operator">=</span> <span class="tok-type">OpenAPILoggingMiddleware</span>(
    level<span class="tok-operator">:</span> <span class="tok-operator">.</span>debug,
    redact<span class="tok-type">Headers</span><span class="tok-operator">:</span> [<span class="tok-string">"Authorization"</span>, <span class="tok-string">"Cookie"</span>]
)</code></pre>
<hr>
<h2>Design Details: Why Simplicity Wins</h2>
<p>Many logging libraries start small and end up as frameworks. They introduce dependency graphs, adapters, output sinks, configuration DSLs — and complexity sneaks in through the back door.</p>
<p>I deliberately avoided that path.</p>
<p><code>OpenAPILoggingMiddleware</code> does one thing: <strong>it shows what your OpenAPI server is doing</strong>.
Nothing else.</p>
<p>No JSON serialization frameworks. No dependency injection. No external configuration.
Just clean Swift and a single dependency on <code>OpenAPIRuntime</code>.</p>
<p>The codebase is small enough to read in one sitting — and that’s intentional. In my opinion, <strong>you should be able to understand every line of code that runs in your server’s core path</strong>.</p>
<hr>
<h2>Performance Considerations</h2>
<p>Logging always comes at a cost, but the impact here is minimal.
The middleware measures request duration using <code>Date().timeIntervalSince(start)</code>, which is negligible compared to network latency or I/O.</p>
<p>You can safely keep it enabled even in staging or pre-production environments.
In production, switching to <code>.error</code> mode will keep your logs clean while still providing visibility into failures.</p>
<hr>
<h2>Testing and Debugging</h2>
<p>The middleware is fully testable using Vapor’s <code>Application</code> test harness or plain <code>XCTest</code> with mock requests.
Here’s a simple test that validates duration and structure:</p>
<pre><code class="language-swift"><span class="tok-keyword">func</span> <span class="tok-function">testMiddlewareLogsRequestAndResponse</span>() <span class="tok-keyword">async</span> <span class="tok-keyword">throws</span> {
    <span class="tok-keyword">let</span> app <span class="tok-operator">=</span> <span class="tok-type">Application</span>(<span class="tok-operator">.</span>testing)
    app<span class="tok-operator">.</span>middleware<span class="tok-operator">.</span><span class="tok-function">use</span>(<span class="tok-type">OpenAPILoggingMiddleware</span>(level<span class="tok-operator">:</span> <span class="tok-operator">.</span>info))
    <span class="tok-keyword">try</span> <span class="tok-keyword">await</span> app<span class="tok-operator">.</span><span class="tok-function">test</span>(<span class="tok-operator">.</span><span class="tok-type">POST</span>, <span class="tok-string">"/ping"</span>, after<span class="tok-type">Response</span><span class="tok-operator">:</span> { res <span class="tok-keyword">in</span>
        <span class="tok-type">XCTAssertEqual</span>(res<span class="tok-operator">.</span>status, <span class="tok-operator">.</span>ok)
    })
}</code></pre>
<p>You can also inject your own logger conforming to <code>LogHandler</code> if you prefer structured output rather than printing to stdout.</p>
<hr>
<h2>Future Work</h2>
<p>The roadmap includes:</p>
<ol><li><p><strong>JSON Formatter</strong> — for structured logs in production environments.</p></li><li><p><strong>Redaction Rules</strong> — for headers and sensitive body fields.</p></li><li><p><strong>Metrics Hooks</strong> — integration with Swift Metrics or Prometheus.</p></li><li><p><strong>Pluggable Output Destinations</strong> — allowing streaming to files or external monitoring systems.</p></li><li><p><strong>Async Logging</strong> — offloading logging I/O to background tasks for ultra-high performance scenarios.</p></li></ol>
<p>Each of these will follow the same guiding principles: clarity, composability, and minimalism.</p>
<hr>
<h2>Philosophy: Clean Visibility</h2>
<p>Logging is not just a developer tool — it’s part of the interface between humans and systems.
A well-designed logging layer doesn’t scream for attention; it quietly reveals how the system behaves.</p>
<p>When I was designing this package, I thought about the elegance of Apple’s own frameworks — the way their APIs feel inevitable, obvious in hindsight. That’s what I aim for here: <strong>a logging middleware that feels invisible until you need it, and indispensable once you use it.</strong></p>
<hr>
<h2>Example Output in Context</h2>
<p>Here’s a real-world example of multiple concurrent requests hitting the same endpoint:</p>
<pre><code class="language-text">[<span class="tok-type">GET</span>] <span class="tok-operator">/</span>user<span class="tok-operator">/</span><span class="tok-function">profile</span> (<span class="tok-number">200</span> <span class="tok-type">OK</span>)
<span class="tok-type">Duration</span><span class="tok-operator">:</span> <span class="tok-number">87</span> ms

[<span class="tok-type">POST</span>] <span class="tok-operator">/</span>mocks<span class="tok-operator">/</span>messages<span class="tok-operator">/</span>agent<span class="tok-operator">-</span><span class="tok-function">responses</span> (<span class="tok-number">200</span> <span class="tok-type">OK</span>)
<span class="tok-type">Duration</span><span class="tok-operator">:</span> <span class="tok-number">121</span> ms
<span class="tok-type">Body</span><span class="tok-operator">:</span> {<span class="tok-string">"message"</span><span class="tok-operator">:</span><span class="tok-string">"You shall not pass!"</span>}

[<span class="tok-type">PATCH</span>] <span class="tok-operator">/</span>user<span class="tok-operator">/</span><span class="tok-function">preferences</span> (<span class="tok-number">204</span> <span class="tok-type">No</span> <span class="tok-type">Content</span>)
<span class="tok-type">Duration</span><span class="tok-operator">:</span> <span class="tok-number">96</span> ms</code></pre>
<p>Notice how easy it is to see patterns — which endpoints are slow, which ones are frequent, which ones failed.
That’s the essence of <strong>observability</strong> — not more data, but <em>useful</em> data.</p>
<hr>
<h2>Real-World Use</h2>
<p>I use <code>OpenAPILoggingMiddleware</code> in all my OpenAPI projects — from small prototypes to complex SSE (Server-Sent Events) systems. It’s particularly valuable when debugging <strong>streamed responses</strong> or <strong>multipart form uploads</strong>, where conventional logs become unreadable.</p>
<p>Because it’s a simple <code>OpenAPIMiddleware</code>, it works with any generated server conforming to the OpenAPI ecosystem — including custom transports and pure SwiftNIO backends.</p>
<hr>
<h2>Closing Thoughts</h2>
<p>This middleware is a reminder that sometimes the simplest tools make the biggest difference.
It’s easy to underestimate the power of <strong>well-designed visibility</strong> — until you remove it and start guessing again.</p>
<p>Whether you’re debugging mock routes, profiling API latency, or simply curious about what your server is doing, <code>OpenAPILoggingMiddleware</code> gives you that quiet transparency every developer deserves.</p>
<p>👉 <strong>Codeberg:</strong> <a href="https://codeberg.org/OpenAPIHQ/OpenAPILoggingMiddleware">OpenAPIHQ/OpenAPILoggingMiddleware</a></p>
<hr>
<p><em>“Clean code should be composable, testable, and visible when it runs.”</em></p>]]></content:encoded>
</item>
<item>
<title>ExtremePackaging</title>
<link>https://aleahim.com/blog/extreme-packaging/</link>
<guid isPermaLink="true">https://aleahim.com/blog/extreme-packaging/</guid>
<pubDate>Sat, 13 Sep 2025 00:00:00 +0000</pubDate>
<dc:creator>Mihaela Mihaljević</dc:creator>
<description>Example of Extreme Packaging in Swift</description>
<content:encoded><![CDATA[<p>A Modular Architecture Methodology for Swift Projects
By Mihaela Mihaljević</p>
<h2>Introduction</h2>
<p><strong>Extreme Packaging</strong> is a methodology for structuring Swift projects with <em>maximal modularity and minimal responsibility per module.</em>
Each module represents a single, isolated unit of logic — small enough to reason about, easy to test, and replaceable without side effects.</p>
<p>The core idea is <strong>separation</strong>:
modules depend on stable interfaces, not on each other’s implementations. This enables scalable architectures that remain flexible as projects evolve, while keeping build times short and dependencies explicit.</p>
<p><strong>Table Of Contents:</strong></p>
<ul><li><p>Part 1 — Project Setup</p></li><li><p>Part 2 — Tooling</p></li></ul>
<h3>Goals</h3>
<ul><li><p>Promote clean boundaries between domains and features</p></li><li><p>Enable independent development and testing per package</p></li><li><p>Simplify refactoring and dependency management</p></li><li><p>Keep compilation fast and the architecture transparent</p></li></ul>
<h3>Process</h3>
<p>The repository is organized into <strong>stages</strong>, each representing a self-contained checkpoint in the project’s evolution.
When moving between stages — especially when reverting to earlier ones — always reset and clean your workspace to ensure it matches the intended state.</p>
<p>Here’s the example for <strong>stage 01</strong>:</p>
<pre><code class="language-bash"><span class="tok-comment"># Ensure you're on the branch you want</span>
git checkout stage<span class="tok-operator">/</span><span class="tok-number">01</span><span class="tok-operator">-</span>init<span class="tok-operator">-</span>packages

<span class="tok-comment"># Fetch the latest version</span>
git fetch orig<span class="tok-keyword">in</span>

<span class="tok-comment"># Reset your branch to the remote version</span>
git reset <span class="tok-operator">-</span><span class="tok-operator">-</span>hard stage<span class="tok-operator">/</span><span class="tok-number">01</span><span class="tok-operator">-</span>init<span class="tok-operator">-</span>packages

<span class="tok-comment"># Delete untracked files and directories</span>
git clean <span class="tok-operator">-</span>fdx</code></pre>
<h3>Philosophy</h3>
<p>In most projects, modularization is an afterthought — introduced when the codebase becomes too large to manage.
<strong>Extreme Packaging</strong> inverts that approach: modularization is the starting point.
By treating each package as an autonomous component from day one, you gain clarity, resilience, and a foundation that naturally scales with complexity.</p>
<h2>Part 1 — Project Setup</h2>
<p>The first step in <strong>Extreme Packaging</strong> is establishing a clear and reproducible project structure that can evolve gradually through defined stages.
Each stage in the repository builds upon the previous one — from the initial package setup, to workspace creation, and finally to adding the app target that ties everything together.</p>
<h3>Overview</h3>
<p>The project begins as a <strong>Swift Package Manager–based structure</strong>, designed for modularity from the start.
At its core is a single <code>Packages</code> directory that houses all functional modules (such as <code>AppFeature</code>, <code>SharedModels</code>, and later others).
Every addition to the project — whether a new feature, UI layer, or platform target — is layered on top of this foundation in small, trackable increments.</p>
<p>Here is the link to the project used:
<a href="https://codeberg.org/Mihaela/ExtremePackaging/src/branch/stage/01-init-packages">https://codeberg.org/Mihaela/ExtremePackaging</a></p>
<h3>1.1 Stage 01 — Initialize Packages</h3>
<h4>Purpose</h4>
<p>This stage ensures a working, self-contained Swift package that compiles and passes initial linting checks.</p>
<h4>Parts</h4>
<p>At <strong>stage/01-init-packages</strong>, the repository contains:</p>
<ul><li><p>A minimal <strong>package structure</strong> with <code>Sources</code> and <code>Tests</code></p></li><li><p><strong>Core configuration file</strong>s:</p>
<ul><li><p><code>.swiftlint.yml</code> for linting rules</p></li><li><p><code>.swiftformat</code> for consistent formatting</p></li><li><p><code>.gitignore</code>, <code>LICENSE</code>, and <code>README.md</code></p></li></ul></li><li><p><strong>Two base modules</strong>:</p>
<ul><li><p><code>AppFeature</code> — serves as the entry feature for the app</p></li><li><p><code>SharedModels</code> — holds simple model definitions</p></li></ul></li></ul>
<h4>Folder Structure snapshot</h4>
<p>Example folder structure:
![A Finder list view of the ExtremePackaging folder: Packages (with Tests/AppFeatureTests/AppTests.swift, Package.swift, and Sources/SharedModels/DummyModel.swift and Sources/AppFeature/AppView.swift), .git, Apps, README.md, LICENSE and .gitignore.](/images/xpack/Screenshot 2025-03-31 at 17.07.23.png)</p>
<p>Inside the  folder:</p>
<pre><code class="language-bash">
➜  ExtremePackaging git<span class="tok-operator">:</span>(ma<span class="tok-keyword">in</span>) ✗ ls <span class="tok-operator">-</span>all
 <span class="tok-operator">.</span>
 <span class="tok-operator">.</span><span class="tok-operator">.</span>
 <span class="tok-operator">.</span>git
 <span class="tok-operator">.</span>gitignore
 <span class="tok-operator">.</span>swiftformat
 <span class="tok-operator">.</span>swiftlint<span class="tok-operator">.</span>yml
 Apps
 LICENSE
 Packages
 README<span class="tok-operator">.</span>md</code></pre>
<p>Inside the <code>Packages</code> folder:</p>
<pre><code class="language-bash">➜  ExtremePackaging git<span class="tok-operator">:</span>(ma<span class="tok-keyword">in</span>) cd Packages
➜  Packages git<span class="tok-operator">:</span>(ma<span class="tok-keyword">in</span>) ls <span class="tok-operator">-</span>all
 <span class="tok-operator">.</span>
 <span class="tok-operator">.</span><span class="tok-operator">.</span>
 Package<span class="tok-operator">.</span>swift
 Sources
 Tests</code></pre>
<p>Inside the <code>Apps</code> folder:</p>
<pre><code class="language-bash"><span class="tok-operator">.</span>
<span class="tok-operator">.</span><span class="tok-operator">.</span>
<span class="tok-operator">.</span>gitkeep</code></pre>
<h4>Basic Package Code:</h4>
<p>I start with package structure like this:</p>
<pre><code class="language-swift"><span class="tok-comment">// swift-tools-version: 6.0</span>

<span class="tok-keyword">import</span> <span class="tok-type">PackageDescription</span>

<span class="tok-keyword">let</span> <span class="tok-keyword">package</span> <span class="tok-operator">=</span> <span class="tok-keyword">Package</span>(
    name<span class="tok-operator">:</span> <span class="tok-string">"Main"</span>,
    platforms<span class="tok-operator">:</span> [
        <span class="tok-operator">.</span><span class="tok-function">iOS</span>(<span class="tok-operator">.</span>v<span class="tok-number">17</span>),
        <span class="tok-operator">.</span><span class="tok-function">macOS</span>(<span class="tok-operator">.</span>v<span class="tok-number">14</span>),
    ],
    products<span class="tok-operator">:</span> [
        <span class="tok-operator">.</span><span class="tok-function">singleTargetLibrary</span>(<span class="tok-string">"AppFeature"</span>),
    ],
    dependencies<span class="tok-operator">:</span> [
        <span class="tok-operator">.</span><span class="tok-keyword">package</span>(url<span class="tok-operator">:</span> <span class="tok-string">"https://github.com/realm/SwiftLint"</span>, exact<span class="tok-operator">:</span> <span class="tok-string">"0.52.3"</span>),
    ],
    targets<span class="tok-operator">:</span> [
        <span class="tok-operator">.</span><span class="tok-function">target</span>(
            name<span class="tok-operator">:</span> <span class="tok-string">"AppFeature"</span>,
            dependencies<span class="tok-operator">:</span> [
                <span class="tok-string">"SharedModels"</span>,
            ]
        ),
        <span class="tok-operator">.</span><span class="tok-function">testTarget</span>(
            name<span class="tok-operator">:</span> <span class="tok-string">"AppFeatureTests"</span>,
            dependencies<span class="tok-operator">:</span> [
                <span class="tok-string">"AppFeature"</span>
            ]
        ),
        <span class="tok-operator">.</span><span class="tok-function">target</span>(
            name<span class="tok-operator">:</span> <span class="tok-string">"SharedModels"</span>
        )
    ]
)

<span class="tok-comment">// Inject base plugins into each target</span>
<span class="tok-keyword">package</span><span class="tok-operator">.</span>targets <span class="tok-operator">=</span> <span class="tok-keyword">package</span><span class="tok-operator">.</span>targets<span class="tok-operator">.</span>map { target <span class="tok-keyword">in</span>
    <span class="tok-keyword">var</span> plugins <span class="tok-operator">=</span> target<span class="tok-operator">.</span>plugins <span class="tok-operator">?</span><span class="tok-operator">?</span> []
    plugins<span class="tok-operator">.</span><span class="tok-function">append</span>(<span class="tok-operator">.</span><span class="tok-function">plugin</span>(name<span class="tok-operator">:</span> <span class="tok-string">"SwiftLintPlugin"</span>, <span class="tok-keyword">package</span><span class="tok-operator">:</span> <span class="tok-string">"SwiftLint"</span>))
    target<span class="tok-operator">.</span>plugins <span class="tok-operator">=</span> plugins
    <span class="tok-keyword">return</span> tar<span class="tok-keyword">get</span>
}

<span class="tok-keyword">extension</span> <span class="tok-type">Product</span> {
    <span class="tok-keyword">static</span> <span class="tok-keyword">func</span> <span class="tok-function">singleTargetLibrary</span>(_ name<span class="tok-operator">:</span> <span class="tok-type">String</span>) <span class="tok-operator">-</span><span class="tok-operator">&gt;</span> <span class="tok-type">Product</span> {
        <span class="tok-operator">.</span><span class="tok-function">library</span>(name<span class="tok-operator">:</span> name, targets<span class="tok-operator">:</span> [name])
    }
}</code></pre>
<h4>Dummy Files</h4>
<h5>AppView</h5>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">SharedModels</span>
<span class="tok-keyword">import</span> <span class="tok-type">SharedViews</span>
<span class="tok-keyword">import</span> <span class="tok-type">SwiftUI</span>

<span class="tok-keyword">public</span> <span class="tok-keyword">struct</span> <span class="tok-type">AppView</span><span class="tok-operator">:</span> <span class="tok-type">View</span> {
    <span class="tok-keyword">public</span> <span class="tok-keyword">var</span> body<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">View</span> {
        <span class="tok-type">VStack</span> {
            <span class="tok-type">Text</span>(<span class="tok-string">"Extreme Packaging!"</span>)
                <span class="tok-operator">.</span><span class="tok-function">font</span>(<span class="tok-operator">.</span>title)
                <span class="tok-operator">.</span><span class="tok-function">fontWeight</span>(<span class="tok-operator">.</span>bold)
                <span class="tok-operator">.</span><span class="tok-function">multilineTextAlignment</span>(<span class="tok-operator">.</span>center)
                <span class="tok-operator">.</span><span class="tok-function">padding</span>()
        }
    }
}</code></pre>
<h5>DummyModel</h5>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">Foundation</span>

<span class="tok-keyword">public</span> <span class="tok-keyword">struct</span> <span class="tok-type">DummyModel</span><span class="tok-operator">:</span> <span class="tok-type">Identifiable</span> {
    <span class="tok-keyword">public</span> <span class="tok-keyword">var</span> id<span class="tok-operator">:</span> <span class="tok-type">UUID</span> <span class="tok-operator">=</span> <span class="tok-operator">.</span><span class="tok-keyword">init</span>()
    <span class="tok-keyword">public</span> <span class="tok-keyword">var</span> title<span class="tok-operator">:</span> <span class="tok-type">String</span>
    <span class="tok-keyword">public</span> <span class="tok-keyword">init</span>(
        id<span class="tok-operator">:</span> <span class="tok-type">UUID</span> <span class="tok-operator">=</span> <span class="tok-operator">.</span><span class="tok-keyword">init</span>(),
        title<span class="tok-operator">:</span> <span class="tok-type">String</span>
    ) {
        <span class="tok-keyword">self</span><span class="tok-operator">.</span>id <span class="tok-operator">=</span> id
        <span class="tok-keyword">self</span><span class="tok-operator">.</span>title <span class="tok-operator">=</span> title
    }
}</code></pre>
<h4>Stage 01-init-packages</h4>
<p>Here’s the code for <strong>stage 01</strong>:</p>
<pre><code class="language-bash">
<span class="tok-comment"># Clone repo if needed</span>
git clone https<span class="tok-operator">:</span><span class="tok-operator">/</span><span class="tok-operator">/</span>codeberg<span class="tok-operator">.</span>org<span class="tok-operator">/</span>Mihaela<span class="tok-operator">/</span>ExtremePackaging<span class="tok-operator">.</span>git

<span class="tok-comment"># Ensure you're on the branch you want</span>
git checkout stage<span class="tok-operator">/</span><span class="tok-number">01</span><span class="tok-operator">-</span>init<span class="tok-operator">-</span>packages

<span class="tok-comment"># Fetch the latest version</span>
git fetch orig<span class="tok-keyword">in</span>

<span class="tok-comment"># Reset your branch to the remote version</span>
git reset <span class="tok-operator">-</span><span class="tok-operator">-</span>hard stage<span class="tok-operator">/</span><span class="tok-number">01</span><span class="tok-operator">-</span>init<span class="tok-operator">-</span>packages

<span class="tok-comment"># Delete untracked files and directories</span>
git clean <span class="tok-operator">-</span>fdx</code></pre>
<p>To see how it looks in <strong>Xcode</strong> we need to switch to subfolder <code>packages</code>, since we haven’t created the workspace yet.</p>
<pre><code class="language-bash">➜  ExtremePackaging git<span class="tok-operator">:</span>(stage<span class="tok-operator">/</span><span class="tok-number">01</span><span class="tok-operator">-</span>init<span class="tok-operator">-</span>packages) ✗ cd Packages
➜  Packages git<span class="tok-operator">:</span>(stage<span class="tok-operator">/</span><span class="tok-number">01</span><span class="tok-operator">-</span>init<span class="tok-operator">-</span>packages) ✗ xed <span class="tok-operator">.</span></code></pre>
<h3>1.2 Stage 02 — Add Workspace</h3>
<h4>Purpose</h4>
<p>In <strong>stage/02-workspace-added</strong>, an Xcode <strong>workspace</strong> named <code>Main.xcworkspace</code> is introduced at the project root.
It includes the <code>Packages</code> folder, allowing smooth integration of multiple modules while keeping them decoupled.
This step establishes the foundation for a multi-target environment.</p>
<h4>Workspace creation steps</h4>
<p>Create a new workspace (I name it <code>Main</code>), in the root of our folder.</p>
<p><img src="https://aleahim.com/images/xpack/workspace.png" alt="The macOS save dialog naming a new file Main.xcworkspace, saved in the ExtremePackaging folder, which already holds Apps, Packages, README.md and LICENSE."></p>
<p>Add folder <code>Packages</code> to the workspace.
It will add our package structure to the project:</p>
<p>![Xcode with Package.swift open in a workspace named Main: the navigator lists Packages (Package.swift, Sources, Tests, Package.resolved) and nine package dependencies, and the editor shows the file’s first lines, starting with swift-tools-version 6.0.](/images/xpack/Screenshot 2025-03-31 at 18.33.55.png)</p>
<h4>Stage 02-add—to-workspace</h4>
<p>Here’s the code for <strong>stage 02</strong>:</p>
<pre><code class="language-bash">
<span class="tok-comment"># Clone repo if needed</span>
git clone https<span class="tok-operator">:</span><span class="tok-operator">/</span><span class="tok-operator">/</span>codeberg<span class="tok-operator">.</span>org<span class="tok-operator">/</span>Mihaela<span class="tok-operator">/</span>ExtremePackaging<span class="tok-operator">.</span>git

<span class="tok-comment"># Ensure you're on the branch you want</span>
git checkout stage<span class="tok-operator">/</span><span class="tok-number">02</span><span class="tok-operator">-</span>add—to<span class="tok-operator">-</span>workspace

<span class="tok-comment"># Fetch the latest version</span>
git fetch orig<span class="tok-keyword">in</span>

<span class="tok-comment"># Reset your branch to the remote version</span>
git reset <span class="tok-operator">-</span><span class="tok-operator">-</span>hard stage<span class="tok-operator">/</span><span class="tok-number">02</span><span class="tok-operator">-</span>add—to<span class="tok-operator">-</span>workspace

<span class="tok-comment"># Delete untracked files and directories</span>
git clean <span class="tok-operator">-</span>fdx</code></pre>
<p>Now we have the <strong>workspace</strong>, so we just need to open <strong>Xcode</strong>:</p>
<pre><code class="language-bash">➜  Packages git<span class="tok-operator">:</span>(stage<span class="tok-operator">/</span><span class="tok-number">02</span><span class="tok-operator">-</span>add—to<span class="tok-operator">-</span>workspace) ✗ xed <span class="tok-operator">.</span>
➜  Packages git<span class="tok-operator">:</span>(stage<span class="tok-operator">/</span><span class="tok-number">02</span><span class="tok-operator">-</span>add—to<span class="tok-operator">-</span>workspace) ✗</code></pre>
<h3>1.3 Stage 03 — Add iOS and macOS App Targets</h3>
<h4>Platform targets creation</h4>
<p><strong>Add new iOS and a new macOS project</strong>
Repeat this for each target:</p>
<p>Create a new project in Xcode:</p>
<p><img src="https://aleahim.com/images/xpack/macos1.jpg" alt="Xcode’s template chooser for a new project with the macOS tab selected, listing App, Document App, Game, Spatial Rendering App, Command Line Tool and Safari Extension App, then Framework, Library, Metal Library, XPC Service and Bundle."></p>
<p><img src="https://aleahim.com/images/xpack/macos2.jpg" alt="The options sheet for a new Xcode project: Product Name macApp, Organization Identifier extremepackaging.com, Interface SwiftUI, Language Swift, Testing System None, Storage None."></p>
<p>Add each to <code>Apps</code> folder:</p>
<p><img src="https://aleahim.com/images/xpack/macosFolder.jpg" alt="The save sheet for the new project with the ExtremePackaging folder open and its Apps folder selected, with the Source Control option unavailable because the folder already holds a Git repository, and “Don’t add to any project or workspace” chosen."></p>
<h4>Adding them to workspace</h4>
<p>We will be adding each app target to the workspace, below <em>Packages</em>.
Open the current repository folder and drag both new projects (iOS and macOS) into the workspace sidebar.</p>
<p>Each target remains isolated within its own folder, but both share the same logic through the <em>AppFeature</em> module.
This ensures that all common code — views, models, and reducers — stays within shared packages, while each platform target keeps its own configuration files.</p>
<p>Open the current repo folder:
<img src="https://aleahim.com/images/xpack/show_in_finder.jpg" alt="Xcode’s context menu on the Packages folder in the navigator with “Show in Finder” highlighted, above Open in New Tabs, Open in New Window, Add Files to “Main”, Add Package Dependencies, Delete and New Folder."></p>
<p><img src="https://aleahim.com/images/xpack/folders_on_disk.jpg" alt="Xcode beside a Finder window: the ExtremePackaging folder on disk holds Apps (macApp and iosApp, each with its .xcodeproj), Main.xcworkspace, Packages (Package.swift, Sources/AppFeature, Sources/SharedModels, Tests/AppFeatureTests), .gitignore, README.md, LICENSE, .swiftlint.yml and .swiftformat."></p>
<p>Add <strong>macOS</strong> target:</p>
<p><img src="https://aleahim.com/images/xpack/add_macos.jpg" alt="The Xcode sheet “Choose options for adding these files” with the action “Reference files in place”, over Xcode and a Finder window in which macApp.xcodeproj is selected."></p>
<p>Choose “Reference files in place”</p>
<p><img src="https://aleahim.com/images/xpack/reference_files.jpg" alt="The same sheet close up: the action “Reference files in place”, an empty Targets list marked “Not Applicable”, and the Finish button under the pointer."></p>
<p>This is how it looks when added:</p>
<p><img src="https://aleahim.com/images/xpack/add_macOS_done.jpg" alt="Xcode after adding the macApp project: macApp now appears above Packages in the navigator, and its target page shows Supported Destinations with Mac, above the Minimum Deployments and Identity sections."></p>
<p>Add <strong>iOS</strong> target:</p>
<p><img src="https://aleahim.com/images/xpack/add_iOS.jpg" alt="Dragging iosApp.xcodeproj from a Finder window onto the macApp row at the top of Xcode’s navigator; the Finder window lists the Apps folder with macApp and iosApp."></p>
<p>This is how it looks when added:</p>
<p><img src="https://aleahim.com/images/xpack/add_iOS_done.jpg" alt="Xcode with both projects in the navigator, iosApp and macApp above Packages; the iosApp target lists supported destinations iPhone, iPad, Mac (Designed for iPad) and Apple Vision (Designed for iPad), with a minimum iOS deployment of 26.0."></p>
<h4>Explanation: Why separate targets</h4>
<p>Keeping iOS and macOS projects distinct allows:</p>
<ul><li><p>Independent platform configuration (e.g. Info.plist, app icons, signing settings)</p></li><li><p>Platform-specific features when needed (e.g. menu commands on macOS, touch gestures on iOS)</p></li><li><p>Consistent architecture and shared logic through modular Swift packages</p></li></ul>
<p>This structure aligns perfectly with the <strong>Extreme Packaging</strong> philosophy — shared foundation, platform-specific shells.</p>
<h4>Configuration steps</h4>
<ul><li><p>Delete automatically added <code>ContentView.swift</code></p></li><li><p>Add <code>AppFeature</code> package to the our target:</p></li></ul>
<p><img src="https://aleahim.com/images/xpack/AppTarget05.png" alt="The Xcode sheet “Choose frameworks and libraries to add” with the AppFeature library of the Main package selected under Workspace, above the list of Apple SDK frameworks, and the Add button under the pointer."></p>
<p>Now our project looks like this:
<img src="https://aleahim.com/images/xpack/AppTarget06.png" alt="Xcode with the SwiftUIApp project below Packages and SwiftUIAppApp.swift open: it imports SwiftUI and AppFeature and declares the @main App whose WindowGroup shows AppView()."></p>
<p>And the main app starts with the fully testable <code>AppFeature</code></p>
<p><img src="https://aleahim.com/images/xpack/AppTarget07.png" alt="Xcode with Packages/Tests/AppFeatureTests/AppTests.swift open: a test class AppTests with one empty test, testExample, and the SwiftUIApp project in the navigator."></p>
<pre><code class="language-swift"><span class="tok-keyword">import</span> <span class="tok-type">SwiftUI</span>
<span class="tok-keyword">import</span> <span class="tok-type">AppFeature</span>

<span class="tok-attribute">@main</span>
<span class="tok-keyword">struct</span> <span class="tok-type">SwiftUIAppApp</span><span class="tok-operator">:</span> <span class="tok-type">App</span> {
    <span class="tok-keyword">var</span> body<span class="tok-operator">:</span> <span class="tok-keyword">some</span> <span class="tok-type">Scene</span> {
        <span class="tok-type">WindowGroup</span> {
            <span class="tok-type">AppView</span>()
        }
    }
}</code></pre>
<h4>Final structure</h4>
<p>At this point, the project has evolved into a fully cross-platform modular setup.</p>
<p>The screenshot below illustrates the final structure after completing <strong>Stage 03 (iOS &amp; macOS targets added)</strong>:</p>
<p><img src="https://aleahim.com/images/xpack/final_struc.jpg" alt="The final project structure in Xcode’s navigator: Packages (Package.swift, Sources with AppFeature and SharedModels, Tests), then the iosApp and macApp projects, each with Assets.xcassets, ContentView.swift and its App file; Package.swift is open on the right."></p>
<ul><li><p>The <strong>Packages</strong> directory defines the shared Swift Package with <code>AppFeature</code> and <code>SharedModels</code> modules.</p></li><li><p>Both <strong>iOS</strong> and <strong>macOS</strong> apps live inside the <code>Apps</code> folder, each with its own assets, entry point, and platform-specific configuration files.</p></li><li><p>The <strong><code>Package.swift</code></strong> file defines a single modular product, with SwiftLint integrated as a plugin and dependencies kept cleanly separated.</p></li><li><p>This structure enables both platforms to share logic and UI built with <strong>SwiftUI</strong>, while still allowing native customization per platform.</p></li></ul>
<p><strong>Result:</strong>
A clean, modular workspace where shared code resides in packages, and each platform acts only as a thin presentation shell — the essence of <em>Extreme Packaging</em>.</p>
<h4>Stage 03-apps-added</h4>
<p>In <strong>stage/03-apps-added</strong>, we create two separate app targets — one for <strong>iOS</strong> and one for <strong>macOS</strong> — both sharing the same SwiftUI core logic.</p>
<p>Each app lives inside the <code>Apps</code> folder and imports the <code>AppFeature</code> module, demonstrating how the same feature package can power multiple platforms with no duplicated code.</p>
<p>After adding the targets:</p>
<ul><li><p>Delete the automatically generated <code>ContentView.swift</code></p></li><li><p>Add the <code>AppFeature</code> package dependency to both targets</p></li><li><p>Verify that both apps build successfully</p></li></ul>
<p>This stage concludes with a fully functional cross-platform setup where both iOS and macOS share a unified architecture driven by modular packages.</p>
<p>Here’s the code for <strong>stage 03</strong>:</p>
<pre><code class="language-bash">
<span class="tok-comment"># Clone repo if needed</span>
git clone https<span class="tok-operator">:</span><span class="tok-operator">/</span><span class="tok-operator">/</span>codeberg<span class="tok-operator">.</span>org<span class="tok-operator">/</span>Mihaela<span class="tok-operator">/</span>ExtremePackaging<span class="tok-operator">.</span>git

<span class="tok-comment"># Ensure you're on the branch you want</span>
git checkout stage<span class="tok-operator">/</span><span class="tok-number">03</span><span class="tok-operator">-</span>apps<span class="tok-operator">-</span>added

<span class="tok-comment"># Fetch the latest version</span>
git fetch orig<span class="tok-keyword">in</span>

<span class="tok-comment"># Reset your branch to the remote version</span>
git reset <span class="tok-operator">-</span><span class="tok-operator">-</span>hard stage<span class="tok-operator">/</span><span class="tok-number">03</span><span class="tok-operator">-</span>apps<span class="tok-operator">-</span>added

<span class="tok-comment"># Delete untracked files and directories</span>
git clean <span class="tok-operator">-</span>fdx</code></pre>
<h3>Summary</h3>
<table><thead><tr><th style="text-align:left">Stage</th><th style="text-align:left">Description</th><th style="text-align:left">Key Additions</th></tr></thead><tbody><tr><td style="text-align:left"><strong>01</strong></td><td style="text-align:left">Initial package setup</td><td style="text-align:left"><code>Package.swift</code>, SwiftLint &amp; SwiftFormat configs, dummy modules (<code>AppFeature</code>, <code>SharedModels</code>)</td></tr><tr><td style="text-align:left"><strong>02</strong></td><td style="text-align:left">Workspace creation</td><td style="text-align:left"><code>Main.xcworkspace</code>, integrated <code>Packages</code> folder for modular management</td></tr><tr><td style="text-align:left"><strong>03</strong></td><td style="text-align:left">iOS &amp; macOS app targets added</td><td style="text-align:left">Separate iOS and macOS apps in <code>Apps/</code>, both using <code>AppFeature</code> for shared SwiftUI logic</td></tr></tbody></table>
<p>Each stage corresponds to a dedicated branch in the repository, allowing you to switch between checkpoints and observe the project’s evolution step by step.
This structure provides a transparent history of how a modular Swift project grows from a single package into a fully multi-platform architecture.</p>
<h2>Part 2 — Tooling</h2>
<ul><li><p>Every project includes <strong>SwiftLint</strong> and <strong>SwiftFormat</strong> for enforcing consistent code style and quality</p></li><li><p>Each stage of the repository introduces incremental improvements, from initializing packages to adding app targets and integrations</p></li><li><p>These are applied from the very first stage but can be customized at any point.</p></li></ul>
<h3>GitIgnore</h3>
<pre><code class="language-bash"><span class="tok-comment"># Xcode</span>
<span class="tok-comment">#</span>
<span class="tok-comment"># gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore &amp; Swift.gitignore</span>

<span class="tok-comment">## User settings</span>
xcuserdata<span class="tok-operator">/</span>

<span class="tok-comment">## Obj-C/Swift specific</span>
<span class="tok-operator">*</span><span class="tok-operator">.</span>hmap

<span class="tok-comment">## App packaging</span>
<span class="tok-operator">*</span><span class="tok-operator">.</span>ipa
<span class="tok-operator">*</span><span class="tok-operator">.</span>dSYM<span class="tok-operator">.</span>zip
<span class="tok-operator">*</span><span class="tok-operator">.</span>dSYM

<span class="tok-comment">## Playgrounds</span>
timeline<span class="tok-operator">.</span>xctimeline
playground<span class="tok-operator">.</span>xcworkspace

<span class="tok-comment"># Swift Package Manager</span>
<span class="tok-operator">.</span>build<span class="tok-operator">/</span>
<span class="tok-operator">.</span>swiftpm<span class="tok-operator">/</span>
Package<span class="tok-operator">.</span>resolved

<span class="tok-comment"># Xcode workspace &amp; projects</span>
<span class="tok-operator">*</span><span class="tok-operator">.</span>xcworkspace<span class="tok-operator">/</span>xcshareddata<span class="tok-operator">/</span>WorkspaceSettings<span class="tok-operator">.</span>xcsettings
<span class="tok-operator">*</span><span class="tok-operator">.</span>xcworkspace<span class="tok-operator">/</span>xcuserdata<span class="tok-operator">/</span>
DerivedData<span class="tok-operator">/</span>
<span class="tok-operator">*</span><span class="tok-operator">.</span>xcuserstate
<span class="tok-operator">*</span><span class="tok-operator">.</span>xcscmblueprint
<span class="tok-operator">*</span><span class="tok-operator">.</span>xccheckout

<span class="tok-comment"># macOS system files</span>
<span class="tok-operator">.</span>DS_Store

<span class="tok-comment"># Carthage</span>
Carthage<span class="tok-operator">/</span>Build<span class="tok-operator">/</span>

<span class="tok-comment"># fastlane</span>
fastlane<span class="tok-operator">/</span>report<span class="tok-operator">.</span>xml
fastlane<span class="tok-operator">/</span>Preview<span class="tok-operator">.</span>html
fastlane<span class="tok-operator">/</span>screenshots<span class="tok-operator">/</span><span class="tok-operator">*</span><span class="tok-operator">*</span><span class="tok-operator">/</span><span class="tok-operator">*</span><span class="tok-operator">.</span>png
fastlane<span class="tok-operator">/</span>test_output

<span class="tok-comment"># Custom folders used in ExtremePackaging</span>
Stage<span class="tok-operator">/</span>
Tasks<span class="tok-operator">/</span><span class="tok-operator">.</span>build<span class="tok-operator">/</span></code></pre>
<h3>SwiftFormat Config</h3>
<p>This is my <code>.swiftformat</code></p>
<pre><code class="language-yaml"><span class="tok-comment"># General Options</span>
--swiftversion <span class="tok-number">5.7</span>

<span class="tok-comment"># File Options</span>
--exclude Stage<span class="tok-operator">,</span>Tasks/.build<span class="tok-operator">,</span>ThirdParty<span class="tok-operator">,</span>**/SwiftGen/*<span class="tok-operator">,</span>**/Sourcery/*<span class="tok-operator">,</span>Frameworks/swift-composable-architecture<span class="tok-operator">,</span>**.generated.swift

<span class="tok-comment"># Format Options</span>

--allman <span class="tok-literal">false</span>
--binarygrouping none
--closingparen balanced
--commas always
--conflictmarkers reject
--decimalgrouping none
--elseposition same-line
--exponentcase lowercase
--exponentgrouping disabled
--fractiongrouping disabled
--fragment <span class="tok-literal">false</span>
--header ignore
--hexgrouping none
--hexliteralcase lowercase
--ifdef <span class="tok-literal">no</span>-indent
--importgrouping alphabetized
--indent <span class="tok-number">4</span>
--indentcase <span class="tok-literal">false</span>
<span class="tok-comment"># make sure this matches .swiftlint</span>
--maxwidth <span class="tok-number">180</span>
--nospaceoperators ..&lt;<span class="tok-operator">,</span>...
--octalgrouping none
--operatorfunc <span class="tok-literal">no</span>-space
--selfrequired
--stripunusedargs closure-only
--trailingclosures
--wraparguments before-first
--wrapcollections before-first
--wrapparameters before-first

<span class="tok-comment"># Rules</span>
--disable hoistAwait
--disable hoistPatternLet
--disable hoistTry
--disable wrapMultilineStatementBraces
--disable extensionAccessControl</code></pre>
<h3>SwiftLint Config</h3>
<pre><code class="language-yaml"><span class="tok-property">disabled_rules</span><span class="tok-operator">:</span> <span class="tok-comment"># rule identifiers to exclude from running</span>
  - opening_brace
  - operator_whitespace
  - orphaned_doc_comment

<span class="tok-property">opt_in_rules</span><span class="tok-operator">:</span>
  - empty_count
  - force_unwrapping
  - shorthand_optional_binding
  - weak_delegate

<span class="tok-property">excluded</span><span class="tok-operator">:</span>
  - <span class="tok-string">"*.generated"</span>

<span class="tok-property">custom_rules</span><span class="tok-operator">:</span>
  <span class="tok-comment"># check's for Combine's .assign(to: xxx, on: self) ref-cycle</span>
  <span class="tok-property">combine_assign_to_self</span><span class="tok-operator">:</span>
    <span class="tok-property">included</span><span class="tok-operator">:</span> <span class="tok-string">".*\\.swift"</span>
    <span class="tok-property">name</span><span class="tok-operator">:</span> <span class="tok-string">"`assign` to self"</span>
    <span class="tok-property">regex</span><span class="tok-operator">:</span> <span class="tok-string">'\.assign\(to: [^,]*, on: self\)'</span>
    <span class="tok-property">message</span><span class="tok-operator">:</span> <span class="tok-string">"For assigning on self, use assignNoRetain(to: ..., on: self)."</span>
    <span class="tok-property">severity</span><span class="tok-operator">:</span> error
  <span class="tok-property">duplicate_remove_duplicates</span><span class="tok-operator">:</span>
    <span class="tok-property">included</span><span class="tok-operator">:</span> <span class="tok-string">".*\\.swift"</span>
    <span class="tok-property">name</span><span class="tok-operator">:</span> <span class="tok-string">"Duplicate `removeDuplicates()`"</span>
    <span class="tok-property">message</span><span class="tok-operator">:</span> <span class="tok-string">"ViewStore's publisher already does `removeDuplicates()`"</span>
    <span class="tok-property">regex</span><span class="tok-operator">:</span> <span class="tok-string">'publisher\.[^(|{|,]*removeDuplicates\(\)'</span>
    <span class="tok-property">severity</span><span class="tok-operator">:</span> error
  <span class="tok-property">dont_scale_to_zero</span><span class="tok-operator">:</span>
    <span class="tok-property">included</span><span class="tok-operator">:</span> <span class="tok-string">".*\\.swift"</span>
    <span class="tok-property">name</span><span class="tok-operator">:</span> <span class="tok-string">"Don't scale down to 0."</span>
    <span class="tok-property">regex</span><span class="tok-operator">:</span> <span class="tok-string">"\\.scaleEffect\\([^\\)]*(\\ 0\\ [^\\)]*\\)|0.0(\\ |\\))|\\ 0(\\)|,))"</span>
    <span class="tok-property">message</span><span class="tok-operator">:</span> <span class="tok-string">"Please make sure to pass a number not equal zero, so transformations don't throw warnings like `ignoring singular matrix`."</span>
    <span class="tok-property">severity</span><span class="tok-operator">:</span> error
  <span class="tok-property">use_data_constructor_over_string_member</span><span class="tok-operator">:</span>
    <span class="tok-property">included</span><span class="tok-operator">:</span> <span class="tok-string">".*\\.swift"</span>
    <span class="tok-property">name</span><span class="tok-operator">:</span> <span class="tok-string">"Do not use String.data(using: .utf8)"</span>
    <span class="tok-property">regex</span><span class="tok-operator">:</span> <span class="tok-string">"\\.?data\\(using: \\.utf8\\)"</span>
    <span class="tok-property">message</span><span class="tok-operator">:</span> <span class="tok-string">"Please use Data(string.utf8) instead of String.data(using: .utf8) because the Data constructor is non-optional and Strings are guaranteed to be encodable as .utf8"</span>
    <span class="tok-property">severity</span><span class="tok-operator">:</span> error
  <span class="tok-property">tca_explicit_generics_reducer</span><span class="tok-operator">:</span>
    <span class="tok-property">included</span><span class="tok-operator">:</span> <span class="tok-string">".*\\.swift"</span>
    <span class="tok-property">name</span><span class="tok-operator">:</span> <span class="tok-string">"Explicit Generics for Reducer"</span>
    <span class="tok-property">regex</span><span class="tok-operator">:</span> <span class="tok-string">'Reduce\s+\{'</span>
    <span class="tok-property">message</span><span class="tok-operator">:</span> <span class="tok-string">"Use explicit generics in ReducerBuilder (Reduce&lt;State, Action&gt;) for successful autocompletion."</span>
    <span class="tok-property">severity</span><span class="tok-operator">:</span> error
  <span class="tok-property">tca_scope_unused_closure_parameter</span><span class="tok-operator">:</span>
    <span class="tok-property">name</span><span class="tok-operator">:</span> <span class="tok-string">"TCA Scope Unused Closure Parameter"</span>
    <span class="tok-property">regex</span><span class="tok-operator">:</span> <span class="tok-string">'\.scope\(\s*state\s*:\s*\{\s*\_'</span>
    <span class="tok-property">message</span><span class="tok-operator">:</span> <span class="tok-string">"Explicitly use closure parameter when scoping store (ensures the right state is being mutated)"</span>
    <span class="tok-property">severity</span><span class="tok-operator">:</span> error
  <span class="tok-property">tca_use_observe_viewstore_api</span><span class="tok-operator">:</span>
    <span class="tok-property">name</span><span class="tok-operator">:</span> <span class="tok-string">"TCA ViewStore observe API"</span>
    <span class="tok-property">regex</span><span class="tok-operator">:</span> <span class="tok-string">'ViewStore\(store\.scope'</span>
    <span class="tok-property">message</span><span class="tok-operator">:</span> <span class="tok-string">"Use modern observe: api instead of store.scope"</span>
    <span class="tok-property">severity</span><span class="tok-operator">:</span> error

<span class="tok-property">trailing_comma</span><span class="tok-operator">:</span>
    <span class="tok-property">mandatory_comma</span><span class="tok-operator">:</span> <span class="tok-literal">true</span>

<span class="tok-property">cyclomatic_complexity</span><span class="tok-operator">:</span>
  <span class="tok-property">ignores_case_statements</span><span class="tok-operator">:</span> <span class="tok-literal">true</span>
  <span class="tok-property">warning</span><span class="tok-operator">:</span> <span class="tok-number">20</span>

<span class="tok-property">file_length</span><span class="tok-operator">:</span>
  <span class="tok-property">warning</span><span class="tok-operator">:</span> <span class="tok-number">1000</span>
  <span class="tok-property">error</span><span class="tok-operator">:</span> <span class="tok-number">1000</span>

<span class="tok-property">identifier_name</span><span class="tok-operator">:</span>
  <span class="tok-property">severity</span><span class="tok-operator">:</span> warning
  <span class="tok-property">allowed_symbols</span><span class="tok-operator">:</span> <span class="tok-string">"_"</span>
  <span class="tok-property">min_length</span><span class="tok-operator">:</span> <span class="tok-number">2</span>
  <span class="tok-property">max_length</span><span class="tok-operator">:</span>
    <span class="tok-property">warning</span><span class="tok-operator">:</span> <span class="tok-number">90</span>
    <span class="tok-property">error</span><span class="tok-operator">:</span> <span class="tok-number">90</span>
  <span class="tok-property">excluded</span><span class="tok-operator">:</span>
    - iO
    - id
    - vc
    - x
    - y
    - i
    - pi
    - d

<span class="tok-property">legacy_constant</span><span class="tok-operator">:</span> error
<span class="tok-property">legacy_constructor</span><span class="tok-operator">:</span> error

<span class="tok-property">line_length</span><span class="tok-operator">:</span>
  <span class="tok-property">warning</span><span class="tok-operator">:</span> <span class="tok-number">180</span>
  <span class="tok-property">error</span><span class="tok-operator">:</span> <span class="tok-number">180</span>
  <span class="tok-property">ignores_comments</span><span class="tok-operator">:</span> <span class="tok-literal">true</span>
  <span class="tok-property">ignores_urls</span><span class="tok-operator">:</span> <span class="tok-literal">true</span>

<span class="tok-property">nesting</span><span class="tok-operator">:</span>
  <span class="tok-property">type_level</span><span class="tok-operator">:</span>
    <span class="tok-property">warning</span><span class="tok-operator">:</span> <span class="tok-number">3</span>
    <span class="tok-property">error</span><span class="tok-operator">:</span> <span class="tok-number">3</span>
  <span class="tok-property">function_level</span><span class="tok-operator">:</span>
    <span class="tok-property">warning</span><span class="tok-operator">:</span> <span class="tok-number">5</span>
    <span class="tok-property">error</span><span class="tok-operator">:</span> <span class="tok-number">5</span>

<span class="tok-property">function_parameter_count</span><span class="tok-operator">:</span>
  <span class="tok-property">warning</span><span class="tok-operator">:</span> <span class="tok-number">5</span>

<span class="tok-property">force_cast</span><span class="tok-operator">:</span> warning
<span class="tok-property">force_unwrapping</span><span class="tok-operator">:</span> warning

<span class="tok-property">type_body_length</span><span class="tok-operator">:</span>
  - <span class="tok-number">300</span> <span class="tok-comment"># warning</span>
  - <span class="tok-number">300</span> <span class="tok-comment"># error</span>

<span class="tok-property">large_tuple</span><span class="tok-operator">:</span>
  - <span class="tok-number">3</span>  <span class="tok-comment"># warning</span>
  - <span class="tok-number">10</span> <span class="tok-comment"># error%</span></code></pre>]]></content:encoded>
</item>
</channel>
</rss>
