You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,6 +125,27 @@ public class YourServerLauncher {
125
125
126
126
`Spec.fromPath(Path)` picks the parser by file extension: `.json` is parsed by Gson, `.yaml` / `.yml` by SnakeYAML. Both are optional dependencies of this library — the same Gson that powers the built-in JSON `TypeMapper`, and the same SnakeYAML you'd add explicitly to parse YAML. If the required parser isn't on the classpath the call fails with `IllegalStateException`; parse the file yourself and use `Spec.from(Map<String, Object>)` instead. Any other extension is rejected.
127
127
128
+
To load a spec from the classpath (including from inside a JAR) use the `InputStream` overloads:
129
+
130
+
```java
131
+
Spec spec;
132
+
try (InputStream in =YourServerLauncher.class.getResourceAsStream("/openapi.json")) {
133
+
spec =Spec.fromJson(in); // Gson on the classpath
134
+
}
135
+
```
136
+
137
+
The matching `Spec.fromYaml(InputStream)` uses SnakeYAML. Both close the stream before returning. If you can't (or don't want to) depend on Gson, supply your own JSON parser:
138
+
139
+
```java
140
+
ObjectMapper jackson =newObjectMapper();
141
+
Spec spec;
142
+
try (InputStream in =YourServerLauncher.class.getResourceAsStream("/openapi.json")) {
YAML always parses through SnakeYAML — there's no parser-injecting overload. If you want a different YAML library, decode the stream yourself and call `Spec.from(Map<String, Object>)`.
148
+
128
149
### JSON mapping
129
150
130
151
The library ships an internal `GsonJsonMapper` that is auto-registered for `application/json` when Gson is on the classpath and no user-supplied JSON mapper has been registered. It:
0 commit comments