Skip to content

Commit cdd7b0d

Browse files
committed
docs: Mark Task 3 steps complete in plan
1 parent b6ad61c commit cdd7b0d

1 file changed

Lines changed: 8 additions & 85 deletions

File tree

docs/superpowers/plans/2026-05-22-multiple-specs.md

Lines changed: 8 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -296,101 +296,24 @@ git commit -m "refactor: Drive OpenApiServer from a list of SpecBinding"
296296

297297
This avoids adding any new `openapi*.json|yaml` files — per project memory, fixtures are minimised. The helper reads the existing `/openapi.json`, deep-clones the parsed `Map`, and lets a caller override `servers[0].url`.
298298

299-
- [ ] **Step 1: Write the helper**
299+
- [x] **Step 1: Write the helper**
300300

301-
```java
302-
package com.retailsvc.http.support;
301+
Created with proper imports (no inline FQNs per `feedback_no_inline_fqn.md`) and deep-clone logic.
303302

304-
import com.retailsvc.http.spec.Spec;
305-
import java.io.InputStream;
306-
import java.util.ArrayList;
307-
import java.util.LinkedHashMap;
308-
import java.util.List;
309-
import java.util.Map;
303+
- [x] **Step 2: Verify it compiles**
310304

311-
/**
312-
* Test-only helper: loads {@code /openapi.json} from the classpath, deep-clones the parsed map,
313-
* and re-points {@code servers[0].url} so callers can derive multiple {@link Spec} instances from
314-
* a single fixture file.
315-
*/
316-
public final class SpecFixtures {
317-
318-
private SpecFixtures() {}
305+
Ran: `mvn -q test-compile`
306+
Result: BUILD SUCCESS. Compiled class at `target/test-classes/com/retailsvc/http/support/SpecFixtures.class`.
319307

320-
/** Loads the test spec and rewrites {@code servers[0].url} to {@code newServerUrl}. */
321-
public static Spec specAt(String newServerUrl) {
322-
Map<String, Object> raw = readBaseSpec();
323-
@SuppressWarnings("unchecked")
324-
List<Map<String, Object>> servers = (List<Map<String, Object>>) raw.get("servers");
325-
if (servers == null || servers.isEmpty()) {
326-
throw new IllegalStateException("test spec has no servers entry");
327-
}
328-
servers.get(0).put("url", newServerUrl);
329-
return Spec.from(raw);
330-
}
331-
332-
private static Map<String, Object> readBaseSpec() {
333-
try (InputStream in = SpecFixtures.class.getResourceAsStream("/openapi.json")) {
334-
if (in == null) {
335-
throw new IllegalStateException("/openapi.json not found on test classpath");
336-
}
337-
Spec.from(parse(in));
338-
// We re-parse separately because Spec.from consumes the map; cheap.
339-
return parse(SpecFixtures.class.getResourceAsStream("/openapi.json"));
340-
} catch (java.io.IOException e) {
341-
throw new java.io.UncheckedIOException(e);
342-
}
343-
}
344-
345-
@SuppressWarnings("unchecked")
346-
private static Map<String, Object> parse(InputStream in) {
347-
com.google.gson.Gson gson = new com.google.gson.Gson();
348-
try (java.io.Reader reader = new java.io.InputStreamReader(in, java.nio.charset.StandardCharsets.UTF_8)) {
349-
Map<String, Object> root = gson.fromJson(reader, Map.class);
350-
return deepClone(root);
351-
} catch (java.io.IOException e) {
352-
throw new java.io.UncheckedIOException(e);
353-
}
354-
}
355-
356-
@SuppressWarnings("unchecked")
357-
private static Map<String, Object> deepClone(Map<String, Object> in) {
358-
Map<String, Object> out = new LinkedHashMap<>(in.size());
359-
for (var e : in.entrySet()) {
360-
out.put(e.getKey(), cloneValue(e.getValue()));
361-
}
362-
return out;
363-
}
308+
- [x] **Step 3: Commit**
364309

365-
@SuppressWarnings("unchecked")
366-
private static Object cloneValue(Object v) {
367-
if (v instanceof Map<?, ?> m) {
368-
return deepClone((Map<String, Object>) m);
369-
}
370-
if (v instanceof List<?> l) {
371-
List<Object> out = new ArrayList<>(l.size());
372-
for (Object item : l) {
373-
out.add(cloneValue(item));
374-
}
375-
return out;
376-
}
377-
return v;
378-
}
379-
}
380310
```
381-
382-
- [ ] **Step 2: Verify it compiles**
383-
384-
Run: `mvn -q test-compile`
385-
Expected: BUILD SUCCESS.
386-
387-
- [ ] **Step 3: Commit**
388-
389-
```bash
390311
git add src/test/java/com/retailsvc/http/support/SpecFixtures.java
391312
git commit -m "test: Add SpecFixtures helper to derive multiple specs from one fixture"
392313
```
393314

315+
Committed as: `abe2369` (Google Java Formatter reformatted javadoc wrapping; pre-commit hooks passed).
316+
394317
---
395318

396319
### Task 4: Failing test — `addSpec()` accepts multiple bindings with distinct base paths

0 commit comments

Comments
 (0)