typespec-http-zod 0.29.0 → 0.31.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.
@@ -0,0 +1,139 @@
1
+ import { type Model, type ModelProperty, type Namespace, type Program, type Type } from "@typespec/compiler";
2
+ import { Visibility, type HttpOperation } from "@typespec/http";
3
+ export declare function withServiceView<T>(program: Program, service: Namespace, run: () => T): T;
4
+ /** The same scope, held across an `await` - returns what puts the previous one back. */
5
+ export declare function beginServiceView(program: Program, service: Namespace): () => void;
6
+ /**
7
+ * **The types of the service no operation reaches, which openapi3 publishes as components all the
8
+ * same** - its `processUnreferencedSchemas`, with `omitUnreachableTypes` unset: every model, enum and
9
+ * union declared in the service namespace and below it (only the service's own, where the service is
10
+ * the global namespace), but not one an operation reaches, a model whose properties were spread as
11
+ * parameters (published as parameters), a type openapi3 inlines, an HTTP file, or an authentication
12
+ * scheme's model. Rendered at `All` by the caller, as openapi3 renders them. A scalar is validated
13
+ * inline wherever it is used, reached or not, so an unreached one has nothing to declare.
14
+ */
15
+ export declare function unreachedTypes(): readonly Type[];
16
+ /** Every type the service publishes, reached by an operation or not - read as {@link usageOf} reads it. */
17
+ export declare function publishedTypes(): Iterable<Type>;
18
+ /** Whether openapi3 suffixes this type's component with the visibility it is rendered at. */
19
+ export declare function isSuffixedByUsage(type: Type): boolean;
20
+ /**
21
+ * An operation's body, part or parameter a walk starts from: `where`, as the diagnostic says it, and
22
+ * `root`, the name of its type where it has one - wrapped in a visibility template, as
23
+ * `Create<Outer>`, the request is published from a model of its own and leaves the shared ones alone.
24
+ */
25
+ interface Via {
26
+ readonly where: string;
27
+ readonly root: string | undefined;
28
+ /** Whether the root is a model, which a visibility template such as `Create<...>` takes. */
29
+ readonly model: boolean;
30
+ /** The root itself, where it is a named model or union - see {@link viewRemedyOf}. */
31
+ readonly type?: Type;
32
+ }
33
+ /**
34
+ * **The visibility openapi3 reads a model's own properties at, where it publishes the model at
35
+ * `at`: the visibility the reference it writes the schema from arrived at** - see
36
+ * {@link publicationOf}. Where nothing reshapes the model there, the two are one schema - anything
37
+ * else is `split-visibility` - but a type a property refers to is reached at the first, and a list
38
+ * or a union instance is not reduced: `Mid { tags: Tags }` first sent in a create body and also
39
+ * returned is published as `Mid`, its `tags` referring to `TagsCreate`. A component is read as
40
+ * `components.schemas` keeps it, the later of two metadata contexts; a model written out where it
41
+ * is used, as the context `ignore` writes it. Where no reference wrote it, at `at`.
42
+ */
43
+ export declare function readVisibilityOf(program: Program, model: Model, at: Visibility, ignore: boolean): Visibility;
44
+ /**
45
+ * **The visibility of the component the document keeps for a type rendered at `at`.** Where the type
46
+ * is published at several visibilities under one name - unsuffixed, as openapi3 names a type it
47
+ * counts at one - `components.schemas` keeps the one written last, and every `$ref` to the name is
48
+ * to it. `K extends P`, written at `All` by the pass over types no operation reaches and at `Read` by
49
+ * `P`'s discriminator mapping, is `K` at `Read` in the document; `G extends K`, written out from
50
+ * `K` at `All`, required a create-only `s` the `K` it refers to leaves out. Elsewhere, `at`.
51
+ */
52
+ export declare function keptVisibilityOf(type: Type, at: Visibility): Visibility;
53
+ /**
54
+ * **Every component openapi3 writes, at the visibility it publishes it at, in the metadata context
55
+ * `components.schemas` keeps** - declared after the routes, so a component no route renders by name
56
+ * is declared all the same. A model a merge holds is written into the merge here, and openapi3
57
+ * publishes it as a component of its own: `L1 extends L0 { m: B }` and `L2 extends L1 { m: Sub }`
58
+ * publish `B` and `Sub`, which had no validator.
59
+ */
60
+ export declare function publishedComponents(program: Program): readonly {
61
+ readonly type: Type;
62
+ readonly at: Visibility;
63
+ readonly ignore: boolean;
64
+ readonly binary: boolean;
65
+ }[];
66
+ /**
67
+ * **The visibility openapi3 publishes a parameter at, where it is not the operation's.** A parameter
68
+ * spread from a named model is published once, as a shared parameter component, from the first
69
+ * operation that sends it, and every later one refers to it: `...CommonA` sent by a GET and then by a
70
+ * POST is read at `Query` for both. Read at each operation's own, the POST was held to a create view
71
+ * the document does not publish for it.
72
+ */
73
+ /**
74
+ * Whether openapi3 publishes a shared route's parameter optional though it is declared required -
75
+ * see `resolveSharedRouteParameters` - asked of the declaration, before or after openapi3 sets its
76
+ * `optional`, with one answer.
77
+ */
78
+ export declare function isSharedRouteOptional(property: ModelProperty): boolean;
79
+ export declare function parameterVisibilityOf(property: ModelProperty): Visibility | undefined;
80
+ /**
81
+ * **The visibility openapi3 publishes an operation's request at.** Its own, unless it shares its
82
+ * verb and path with another: openapi3 publishes one operation for the route, every body and
83
+ * parameter at the first one's visibility, and reports `inconsistent-shared-route-request-visibility`
84
+ * where they differ - graded against what it publishes, as the maintainer decided.
85
+ */
86
+ export declare function requestVisibilityOf(program: Program, operation: HttpOperation): Visibility;
87
+ /**
88
+ * **How openapi3's schema for a model differs from the schema of that model at the visibility it is
89
+ * rendered at.** openapi3 reads a model's properties at the visibility its first reference arrived
90
+ * at - `document` here - and its `required` at the one it reduces that to; the schema it means, and
91
+ * the one rendered here, reads both at the reduced one - `rendered`. Where no reduction intervenes
92
+ * they are one schema. Only the model's own properties are compared: a type a property refers to has
93
+ * a first reference of its own, and is judged by it where it is rendered - a component wherever it
94
+ * is declared, and a model expression where it is written out, as openapi3 writes it out from its
95
+ * cache. A base is part of the model's schema, through `allOf`.
96
+ */
97
+ export interface Misreading {
98
+ /** The model whose properties openapi3 reads at {@link at}: the one judged, or a base of it. */
99
+ readonly model: Model;
100
+ /** The property its schema gets wrong. */
101
+ readonly property: ModelProperty;
102
+ /** The visibility openapi3 reads the properties at. */
103
+ readonly at: Visibility;
104
+ /** What openapi3 publishes for the property. */
105
+ readonly effect: "undeclared" | "dropped" | "added" | "reshaped";
106
+ /** Where the schema it is found in was first reached from. */
107
+ readonly via: Via;
108
+ }
109
+ /**
110
+ * **Whether the schema rendered for `type` here is one openapi3 publishes differently - and if so,
111
+ * `split-visibility`, an error, reported once per declaration.** Refused, as the maintainer decided,
112
+ * rather than validated against a schema the document does not hold: the document's `required` names
113
+ * a property its properties leave out, which no value satisfies under `seal-object-schemas`, or it
114
+ * leaves out an optional one, which a sealed schema then refuses.
115
+ *
116
+ * `declared` is the component's name, for a type published as a component; `type` is then its
117
+ * canonical type and `at` the visibility it is declared at. Otherwise `type` is written out where it
118
+ * is used - a model expression, an inlined template instance - and judged by the emission openapi3
119
+ * writes out in the metadata context `ignore`.
120
+ */
121
+ export declare function isSplitByVisibility(program: Program, type: Type, at: Visibility, ignore: boolean, declared: string | undefined): boolean;
122
+ /**
123
+ * Whether openapi3 publishes the component of `type` at `at` split - the refusal
124
+ * {@link isSplitByVisibility} reports, asked without reporting it. A dispatch leaves such a subtype
125
+ * out, as it leaves out one no value is: its validator is `z.never()`, which no
126
+ * `z.discriminatedUnion` can hold.
127
+ */
128
+ export declare function isPublishedSplit(program: Program, type: Type, at: Visibility): boolean;
129
+ /** The standard template that is a model's view at a request visibility, where there is one. */
130
+ /**
131
+ * **The view a remedy names, declared so that it works where it is pasted**: a model of its own,
132
+ * `model OuterCreate is Create<Ns.Outer>;`, with the type spelled from the global namespace. Named
133
+ * `Create<Outer>`, the view inherited `Outer`'s `@friendlyName` and collided with it; spelled by the
134
+ * friendly name, or without its namespace from a sub-namespace, it named nothing; and sent through
135
+ * a spread, `...Create<O1>`, it left the body the document publishes as it was.
136
+ */
137
+ export declare function viewRemedyOf(template: string, type: Type): string;
138
+ export declare function viewTemplateOf(at: Visibility): string | undefined;
139
+ export {};