@zudojs/openapi 0.1.0 → 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.
Files changed (130) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +340 -21
  3. package/dist/index.d.ts +26 -21
  4. package/dist/index.js +31 -13
  5. package/dist/openApiComponents/index.d.ts +2 -2
  6. package/dist/openApiComponents/index.js +1 -1
  7. package/dist/openApiConstants/index.d.ts +1 -1
  8. package/dist/openApiConstants/index.js +1 -1
  9. package/dist/openApiConstants/openApiConstants.core.d.ts +15 -3
  10. package/dist/openApiConstants/openApiConstants.core.js +22 -3
  11. package/dist/openApiDocument/index.d.ts +1 -1
  12. package/dist/openApiDocument/index.js +1 -1
  13. package/dist/openApiDocument/openApiDocument.builder.d.ts +39 -52
  14. package/dist/openApiDocument/openApiDocument.builder.js +73 -72
  15. package/dist/openApiErrors/index.d.ts +2 -2
  16. package/dist/openApiErrors/index.js +2 -1
  17. package/dist/openApiErrors/openApiError.base.d.ts +9 -0
  18. package/dist/openApiErrors/openApiError.base.js +7 -0
  19. package/dist/openApiErrors/openApiError.types.d.ts +34 -14
  20. package/dist/openApiErrors/openApiError.types.js +83 -35
  21. package/dist/openApiHttp/index.d.ts +2 -2
  22. package/dist/openApiHttp/index.js +2 -2
  23. package/dist/openApiHttp/openApiHttpAdapter.core.d.ts +129 -25
  24. package/dist/openApiHttp/openApiHttpAdapter.core.js +226 -16
  25. package/dist/openApiRegistry/openApiRegistry.core.d.ts +47 -5
  26. package/dist/openApiRegistry/openApiRegistry.core.js +180 -66
  27. package/dist/openApiRegistry/openApiRegistry.type.d.ts +18 -13
  28. package/dist/openApiRegistry/openApiRegistry.type.js +1 -2
  29. package/dist/openApiRouting/index.d.ts +2 -2
  30. package/dist/openApiRouting/index.js +1 -1
  31. package/dist/openApiRouting/routeConverter.core.d.ts +25 -7
  32. package/dist/openApiRouting/routeConverter.core.js +104 -58
  33. package/dist/openApiRouting/routeMetadata.type.d.ts +40 -17
  34. package/dist/openApiRouting/routeMetadata.type.js +9 -0
  35. package/dist/openApiRouting/routeScanner.core.d.ts +17 -47
  36. package/dist/openApiRouting/routeScanner.core.js +40 -55
  37. package/dist/openApiSchema/index.d.ts +4 -4
  38. package/dist/openApiSchema/index.js +2 -2
  39. package/dist/openApiSchema/references.core.d.ts +18 -1
  40. package/dist/openApiSchema/references.core.js +21 -1
  41. package/dist/openApiSchema/schemaConverter.core.d.ts +61 -3
  42. package/dist/openApiSchema/schemaConverter.core.js +523 -117
  43. package/dist/openApiSchema/schemaRegistry.core.d.ts +27 -10
  44. package/dist/openApiSchema/schemaRegistry.core.js +33 -14
  45. package/dist/openApiSerialization/openApiSerializer.core.d.ts +10 -4
  46. package/dist/openApiSerialization/openApiSerializer.core.js +158 -9
  47. package/dist/openApiTypes/index.d.ts +1 -1
  48. package/dist/openApiTypes/openApiDocument.type.d.ts +16 -0
  49. package/dist/openApiTypes/openApiSchema.type.d.ts +24 -1
  50. package/dist/openApiTypes/openApiSchema.type.js +3 -0
  51. package/dist/openApiUi/index.d.ts +8 -0
  52. package/dist/openApiUi/index.js +8 -0
  53. package/dist/openApiUi/openApiUi.brand.d.ts +26 -0
  54. package/dist/openApiUi/openApiUi.brand.js +44 -0
  55. package/dist/openApiUi/openApiUi.core.d.ts +47 -0
  56. package/dist/openApiUi/openApiUi.core.js +157 -0
  57. package/dist/openApiValidation/index.d.ts +2 -2
  58. package/dist/openApiValidation/index.js +1 -1
  59. package/dist/openApiValidation/openApiValidator.core.d.ts +33 -11
  60. package/dist/openApiValidation/openApiValidator.core.js +295 -66
  61. package/package.json +29 -18
  62. package/dist/.tsbuildinfo +0 -1
  63. package/dist/index.d.ts.map +0 -1
  64. package/dist/index.js.map +0 -1
  65. package/dist/openApiComponents/index.d.ts.map +0 -1
  66. package/dist/openApiComponents/index.js.map +0 -1
  67. package/dist/openApiConstants/index.d.ts.map +0 -1
  68. package/dist/openApiConstants/index.js.map +0 -1
  69. package/dist/openApiConstants/openApiConstants.core.d.ts.map +0 -1
  70. package/dist/openApiConstants/openApiConstants.core.js.map +0 -1
  71. package/dist/openApiDocument/index.d.ts.map +0 -1
  72. package/dist/openApiDocument/index.js.map +0 -1
  73. package/dist/openApiDocument/openApiDocument.builder.d.ts.map +0 -1
  74. package/dist/openApiDocument/openApiDocument.builder.js.map +0 -1
  75. package/dist/openApiErrors/index.d.ts.map +0 -1
  76. package/dist/openApiErrors/index.js.map +0 -1
  77. package/dist/openApiErrors/openApiError.base.d.ts.map +0 -1
  78. package/dist/openApiErrors/openApiError.base.js.map +0 -1
  79. package/dist/openApiErrors/openApiError.core.d.ts.map +0 -1
  80. package/dist/openApiErrors/openApiError.core.js.map +0 -1
  81. package/dist/openApiErrors/openApiError.types.d.ts.map +0 -1
  82. package/dist/openApiErrors/openApiError.types.js.map +0 -1
  83. package/dist/openApiHttp/index.d.ts.map +0 -1
  84. package/dist/openApiHttp/index.js.map +0 -1
  85. package/dist/openApiHttp/openApiHttpAdapter.core.d.ts.map +0 -1
  86. package/dist/openApiHttp/openApiHttpAdapter.core.js.map +0 -1
  87. package/dist/openApiRegistry/index.d.ts.map +0 -1
  88. package/dist/openApiRegistry/index.js.map +0 -1
  89. package/dist/openApiRegistry/openApiRegistry.core.d.ts.map +0 -1
  90. package/dist/openApiRegistry/openApiRegistry.core.js.map +0 -1
  91. package/dist/openApiRegistry/openApiRegistry.type.d.ts.map +0 -1
  92. package/dist/openApiRegistry/openApiRegistry.type.js.map +0 -1
  93. package/dist/openApiRouting/index.d.ts.map +0 -1
  94. package/dist/openApiRouting/index.js.map +0 -1
  95. package/dist/openApiRouting/routeConverter.core.d.ts.map +0 -1
  96. package/dist/openApiRouting/routeConverter.core.js.map +0 -1
  97. package/dist/openApiRouting/routeMetadata.type.d.ts.map +0 -1
  98. package/dist/openApiRouting/routeMetadata.type.js.map +0 -1
  99. package/dist/openApiRouting/routeScanner.core.d.ts.map +0 -1
  100. package/dist/openApiRouting/routeScanner.core.js.map +0 -1
  101. package/dist/openApiSchema/index.d.ts.map +0 -1
  102. package/dist/openApiSchema/index.js.map +0 -1
  103. package/dist/openApiSchema/references.core.d.ts.map +0 -1
  104. package/dist/openApiSchema/references.core.js.map +0 -1
  105. package/dist/openApiSchema/schemaConverter.core.d.ts.map +0 -1
  106. package/dist/openApiSchema/schemaConverter.core.js.map +0 -1
  107. package/dist/openApiSchema/schemaRegistry.core.d.ts.map +0 -1
  108. package/dist/openApiSchema/schemaRegistry.core.js.map +0 -1
  109. package/dist/openApiSerialization/index.d.ts.map +0 -1
  110. package/dist/openApiSerialization/index.js.map +0 -1
  111. package/dist/openApiSerialization/openApiSerializer.core.d.ts.map +0 -1
  112. package/dist/openApiSerialization/openApiSerializer.core.js.map +0 -1
  113. package/dist/openApiTypes/index.d.ts.map +0 -1
  114. package/dist/openApiTypes/index.js.map +0 -1
  115. package/dist/openApiTypes/openApiComponent.type.d.ts.map +0 -1
  116. package/dist/openApiTypes/openApiComponent.type.js.map +0 -1
  117. package/dist/openApiTypes/openApiDocument.type.d.ts.map +0 -1
  118. package/dist/openApiTypes/openApiDocument.type.js.map +0 -1
  119. package/dist/openApiTypes/openApiPath.type.d.ts.map +0 -1
  120. package/dist/openApiTypes/openApiPath.type.js.map +0 -1
  121. package/dist/openApiTypes/openApiSchema.type.d.ts.map +0 -1
  122. package/dist/openApiTypes/openApiSchema.type.js.map +0 -1
  123. package/dist/openApiTypes/openApiSecurity.type.d.ts.map +0 -1
  124. package/dist/openApiTypes/openApiSecurity.type.js.map +0 -1
  125. package/dist/openApiTypes/openApiTypes.core.d.ts.map +0 -1
  126. package/dist/openApiTypes/openApiTypes.core.js.map +0 -1
  127. package/dist/openApiValidation/index.d.ts.map +0 -1
  128. package/dist/openApiValidation/index.js.map +0 -1
  129. package/dist/openApiValidation/openApiValidator.core.d.ts.map +0 -1
  130. package/dist/openApiValidation/openApiValidator.core.js.map +0 -1
@@ -1,12 +1,32 @@
1
+ import { COMPONENT_REF_PREFIX } from "../openApiConstants/openApiConstants.core.js";
2
+ /**
3
+ * Escapes a component name for use inside a JSON Pointer.
4
+ *
5
+ * RFC 6901 reserves `~` and `/`; a component called `Order/Line` produces a
6
+ * pointer that resolves to the wrong place — or nowhere — unless they are
7
+ * escaped. The `~0` substitution must come first, or the `~1` it introduces
8
+ * would be escaped again.
9
+ */
10
+ export function escapeJsonPointerSegment(segment) {
11
+ return segment.replace(/~/g, "~0").replace(/\//g, "~1");
12
+ }
13
+ /** Reverses {@link escapeJsonPointerSegment}. */
14
+ export function unescapeJsonPointerSegment(segment) {
15
+ return segment.replace(/~1/g, "/").replace(/~0/g, "~");
16
+ }
1
17
  /**
2
18
  * Creates an OpenAPI component reference.
3
19
  *
20
+ * This is the single `$ref` builder in the package — the registry and the
21
+ * schema registry both delegate here, so escaping cannot be right in one
22
+ * place and missing in another.
23
+ *
4
24
  * @param section - The component section (e.g., "schemas", "responses")
5
25
  * @param name - The component name
6
26
  */
7
27
  export function createComponentReference(section, name) {
8
28
  return {
9
- $ref: `#/components/${section}/${name}`,
29
+ $ref: `${COMPONENT_REF_PREFIX}/${escapeJsonPointerSegment(section)}/${escapeJsonPointerSegment(name)}`,
10
30
  };
11
31
  }
12
32
  //# sourceMappingURL=references.core.js.map
@@ -1,11 +1,69 @@
1
1
  import type { OpenAPISchema } from "../openApiTypes/openApiTypes.core.js";
2
+ /**
3
+ * Converts `@zudojs/schema` schemas into OpenAPI schema objects.
4
+ *
5
+ * The conversion reads the schema classes' runtime fields directly rather
6
+ * than importing them, so this package stays usable with any object that
7
+ * follows the same shape. That structural coupling is the reason every field
8
+ * name below is named in one place and covered by tests: a rename in
9
+ * `@zudojs/schema` is not a compile error here, it is a silently empty
10
+ * document.
11
+ *
12
+ * Field names as of `@zudojs/schema@0.1.0`:
13
+ * object `_config.shape`, `_config.requiredKeys` (a Set), `_config.unknownKeys`
14
+ * array `_config.itemSchema`, `_config.min`, `_config.max`, `_config.length`
15
+ * string `_config.min|max|length|pattern|format`
16
+ * number `_config.min|max|int|gt|lt|multipleOf`
17
+ * coerce.string / coerce.number
18
+ * `_constraints` — the wrapped StringSchema / NumberSchema that
19
+ * carries the `_config` above
20
+ * union `_schemas` intersection `_left` / `_right`
21
+ * enum `_values` literal `_expected`
22
+ * optional `_inner` nullable `_inner`
23
+ * default `_inner`, `_defaultValue` (a value or a factory function)
24
+ * refine `_inner`
25
+ * transform `_inner` (`schema.transform(...)`, TransformModifierSchema)
26
+ * or `_base` (the standalone TransformSchema class)
27
+ * lazy `_factory` / `_inner`
28
+ * record `_keySchema`, `_valueSchema` tuple `_schemas`
29
+ * map `_keySchema`, `_valueSchema` set `_valueSchema`
30
+ * metadata `_metadata` (description, example, title, deprecated)
31
+ *
32
+ * Object parsing accepts a missing key when the field schema is one of
33
+ * `optional`, `default`, `any` or `unknown` (`ACCEPTS_UNDEFINED` in
34
+ * schemaObject.core.ts), so exactly those are left out of `required`.
35
+ */
2
36
  export interface SchemaConversionResult {
3
37
  readonly schema: OpenAPISchema;
4
38
  readonly warnings: readonly string[];
5
39
  }
6
- export declare function convertSchema(input: unknown, _visited?: Set<object>): SchemaConversionResult;
40
+ /** Options controlling how a schema is converted. */
41
+ export interface SchemaConversionOptions {
42
+ /**
43
+ * Target specification version. 3.1 expresses nullability as
44
+ * `type: [t, "null"]`; 3.0 uses `nullable: true`, which 3.1 removed.
45
+ */
46
+ readonly version?: string;
47
+ /**
48
+ * Depth at which conversion stops descending. Guards against a recursive
49
+ * schema whose `lazy` wrapper resolves to itself. Default: 32.
50
+ */
51
+ readonly maxDepth?: number;
52
+ }
53
+ /** True when the document being produced follows OpenAPI 3.1 or later. */
54
+ export declare function isVersion31(version: string): boolean;
55
+ /**
56
+ * Converts a schema into an OpenAPI schema object.
57
+ *
58
+ * Warnings describe everything that could not be represented exactly. They
59
+ * are part of the result rather than a side channel, because silently
60
+ * emitting `{}` for an unsupported construct is how a specification ends up
61
+ * documenting nothing.
62
+ */
63
+ export declare function convertSchema(input: unknown, options?: SchemaConversionOptions): SchemaConversionResult;
7
64
  export interface SchemaConverter {
8
- convert(input: unknown, visited?: Set<object>): SchemaConversionResult;
65
+ convert(input: unknown, options?: SchemaConversionOptions): SchemaConversionResult;
9
66
  }
10
- export declare function createSchemaConverter(): SchemaConverter;
67
+ /** Creates a converter bound to a specification version. */
68
+ export declare function createSchemaConverter(defaults?: SchemaConversionOptions): SchemaConverter;
11
69
  //# sourceMappingURL=schemaConverter.core.d.ts.map