froggy-docs 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -112,7 +112,8 @@ class _AppState extends State<App> {
112
112
  }
113
113
 
114
114
  final headers = <String, String>{};
115
- if (!hasFiles) headers['Content-Type'] = 'application/json';
115
+ final isGetOrHead = method.toUpperCase() == 'GET' || method.toUpperCase() == 'HEAD';
116
+ if (!hasFiles && !isGetOrHead) headers['Content-Type'] = 'application/json';
116
117
  if (_authHeader.isNotEmpty) headers['Authorization'] = _authHeader;
117
118
  for (final hp in headerParams) {
118
119
  final name = hp['name'] as String;
@@ -148,19 +149,19 @@ class _AppState extends State<App> {
148
149
 
149
150
  final streamed = await req.send();
150
151
  resp = await http.Response.fromStream(streamed);
152
+ } else if (isGetOrHead) {
153
+ resp = await http.get(uri, headers: headers);
151
154
  } else {
152
155
  final req = http.Request(method.toUpperCase(), uri);
153
156
  req.headers.addAll(headers);
154
157
 
155
- if (method.toUpperCase() != 'GET' && method.toUpperCase() != 'HEAD') {
156
- final savedValues = _bodyValues[key] ?? {};
157
- final bodyData = <String, dynamic>{};
158
- for (final entry in (bodyProps ?? {}).entries) {
159
- final val = savedValues[entry.key] ?? '';
160
- if (val.isNotEmpty) bodyData[entry.key] = val;
161
- }
162
- req.body = jsonEncode(bodyData);
158
+ final savedValues = _bodyValues[key] ?? {};
159
+ final bodyData = <String, dynamic>{};
160
+ for (final entry in (bodyProps ?? {}).entries) {
161
+ final val = savedValues[entry.key] ?? '';
162
+ if (val.isNotEmpty) bodyData[entry.key] = val;
163
163
  }
164
+ req.body = jsonEncode(bodyData);
164
165
 
165
166
  final client = http.Client();
166
167
  try {
@@ -136,64 +136,13 @@
136
136
  "200": {
137
137
  "description": "Successful response"
138
138
  }
139
- },
140
- "parameters": [
141
- {
142
- "name": "page",
143
- "in": "query",
144
- "description": "Page number",
145
- "schema": {
146
- "type": "int",
147
- "default": 1
148
- }
149
- },
150
- {
151
- "name": "limit",
152
- "in": "query",
153
- "description": "Items per page",
154
- "schema": {
155
- "type": "int",
156
- "default": 10
157
- }
158
- },
159
- {
160
- "name": "search",
161
- "in": "query",
162
- "description": "Search term",
163
- "schema": {
164
- "type": "string"
165
- }
166
- }
167
- ]
139
+ }
168
140
  },
169
141
  "post": {
170
142
  "summary": "Create user",
171
143
  "responses": {
172
- "201": {
173
- "description": "User created",
174
- "content": {
175
- "application/json": {
176
- "schema": {
177
- "type": "object"
178
- },
179
- "example": {
180
- "id": 1
181
- }
182
- }
183
- }
184
- },
185
- "400": {
186
- "description": "Bad request",
187
- "content": {
188
- "application/json": {
189
- "schema": {
190
- "type": "object"
191
- },
192
- "example": {
193
- "error": "Invalid input"
194
- }
195
- }
196
- }
144
+ "200": {
145
+ "description": "Successful response"
197
146
  }
198
147
  }
199
148
  }
@@ -234,27 +183,6 @@
234
183
  "200": {
235
184
  "description": "Successful response"
236
185
  }
237
- },
238
- "requestBody": {
239
- "content": {
240
- "multipart/form-data": {
241
- "schema": {
242
- "type": "object",
243
- "properties": {
244
- "avatar": {
245
- "type": "string",
246
- "format": "binary",
247
- "description": "User profile picture"
248
- },
249
- "document": {
250
- "type": "string",
251
- "format": "binary",
252
- "description": "Optional PDF attachment"
253
- }
254
- }
255
- }
256
- }
257
- }
258
186
  }
259
187
  }
260
188
  },
@@ -268,7 +196,7 @@
268
196
  },
269
197
  "requestBody": {
270
198
  "content": {
271
- "multipart/form-data": {
199
+ "application/json": {
272
200
  "schema": {
273
201
  "type": "object",
274
202
  "properties": {
@@ -279,11 +207,6 @@
279
207
  "bio": {
280
208
  "type": "string",
281
209
  "description": "User biography"
282
- },
283
- "avatar": {
284
- "type": "string",
285
- "format": "binary",
286
- "description": "Profile picture"
287
210
  }
288
211
  }
289
212
  }
@@ -299,25 +222,7 @@
299
222
  "200": {
300
223
  "description": "Successful response"
301
224
  }
302
- },
303
- "parameters": [
304
- {
305
- "name": "X-Request-ID",
306
- "in": "header",
307
- "description": "Optional trace ID",
308
- "schema": {
309
- "type": "string"
310
- }
311
- },
312
- {
313
- "name": "X-Api-Version",
314
- "in": "header",
315
- "description": "API version",
316
- "schema": {
317
- "type": "string"
318
- }
319
- }
320
- ]
225
+ }
321
226
  }
322
227
  },
323
228
  "/api/items": {
@@ -326,6 +326,20 @@ class ParserEngine {
326
326
  },
327
327
  });
328
328
  }
329
+ final pathParamMatches = RegExp(r'\{(\w+)\}').allMatches(path);
330
+ for (final match in pathParamMatches) {
331
+ final paramName = match.group(1)!;
332
+ if (!parameters.any((p) => p['name'] == paramName && p['in'] == 'path')) {
333
+ parameters.insert(0, {
334
+ "name": paramName,
335
+ "in": "path",
336
+ "required": true,
337
+ "description": '',
338
+ "schema": {"type": "string"},
339
+ });
340
+ }
341
+ }
342
+
329
343
  if (parameters.isNotEmpty) {
330
344
  endpointData['parameters'] = parameters;
331
345
  }
@@ -466,7 +480,10 @@ class ParserEngine {
466
480
  flushEndpoint();
467
481
  if (parts.length >= 3) {
468
482
  currentMethod = parts[1].toUpperCase();
469
- currentPath = parts[2];
483
+ currentPath = parts[2].replaceAllMapped(
484
+ RegExp(r':(\w+)'),
485
+ (m) => '{${m.group(1)}}',
486
+ );
470
487
  } else {
471
488
  _errors.add('@api requires method and path at line $lineNumber');
472
489
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froggy-docs",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Auto-generate API documentation from code annotations. Works with any programming language.",
5
5
  "author": "Kaung Mrat Thu <kaungmratthu.dev@gmail.com>",
6
6
  "homepage": "https://github.com/Kaung-Myat/froggydocs",