swaggie 1.8.6 → 1.8.7

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.
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  Swaggie generates TypeScript client code from an OpenAPI 3 specification. Instead of writing API-fetching code by hand, you point Swaggie at your API spec and it outputs a fully typed, ready-to-use client — helping you catch errors at compile time rather than at runtime.
14
14
 
15
- See the [Example section](#example) for a quick demo.
15
+ See the [Example section](#example) for a quick demo, or visit the full documentation at **[yhnavein.github.io/swaggie](https://yhnavein.github.io/swaggie/)** for guides, configuration reference, and an interactive playground.
16
16
 
17
17
  > Inspired by [OpenApi Client](https://github.com/mikestead/openapi-client).
18
18
 
@@ -81,6 +81,7 @@ swaggie -s https://petstore3.swagger.io/api/v3/openapi.json -o ./client/petstore
81
81
  -m, --mode <mode> Generation mode: "full" or "schemas" (default: "full")
82
82
  -d, --schemaStyle <style> Schema object style: "interface" or "type" (default: "interface")
83
83
  --enumStyle <style> Enum style for plain string enums: "union" or "enum" (default: "union")
84
+ --enumNamesStyle <s> Enum member name casing: "original" or "PascalCase" (default: "original")
84
85
  --dateFormat <format> Date handling in schemas: "Date" or "string"
85
86
  --nullables <strategy> Nullable handling: "include", "nullableAsOptional", or "ignore"
86
87
  --preferAny Use "any" instead of "unknown" for untyped values (default: false)
@@ -127,6 +128,7 @@ swaggie -c swaggie.config.json
127
128
  "generationMode": "full",
128
129
  "schemaDeclarationStyle": "interface",
129
130
  "enumDeclarationStyle": "union",
131
+ "enumNamesStyle": "original",
130
132
  "queryParamsSerialization": {
131
133
  "arrayFormat": "repeat",
132
134
  "allowDots": true
@@ -291,6 +293,30 @@ Use `enumDeclarationStyle` (or CLI `--enumStyle`) for plain string enums:
291
293
 
292
294
  Note: this applies only to plain string enums. Non-string enums are still emitted as union types.
293
295
 
296
+ ### Enum Names Style
297
+
298
+ Use `enumNamesStyle` (or CLI `--enumNamesStyle`) to control the casing of enum member names when `enumDeclarationStyle` is `"enum"`:
299
+ - `"original"` (default): member names are used exactly as they appear in the spec
300
+ - `"PascalCase"`: member names are converted to PascalCase
301
+
302
+ ### `x-ts-type` Extension
303
+
304
+ Add `x-ts-type` to any schema in your spec to emit a verbatim TypeScript type string instead of deriving it from the schema definition. This is useful for intersection types, complex mapped types, or any TypeScript construct that cannot be expressed in OpenAPI's type system:
305
+
306
+ ```yaml
307
+ ResourceAccess:
308
+ x-ts-type: >-
309
+ { items?: { [key: string]: Entry } } & { [key: string]: boolean | Entry | undefined }
310
+ type: object # kept for doc/validation purposes
311
+ ```
312
+
313
+ Swaggie emits exactly:
314
+ ```typescript
315
+ export type ResourceAccess = { items?: { [key: string]: Entry } } & { [key: string]: boolean | Entry | undefined };
316
+ ```
317
+
318
+ `x-ts-type` takes precedence over all other schema fields, including `$ref`. See the [full documentation](https://yhnavein.github.io/swaggie/guide/advanced#x-ts-type-extension) for more detail.
319
+
294
320
  ### Parameter Modifiers
295
321
 
296
322
  Sometimes an API spec marks a parameter as required, but your client handles it in an interceptor and you don't want it cluttering every method signature. Parameter modifiers let you override this globally without touching the spec.
@@ -358,15 +384,6 @@ function error(e) {
358
384
 
359
385
  ---
360
386
 
361
- ## Server Setup Samples
362
-
363
- Swaggie only needs a JSON or YAML OpenAPI spec file — it does not require a running server. However, if you want to see how to configure your backend to expose an OpenAPI spec automatically, check out the sample configurations in the `samples/` folder:
364
-
365
- - [ASP.NET Core + NSwag](./samples/dotnetcore/nswag/README.md)
366
- - [ASP.NET Core + Swashbuckle](./samples/dotnetcore/swashbuckle/README.md)
367
-
368
- ---
369
-
370
387
  ## What's Supported
371
388
 
372
389
  | Supported | Not Supported |
@@ -374,7 +391,7 @@ Swaggie only needs a JSON or YAML OpenAPI spec file — it does not require a ru
374
391
  | OpenAPI 3.0, 3.1, 3.2 | Swagger / OpenAPI 2.0 |
375
392
  | `allOf`, `oneOf`, `anyOf`, `$ref`, external $refs | `not` keyword |
376
393
  | Spec formats: JSON, YAML | Very complex query parameter structures |
377
- | Extensions: `x-position`, `x-name`, `x-enumNames`, `x-enum-varnames` | Multiple response types (only the first is used) |
394
+ | Extensions: `x-position`, `x-name`, `x-enumNames`, `x-enum-varnames`, `x-ts-type` | Multiple response types (only the first is used) |
378
395
  | Content types: JSON, plain text, multipart/form-data | Multiple request body types (only the first is used) |
379
396
  | Content types: `application/x-www-form-urlencoded`, `application/octet-stream` | OpenAPI callbacks and webhooks |
380
397
  | Various enum definition styles, support for additionalProperties | |
@@ -53,6 +53,18 @@ function renderSchema(
53
53
  return '';
54
54
  }
55
55
 
56
+ // x-ts-type takes precedence over everything, including $ref.
57
+ // When present, emit the literal TypeScript type string verbatim.
58
+ if ('x-ts-type' in schema) {
59
+ const result = [];
60
+ const s = schema ;
61
+ if (_nullishCoalesce(s.description, () => ( s.title))) {
62
+ result.push(_jsDocs.renderComment.call(void 0, _nullishCoalesce(s.description, () => ( s.title))));
63
+ }
64
+ result.push(`export type ${safeName} = ${schema['x-ts-type']};`);
65
+ return result.join('\n');
66
+ }
67
+
56
68
  // This is an interesting case, because it is allowed but not likely to be used
57
69
  // as it is just a reference to another schema object
58
70
  if ('$ref' in schema) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggie",
3
- "version": "1.8.6",
3
+ "version": "1.8.7",
4
4
  "description": "Generate a fully typed TypeScript API client from your OpenAPI 3 spec",
5
5
  "author": {
6
6
  "name": "Piotr Dabrowski",