@scalar/oas-utils 0.2.45 → 0.2.46

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @scalar/oas-utils
2
2
 
3
+ ## 0.2.46
4
+
5
+ ### Patch Changes
6
+
7
+ - 2b75354: fix: null example bug
8
+ - 437d54d: fix: runtime null error prettyprint
9
+
3
10
  ## 0.2.45
4
11
 
5
12
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"request-examples.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/request-examples.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEtC,eAAO,MAAM,8BAA8B;;;;;;IAMzC,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUlF,CAAA;AAEF,kFAAkF;AAClF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,8BAA8B,CACtC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,uEAQ7B,CAAA;AACV,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;YAjCnC,kFAAkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoDlF,CAAA;AACF,MAAM,MAAM,kBAA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5 @@
1
1
  import { z } from 'zod';
2
+ import { schemaModel } from '../../helpers/schema-model.js';
2
3
  import { getRequestBodyFromOperation } from '../../spec-getters/getRequestBodyFromOperation.js';
3
4
  import { getServerVariableExamples } from '../../spec-getters/getServerVariableExamples.js';
4
5
  import { nanoidSchema } from '../shared/utility.js';
@@ -83,7 +84,8 @@ function createParamInstance(param) {
83
84
  * - Need to handle unions/array values for schema
84
85
  */
85
86
  const value = String(schema?.default ?? schema?.examples?.[0] ?? '');
86
- return requestExampleParametersSchema.parse({
87
+ // safe parse the example
88
+ const example = schemaModel({
87
89
  ...schema,
88
90
  key: param.name,
89
91
  value,
@@ -91,7 +93,13 @@ function createParamInstance(param) {
91
93
  required: param.required,
92
94
  /** Initialized all required properties to enabled */
93
95
  enabled: !!param.required,
94
- });
96
+ }, requestExampleParametersSchema, false);
97
+ if (!example) {
98
+ console.warn(`Example at ${param.name} is invalid.`);
99
+ return requestExampleParametersSchema.parse({});
100
+ }
101
+ else
102
+ return example;
95
103
  }
96
104
  /**
97
105
  * Create new request example from a request
@@ -155,14 +163,20 @@ function createExampleFromRequest(request, name, server) {
155
163
  }
156
164
  }
157
165
  const serverVariables = server ? getServerVariableExamples(server) : {};
158
- const example = requestExampleSchema.parse({
166
+ // safe parse the example
167
+ const example = schemaModel({
159
168
  requestUid: request.uid,
160
169
  parameters,
161
170
  name,
162
171
  body,
163
172
  serverVariables,
164
- });
165
- return example;
173
+ }, requestExampleSchema, false);
174
+ if (!example) {
175
+ console.warn(`Example at ${request.uid} is invalid.`);
176
+ return requestExampleSchema.parse({});
177
+ }
178
+ else
179
+ return example;
166
180
  }
167
181
 
168
182
  export { createExampleFromRequest, createParamInstance, exampleRequestBodyEncoding, exampleRequestBodySchema, requestExampleParametersSchema, requestExampleSchema };
@@ -21,7 +21,7 @@ const prettyPrintJson = (value) => {
21
21
  return replaceCircularDependencies(value);
22
22
  }
23
23
  }
24
- return value.toString();
24
+ return value?.toString() ?? '';
25
25
  };
26
26
  /**
27
27
  * JSON.stringify, but with circular dependencies replaced with '[Circular]'
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "specification",
17
17
  "yaml"
18
18
  ],
19
- "version": "0.2.45",
19
+ "version": "0.2.46",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
@@ -94,8 +94,8 @@
94
94
  "zod": "^3.23.8",
95
95
  "@scalar/object-utils": "1.1.8",
96
96
  "@scalar/openapi-types": "0.1.1",
97
- "@scalar/themes": "0.9.30",
98
- "@scalar/types": "0.0.9"
97
+ "@scalar/types": "0.0.9",
98
+ "@scalar/themes": "0.9.30"
99
99
  },
100
100
  "devDependencies": {
101
101
  "rollup": "^4.16.4",
@@ -103,9 +103,9 @@
103
103
  "vite": "^5.2.10",
104
104
  "vitest": "^1.6.0",
105
105
  "zod-to-ts": "^1.2.0",
106
+ "@scalar/openapi-parser": "0.8.3",
106
107
  "@scalar/build-tooling": "0.1.10",
107
- "@scalar/openapi-types": "0.1.1",
108
- "@scalar/openapi-parser": "0.8.3"
108
+ "@scalar/openapi-types": "0.1.1"
109
109
  },
110
110
  "scripts": {
111
111
  "build": "scalar-build-rollup",