genoc 0.5.0 → 0.5.1

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.
@@ -5,7 +5,7 @@ import type { ValidationResult } from '../validate.js';
5
5
  * 3.0-specific validation rules:
6
6
  * - `openapi` must start with "3.0"
7
7
  * - `paths` is required (unlike 3.1 where paths/components/webhooks is flexible)
8
- * - `info` with `title` and `version` required
8
+ * - `info` with `title` and `version` required (shared rule)
9
9
  * - Warns about 3.1-only features: `webhooks`, `$schema` in schemas, `type` as array
10
10
  * - Accepts `nullable` and `example` (valid in 3.0, not in 3.1)
11
11
  * - Errors on `items` as array (3.1-only tuple syntax)
@@ -1,4 +1,5 @@
1
1
  import { specViolation } from '../spec-links.js';
2
+ import { validateInfo } from '../validate-info.js';
2
3
  import { validateSecurity } from '../validate-security.js';
3
4
  /**
4
5
  * Every violation in this file belongs to the 3.0 dialect;
@@ -11,7 +12,7 @@ const violation = (key, message) => specViolation('3.0', key, message);
11
12
  * 3.0-specific validation rules:
12
13
  * - `openapi` must start with "3.0"
13
14
  * - `paths` is required (unlike 3.1 where paths/components/webhooks is flexible)
14
- * - `info` with `title` and `version` required
15
+ * - `info` with `title` and `version` required (shared rule)
15
16
  * - Warns about 3.1-only features: `webhooks`, `$schema` in schemas, `type` as array
16
17
  * - Accepts `nullable` and `example` (valid in 3.0, not in 3.1)
17
18
  * - Errors on `items` as array (3.1-only tuple syntax)
@@ -31,18 +32,7 @@ export function validateSpec30(spec) {
31
32
  else if (!s.openapi.startsWith('3.0')) {
32
33
  errors.push(violation('openapi-field', `OpenAPI version must start with '3.0', got: ${s.openapi}`));
33
34
  }
34
- if (!s.info || typeof s.info !== 'object' || Array.isArray(s.info)) {
35
- errors.push(violation('info-object', "OpenAPI specification must have an 'info' field with object value"));
36
- }
37
- else {
38
- const info = s.info;
39
- if (!info.title || typeof info.title !== 'string') {
40
- errors.push(violation('info-title', "Info object must have a 'title' field with string value"));
41
- }
42
- if (!info.version || typeof info.version !== 'string') {
43
- errors.push(violation('info-version', "Info object must have a 'version' field with string value"));
44
- }
45
- }
35
+ validateInfo(s, '3.0', errors);
46
36
  if (!s.paths || typeof s.paths !== 'object' || Array.isArray(s.paths)) {
47
37
  errors.push(violation('paths-object', "OpenAPI 3.0 specification must have a 'paths' field with object value"));
48
38
  }
@@ -5,7 +5,7 @@ import type { ValidationResult } from '../validate.js';
5
5
  * 3.1-specific validation rules:
6
6
  * - `openapi` must start with "3.1"
7
7
  * - at least one of `paths`, `components`, or `webhooks` (unlike 3.0 where `paths` is required)
8
- * - `info` with `title` and `version` required
8
+ * - `info` with `title` and `version` required (shared rule)
9
9
  * - `paths` must be an object when present
10
10
  * - `components.schemas` entries must be objects, validated recursively for 3.0-only features
11
11
  * - Warns about 3.0-only features in schemas: `nullable`, boolean `exclusiveMinimum`/`exclusiveMaximum`,
@@ -1,4 +1,5 @@
1
1
  import { specViolation } from '../spec-links.js';
2
+ import { validateInfo } from '../validate-info.js';
2
3
  import { validateSecurity } from '../validate-security.js';
3
4
  /**
4
5
  * Every violation in this file belongs to the 3.1 dialect;
@@ -11,7 +12,7 @@ const violation = (key, message) => specViolation('3.1', key, message);
11
12
  * 3.1-specific validation rules:
12
13
  * - `openapi` must start with "3.1"
13
14
  * - at least one of `paths`, `components`, or `webhooks` (unlike 3.0 where `paths` is required)
14
- * - `info` with `title` and `version` required
15
+ * - `info` with `title` and `version` required (shared rule)
15
16
  * - `paths` must be an object when present
16
17
  * - `components.schemas` entries must be objects, validated recursively for 3.0-only features
17
18
  * - Warns about 3.0-only features in schemas: `nullable`, boolean `exclusiveMinimum`/`exclusiveMaximum`,
@@ -35,18 +36,7 @@ export function validateSpec31(spec) {
35
36
  else if (!s.openapi.startsWith('3.1')) {
36
37
  errors.push(violation('openapi-field', `OpenAPI version must start with '3.1', got: ${s.openapi}`));
37
38
  }
38
- if (!s.info || typeof s.info !== 'object' || Array.isArray(s.info)) {
39
- errors.push(violation('info-object', "OpenAPI specification must have an 'info' field with object value"));
40
- }
41
- else {
42
- const info = s.info;
43
- if (!info.title || typeof info.title !== 'string') {
44
- errors.push(violation('info-title', "Info object must have a 'title' field with string value"));
45
- }
46
- if (!info.version || typeof info.version !== 'string') {
47
- errors.push(violation('info-version', "Info object must have a 'version' field with string value"));
48
- }
49
- }
39
+ validateInfo(s, '3.1', errors);
50
40
  if (!s.paths && !s.components && !s.webhooks) {
51
41
  // Not a spec violation: all three fields are optional in 3.1; the check
52
42
  // exists because an empty document gives genoc nothing to generate.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shared Info Object validation for the 3.0 and 3.1 validators.
3
+ *
4
+ * Rules are identical across dialects — every published dialect (3.0, 3.1,
5
+ * 3.2 alike) requires `info` to be an object carrying `title` and `version`
6
+ * strings. Presence and type only: the spec puts no constraint on the
7
+ * values, so `title: ""` is a valid title.
8
+ */
9
+ export declare function validateInfo(spec: Record<string, unknown>, version: '3.0' | '3.1', errors: string[]): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Shared Info Object validation for the 3.0 and 3.1 validators.
3
+ *
4
+ * Rules are identical across dialects — every published dialect (3.0, 3.1,
5
+ * 3.2 alike) requires `info` to be an object carrying `title` and `version`
6
+ * strings. Presence and type only: the spec puts no constraint on the
7
+ * values, so `title: ""` is a valid title.
8
+ */
9
+ import { specViolation } from './spec-links.js';
10
+ export function validateInfo(spec, version, errors) {
11
+ if (!spec.info || typeof spec.info !== 'object' || Array.isArray(spec.info)) {
12
+ errors.push(specViolation(version, 'info-object', "OpenAPI specification must have an 'info' field with object value"));
13
+ return;
14
+ }
15
+ const info = spec.info;
16
+ if (typeof info.title !== 'string') {
17
+ errors.push(specViolation(version, 'info-title', "Info object must have a 'title' field with string value"));
18
+ }
19
+ if (typeof info.version !== 'string') {
20
+ errors.push(specViolation(version, 'info-version', "Info object must have a 'version' field with string value"));
21
+ }
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genoc",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Generate typed HTTP clients from OpenAPI 3.0 / 3.1 specifications",
5
5
  "keywords": [
6
6
  "client",