swaggie 1.1.3-test.1 → 1.2.0

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
@@ -8,9 +8,7 @@
8
8
  ![NodeCI](https://github.com/yhnavein/swaggie/workflows/NodeCI/badge.svg)
9
9
  ![Test Coverage](https://img.shields.io/badge/test_coverage-98%25-brightgreen)
10
10
  ![npm downloads](https://img.shields.io/npm/dw/swaggie.svg)
11
- ![npm bundle size](https://img.shields.io/bundlephobia/minzip/swaggie.svg)
12
11
  ![npm install size](https://packagephobia.now.sh/badge?p=swaggie)
13
- ![Hackage Dependencies](https://img.shields.io/hackage-deps/v/swaggie)
14
12
 
15
13
  Generate Typescript code from an OpenAPI 3.0 document, so that accessing REST API resources from the client code is less error-prone, static-typed and just easier to use long-term.
16
14
 
@@ -86,7 +84,7 @@ swaggie -s https://petstore3.swagger.io/api/v3/openapi.json -o ./client/petstore
86
84
  swaggie -s $URL -o ./client/petstore.ts && prettier ./client/petstore.ts --write`
87
85
  ```
88
86
 
89
- And this can be easily automated (in the npm scripts for example)
87
+ And this can be easily automated (in the `npm` scripts for example)
90
88
 
91
89
  ### Configuration File
92
90
 
@@ -238,6 +236,29 @@ If Petstore owners decide to remove method we use, then after running `swaggie`
238
236
 
239
237
  Without this approach, the error would be spotted by our end-user and he/she would not appreciate it at all!
240
238
 
239
+ ## Other features
240
+
241
+ ### Parameter adjustment
242
+
243
+ In some cases you might want to adjust the parameters globally but without touching the OpenAPI spec. For example, the spec may explicitly define some of parameters as `required`, but you will handle them in the interceptor. In such case, you don't want to define them is every single method. This is where this feature comes in handy.
244
+
245
+ Example (in the config file):
246
+
247
+ ```json
248
+ {
249
+ "modifiers": {
250
+ "parameters": {
251
+ "clientId": "ignore",
252
+ "orgId": "optional",
253
+ "country": "required"
254
+ }
255
+ }
256
+ }
257
+ ```
258
+
259
+ This will ensure that `clientId` parameters will never appear in any of the generated methods, and `orgId` will be optional (regardless of what the spec says).
260
+ You can also use `required` value to enforce the parameter to be required, _(but in this case, realistically it would be better to just fix the spec)_.
261
+
241
262
  ## Server config
242
263
 
243
264
  You might wonder how to set up server to fully utilize Swaggie's features. For that I've added a `samples/` folder with sample configurations.
@@ -270,18 +291,18 @@ function error(e) {
270
291
 
271
292
  ## Notes
272
293
 
273
- | Supported | Not supported |
274
- | ------------------------------------------------------------------------------ | ------------------------------------------ |
275
- | OpenAPI 3 | Swagger, Open API 2.0 |
276
- | `allOf`, `oneOf`, `anyOf`, `$ref` to schemas | `not` |
277
- | Spec formats: `JSON`, `YAML` | Very complex query params |
278
- | Extensions: `x-position`, `x-name`, `x-enumNames`, `x-enum-varnames` | Multiple response types (one will be used) |
279
- | Content types: `JSON`, `text`, `multipart/form-data` | Multiple request types (one will be used) |
280
- | Content types: `application/x-www-form-urlencoded`, `application/octet-stream` | References to other spec files |
281
- | Different types of enum definitions (+ OpenAPI 3.1 support for enums) | |
282
- | Paths inheritance, comments (descriptions) | |
283
- | Getting documents from remote locations or as path reference (local file) | |
284
- | Grouping endpoints by tags + handle gracefully duplicate operation ids | |
294
+ | Supported | Not supported |
295
+ | ------------------------------------------------------------------------------ | ----------------------------------------------- |
296
+ | OpenAPI 3 | Swagger, Open API 2.0 |
297
+ | `allOf`, `oneOf`, `anyOf`, `$ref` to schemas | `not` |
298
+ | Spec formats: `JSON`, `YAML` | Very complex query params |
299
+ | Extensions: `x-position`, `x-name`, `x-enumNames`, `x-enum-varnames` | Multiple response types (only one will be used) |
300
+ | Content types: `JSON`, `text`, `multipart/form-data` | Multiple request types (only one will be used) |
301
+ | Content types: `application/x-www-form-urlencoded`, `application/octet-stream` | References to other spec files |
302
+ | Different types of enum definitions (+ OpenAPI 3.1 support for enums) | OpenAPI callbacks |
303
+ | Paths inheritance, comments (descriptions) | OpenAPI webhooks |
304
+ | Getting documents from remote locations or as path reference (local file) | |
305
+ | Grouping endpoints by tags + handle gracefully duplicate operation ids | |
285
306
 
286
307
  ## Used by
287
308
 
@@ -123,6 +123,15 @@ function prepareClient(
123
123
  });
124
124
  } exports.prepareOperations = prepareOperations;
125
125
 
126
+ /**
127
+ * Marks parameters as skippable based on their position relative to the last required parameter.
128
+ *
129
+ * This function iterates through the list of parameters and finds the last required parameter
130
+ * (where `optional` is false). All parameters that come after this required parameter are marked
131
+ * as skippable. This is useful, as we can skip such parameters when calling the generated function.
132
+ *
133
+ * @param params - Array of operation parameters to analyze and mark as skippable. (in-place modification)
134
+ */
126
135
  function markParametersAsSkippable(params) {
127
136
  const lastRequiredParamIndex = params.map((p) => !p.optional).lastIndexOf(true);
128
137
  if (lastRequiredParamIndex === params.length - 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggie",
3
- "version": "1.1.3-test.1",
3
+ "version": "1.2.0",
4
4
  "description": "Generate TypeScript REST client code from an OpenAPI spec",
5
5
  "author": {
6
6
  "name": "Piotr Dabrowski",
@@ -24,11 +24,11 @@
24
24
  "swaggie": "dist/cli.js"
25
25
  },
26
26
  "scripts": {
27
- "build": "sucrase ./src -d ./dist --transforms typescript,imports && npm run rm-tests && npm run types",
27
+ "build": "sucrase ./src -d ./dist --transforms typescript,imports && yarn rm-tests && yarn types",
28
28
  "rm-tests": "find dist/ \\( -name '*.spec.js' -o -name 'types.js' \\) -type f -delete",
29
29
  "types": "tsc src/types.ts --outDir dist/ --declaration --emitDeclarationOnly && cp test/index.d.ts ./dist/",
30
- "test": "mocha",
31
- "coverage": "npx nyc -r text -r json-summary mocha"
30
+ "test": "tsx --test 'src/**/*.spec.ts' 'test/**/*.spec.ts'",
31
+ "coverage": "npx c8 yarn test"
32
32
  },
33
33
  "files": [
34
34
  "dist",
@@ -47,7 +47,8 @@
47
47
  "swr",
48
48
  "service",
49
49
  "typescript",
50
- "codegen"
50
+ "codegen",
51
+ "TanStack Query"
51
52
  ],
52
53
  "dependencies": {
53
54
  "case": "^1.6.3",
@@ -58,14 +59,11 @@
58
59
  "undici": "^6.21.1"
59
60
  },
60
61
  "devDependencies": {
61
- "@types/chai": "5.2.2",
62
62
  "@types/js-yaml": "4.0.9",
63
- "@types/mocha": "10.0.10",
64
63
  "@types/node": "24.2.0",
65
- "chai": "5.2.1",
66
- "mocha": "11.7.1",
67
64
  "openapi-types": "^12.1.3",
68
65
  "sucrase": "3.35.0",
66
+ "tsx": "^4.20.3",
69
67
  "typescript": "5.9.2"
70
68
  }
71
69
  }