zod-openapi 0.4.0 → 0.4.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.
package/README.md
CHANGED
|
@@ -298,6 +298,20 @@ Wherever `title` is used in schemas across the document, it will instead be crea
|
|
|
298
298
|
|
|
299
299
|
This can be an extremely powerful way to generate better Open API documentation. There are some Open API features like [discriminator mapping](https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/) which require all schemas in the union to contain a ref.
|
|
300
300
|
|
|
301
|
+
To display components which are not referenced by simply add the Zod Schema to the schema components directly.
|
|
302
|
+
|
|
303
|
+
eg.
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
{
|
|
307
|
+
"components": {
|
|
308
|
+
"schemas": {
|
|
309
|
+
MyJobSchema // note: this will register this Zod Schema as MyJobSchema unless `ref` is specified on the type
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
301
315
|
#### Parameters
|
|
302
316
|
|
|
303
317
|
Query, Path, Header & Cookie parameters can be similarly registered:
|
|
@@ -370,6 +384,10 @@ eg.
|
|
|
370
384
|
z.custom().openapi({ type: 'string' });
|
|
371
385
|
```
|
|
372
386
|
|
|
387
|
+
## Ecosystem
|
|
388
|
+
|
|
389
|
+
- [eslint-plugin-zod-openapi](https://github.com/samchungy/eslint-plugin-zod-openapi) - Eslint rules for zod-openapi. This includes features which can autogenerate Typescript comments for your Zod types based on your `description`, `example` and `deprecated` fields.
|
|
390
|
+
|
|
373
391
|
## Development
|
|
374
392
|
|
|
375
393
|
### Prerequisites
|
|
@@ -397,15 +415,23 @@ yarn format
|
|
|
397
415
|
yarn lint
|
|
398
416
|
```
|
|
399
417
|
|
|
400
|
-
###
|
|
418
|
+
### Release
|
|
401
419
|
|
|
402
|
-
|
|
403
|
-
# Compile source
|
|
404
|
-
yarn build
|
|
420
|
+
To release a new version
|
|
405
421
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
422
|
+
1. Create a [new GitHub Release](https://github.com/samchungy/zod-openapi/releases/new)
|
|
423
|
+
2. Select `🏷️ Choose a tag`, enter a version number. eg. `v1.2.0` and click `+ Create new tag: vX.X.X on publish`.
|
|
424
|
+
3. Click the `Generate release notes` button and adjust the description.
|
|
425
|
+
4. Tick the `Set as the latest release` box and click `Publish release`. This will trigger the `Release` workflow.
|
|
426
|
+
5. Check the `Pull Requests` tab for a PR labelled `Release vX.X.X`.
|
|
427
|
+
6. Click `Merge Pull Request` on that Pull Request to update master with the new package version.
|
|
428
|
+
|
|
429
|
+
To release a new beta version
|
|
430
|
+
|
|
431
|
+
1. Create a [new GitHub Release](https://github.com/samchungy/zod-openapi/releases/new)
|
|
432
|
+
2. Select `🏷️ Choose a tag`, enter a version number with a `-beta.X` suffix eg. `v1.2.0-beta.1` and click `+ Create new tag: vX.X.X-beta.X on publish`.
|
|
433
|
+
3. Click the `Generate release notes` button and adjust the description.
|
|
434
|
+
4. Tick the `Set as a pre-release` box and click `Publish release`. This will trigger the `Prerelease` workflow.
|
|
409
435
|
|
|
410
436
|
## Credits
|
|
411
437
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../src/create/document.ts"],"names":[],"mappings":";;;AACA,+BAAiC;
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../src/create/document.ts"],"names":[],"mappings":";;;AACA,+BAAiC;AAKjC,6CAAsE;AACtE,mCAAsC;AA4F/B,MAAM,cAAc,GAAG,CAC5B,gBAAkC,EACb,EAAE;IACvB,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAC7C,gBAAgB,CAAC,UAAU,IAAI,EAAE,CAAC;IACpC,MAAM,UAAU,GAAG,IAAA,iCAAoB,EACrC,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,EAChC,gBAAgB,CAAC,OAAO,CACzB,CAAC;IAEF,OAAO;QACL,GAAG,gBAAgB;QACnB,KAAK,EAAE,IAAA,mBAAW,EAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC;QACtD,QAAQ,EAAE,IAAA,mBAAW,EAAC,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC5D,UAAU,EAAE,IAAA,6BAAgB,EAAC,IAAI,EAAE,UAAU,CAAC;KAC/C,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,cAAc,kBAgBzB;AAEK,MAAM,kBAAkB,GAAG,CAChC,MAAwB,EACxB,WAGC,EACO,EAAE;IACV,MAAM,QAAQ,GAAG,IAAA,sBAAc,EAAC,MAAM,CAAC,CAAC;IACxC,OAAO,IAAI,CAAC,SAAS,CACnB,QAAQ,EACR,WAAW,EAAE,QAAQ,EACrB,WAAW,EAAE,OAAO,IAAI,CAAC,CAC1B,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,kBAAkB,sBAa7B;AAEK,MAAM,kBAAkB,GAAG,CAChC,MAAwB,EACxB,cAGI,EAAE,EACE,EAAE;IACV,MAAM,QAAQ,GAAG,IAAA,sBAAc,EAAC,MAAM,CAAC,CAAC;IACxC,OAAO,IAAA,gBAAS,EAAC,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;AACxE,CAAC,CAAC;AATW,QAAA,kBAAkB,sBAS7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../src/create/document.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../src/create/document.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAKjC,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE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Object, ZodOpenApiVersion } from './document';
|
|
4
4
|
export interface Schema {
|
|
5
5
|
zodSchema?: ZodType;
|
|
6
6
|
schemaObject: oas31.SchemaObject | oas31.ReferenceObject | oas30.SchemaObject | oas30.ReferenceObject;
|
|
@@ -26,9 +26,9 @@ export interface ComponentsObject {
|
|
|
26
26
|
schemas: SchemaComponentObject;
|
|
27
27
|
parameters: ParametersComponentObject;
|
|
28
28
|
headers: HeadersComponentObject;
|
|
29
|
-
openapi:
|
|
29
|
+
openapi: ZodOpenApiVersion;
|
|
30
30
|
}
|
|
31
|
-
export declare const getDefaultComponents: (componentsObject?: Pick<ZodOpenApiComponentsObject, 'schemas' | 'parameters' | 'headers'>, openapi?:
|
|
31
|
+
export declare const getDefaultComponents: (componentsObject?: Pick<ZodOpenApiComponentsObject, 'schemas' | 'parameters' | 'headers'>, openapi?: ZodOpenApiVersion) => ComponentsObject;
|
|
32
32
|
export declare const createComponentSchemaRef: (schemaRef: string) => string;
|
|
33
33
|
export declare const createComponents: (componentsObject: Omit<ZodOpenApiComponentsObject, 'schemas' | 'parameters' | 'headers'> | undefined, components: ComponentsObject) => oas31.ComponentsObject | undefined;
|
|
34
34
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { oas30, oas31 } from 'openapi3-ts';
|
|
2
2
|
import { stringify } from 'yaml';
|
|
3
3
|
import { AnyZodObject, ZodType } from 'zod';
|
|
4
|
+
import { OpenApiVersion } from '../openapi';
|
|
4
5
|
export interface ZodOpenApiMediaTypeObject extends Omit<oas31.MediaTypeObject & oas30.MediaTypeObject, 'schema'> {
|
|
5
6
|
schema?: AnyZodObject | oas31.SchemaObject | oas31.ReferenceObject;
|
|
6
7
|
}
|
|
@@ -45,9 +46,9 @@ export interface ZodOpenApiComponentsObject extends Omit<oas31.ComponentsObject
|
|
|
45
46
|
[schema: string]: ZodType | oas31.SchemaObject | oas31.ReferenceObject | oas30.SchemaObject | oas30.ReferenceObject;
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
|
-
export type
|
|
49
|
+
export type ZodOpenApiVersion = OpenApiVersion;
|
|
49
50
|
export interface ZodOpenApiObject extends Omit<oas31.OpenAPIObject, 'openapi' | 'paths' | 'webhooks' | 'components'> {
|
|
50
|
-
openapi:
|
|
51
|
+
openapi: ZodOpenApiVersion;
|
|
51
52
|
paths?: ZodOpenApiPathsObject;
|
|
52
53
|
webhooks?: ZodOpenApiPathsObject;
|
|
53
54
|
components?: ZodOpenApiComponentsObject;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-openapi",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "A library to create full OpenAPI documents from your Zod types",
|
|
5
5
|
"homepage": "https://github.com/samchungy/zod-openapi#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"commit": "cz",
|
|
27
27
|
"format": "skuba format",
|
|
28
28
|
"lint": "skuba lint",
|
|
29
|
-
"release": "yarn build &&
|
|
29
|
+
"release": "yarn build && npm publish",
|
|
30
30
|
"test": "skuba test",
|
|
31
31
|
"test:ci": "skuba test --coverage",
|
|
32
32
|
"test:watch": "skuba test --watch"
|
|
@@ -40,18 +40,21 @@
|
|
|
40
40
|
"openapi3-ts": "4.0.4",
|
|
41
41
|
"yaml": "2.2.1"
|
|
42
42
|
},
|
|
43
|
-
"peerDependencies": {
|
|
44
|
-
"zod": "^3.21.4"
|
|
45
|
-
},
|
|
46
43
|
"devDependencies": {
|
|
47
44
|
"@types/node": "^16.18.3",
|
|
48
45
|
"commitizen": "^4.2.4",
|
|
49
46
|
"skuba": "6.0.0",
|
|
50
47
|
"zod": "3.21.4"
|
|
51
48
|
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"zod": "^3.21.4"
|
|
51
|
+
},
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=16.11"
|
|
54
54
|
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"registry": "https://registry.npmjs.org/"
|
|
57
|
+
},
|
|
55
58
|
"skuba": {
|
|
56
59
|
"entryPoint": "src/index.ts",
|
|
57
60
|
"template": "oss-npm-package",
|