@jsonapi-serde/openapi 0.0.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.
- package/LICENSE +22 -0
- package/README.md +22 -0
- package/dist/body.d.ts +11 -0
- package/dist/body.js +96 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/query.d.ts +7 -0
- package/dist/query.js +93 -0
- package/dist/response.d.ts +48 -0
- package/dist/response.js +177 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2025-present, Ben Scholzen 'DASPRiD'
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
14
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
15
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
16
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
17
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
18
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
19
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
20
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
21
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
22
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# JSON:API Serde - Server
|
|
2
|
+
|
|
3
|
+
[](https://github.com/DASPRiD/jsonapi-serde-js/actions/workflows/test.yml)
|
|
4
|
+
[](https://codecov.io/gh/DASPRiD/jsonapi-serde-js)
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
JSON:API Serde is a framework-agnostic [JSON:API](https://jsonapi.org) serialization and deserialization library.
|
|
9
|
+
|
|
10
|
+
## Documentation
|
|
11
|
+
|
|
12
|
+
To check out docs, visit [jsonapi-serde.js.org](https://jsonapi-serde.js.org).
|
|
13
|
+
|
|
14
|
+
## Changelog
|
|
15
|
+
|
|
16
|
+
Detailed changes for each release are documented in the [CHANGELOG](https://github.com/dasprid/jsonapi-serde-js/blob/main/packages/server/CHANGELOG.md)
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
[BSD-3-Clause](https://github.com/dasprid/jsonapi-serde-js/blob/main/LICENSE)
|
|
21
|
+
|
|
22
|
+
Copyright (c) 2025-present, Ben Scholzen 'DASPRiD'
|
package/dist/body.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AttributesSchema, IncludedTypeSchemas, ParseResourceRequestOptions, RelationshipsSchema } from "@jsonapi-serde/server/request";
|
|
2
|
+
import type { ContentObject } from "openapi3-ts/oas31";
|
|
3
|
+
import type { $ZodType } from "zod/v4/core";
|
|
4
|
+
/**
|
|
5
|
+
* Generates an OpenAPI 3.1 content object for resource requests based on parser options
|
|
6
|
+
*/
|
|
7
|
+
export declare const buildResourceRequestContentObject: (options: ParseResourceRequestOptions<$ZodType<string> | undefined, string, AttributesSchema | undefined, RelationshipsSchema | undefined, IncludedTypeSchemas | undefined>) => ContentObject;
|
|
8
|
+
/**
|
|
9
|
+
* Generates an OpenAPI 3.1 content object for relationships requests based on parser options
|
|
10
|
+
*/
|
|
11
|
+
export declare const buildRelationshipsRequestContentObject: (type: string, idSchema?: $ZodType<string | null> | undefined) => ContentObject;
|
package/dist/body.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { toJSONSchema } from "zod/v4/core";
|
|
2
|
+
/**
|
|
3
|
+
* Generates an OpenAPI 3.1 content object for resource requests based on parser options
|
|
4
|
+
*/
|
|
5
|
+
export const buildResourceRequestContentObject = (options) => {
|
|
6
|
+
const resourceProperties = {
|
|
7
|
+
type: { type: "string", enum: [options.type] },
|
|
8
|
+
};
|
|
9
|
+
const resourceRequired = ["type"];
|
|
10
|
+
if (options.idSchema) {
|
|
11
|
+
resourceProperties.id = toJSONSchema(options.idSchema);
|
|
12
|
+
resourceRequired.push("id");
|
|
13
|
+
}
|
|
14
|
+
if (options.attributesSchema) {
|
|
15
|
+
resourceProperties.attributes = toJSONSchema(options.attributesSchema);
|
|
16
|
+
resourceRequired.push("attributes");
|
|
17
|
+
}
|
|
18
|
+
if (options.relationshipsSchema) {
|
|
19
|
+
resourceProperties.relationships = toJSONSchema(options.relationshipsSchema);
|
|
20
|
+
resourceRequired.push("relationships");
|
|
21
|
+
}
|
|
22
|
+
const resourceSchema = {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: resourceProperties,
|
|
25
|
+
required: resourceRequired,
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
};
|
|
28
|
+
const rootProperties = {
|
|
29
|
+
data: resourceSchema,
|
|
30
|
+
};
|
|
31
|
+
if (options.includedTypeSchemas) {
|
|
32
|
+
rootProperties.included = {
|
|
33
|
+
type: "array",
|
|
34
|
+
items: {
|
|
35
|
+
oneOf: Object.entries(options.includedTypeSchemas).map(([type, options]) => {
|
|
36
|
+
const properties = {
|
|
37
|
+
lid: { type: "string" },
|
|
38
|
+
type: { type: "string", enum: [type] },
|
|
39
|
+
};
|
|
40
|
+
const required = ["lid", "type"];
|
|
41
|
+
if (options.attributesSchema) {
|
|
42
|
+
properties.attributes = toJSONSchema(options.attributesSchema);
|
|
43
|
+
required.push("attributes");
|
|
44
|
+
}
|
|
45
|
+
if (options.relationshipsSchema) {
|
|
46
|
+
properties.relationships = toJSONSchema(options.relationshipsSchema);
|
|
47
|
+
required.push("relationships");
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
type: "object",
|
|
51
|
+
properties: properties,
|
|
52
|
+
required: required,
|
|
53
|
+
};
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const schema = {
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: rootProperties,
|
|
61
|
+
required: ["data"],
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
"application/vnd.api+json": { schema },
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Generates an OpenAPI 3.1 content object for relationships requests based on parser options
|
|
70
|
+
*/
|
|
71
|
+
export const buildRelationshipsRequestContentObject = (type, idSchema) => {
|
|
72
|
+
const schema = {
|
|
73
|
+
type: "object",
|
|
74
|
+
properties: {
|
|
75
|
+
data: {
|
|
76
|
+
type: "array",
|
|
77
|
+
items: {
|
|
78
|
+
type: "object",
|
|
79
|
+
properties: {
|
|
80
|
+
type: { type: "string", enum: [type] },
|
|
81
|
+
id: idSchema
|
|
82
|
+
? toJSONSchema(idSchema)
|
|
83
|
+
: { type: "string", example: "abc" },
|
|
84
|
+
},
|
|
85
|
+
required: ["id", "type"],
|
|
86
|
+
additionalProperties: false,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
required: ["data"],
|
|
91
|
+
additionalProperties: false,
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
"application/vnd.api+json": { schema },
|
|
95
|
+
};
|
|
96
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ParseQueryOptions, SparseFieldSets } from "@jsonapi-serde/server/request";
|
|
2
|
+
import type { ParameterObject } from "openapi3-ts/oas31";
|
|
3
|
+
import type { $ZodType } from "zod/v4/core";
|
|
4
|
+
/**
|
|
5
|
+
* Generates OpenAPI 3.1 parameters based on query options
|
|
6
|
+
*/
|
|
7
|
+
export declare const buildQueryParameters: (options: ParseQueryOptions<string | undefined, string | undefined, SparseFieldSets | undefined, $ZodType | undefined, $ZodType | undefined>) => ParameterObject[];
|
package/dist/query.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { toJSONSchema } from "zod/v4/core";
|
|
2
|
+
/**
|
|
3
|
+
* Generates OpenAPI 3.1 parameters based on query options
|
|
4
|
+
*/
|
|
5
|
+
export const buildQueryParameters = (options) => {
|
|
6
|
+
const parameters = [];
|
|
7
|
+
if (options.include) {
|
|
8
|
+
parameters.push({
|
|
9
|
+
name: "include",
|
|
10
|
+
in: "query",
|
|
11
|
+
schema: {
|
|
12
|
+
type: "array",
|
|
13
|
+
items: {
|
|
14
|
+
type: "string",
|
|
15
|
+
enum: [...new Set(options.include.allowed.flatMap(expandDotNotation))],
|
|
16
|
+
},
|
|
17
|
+
default: options.include.default,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (options.sort) {
|
|
22
|
+
parameters.push({
|
|
23
|
+
name: "include",
|
|
24
|
+
in: "query",
|
|
25
|
+
schema: {
|
|
26
|
+
type: "array",
|
|
27
|
+
items: {
|
|
28
|
+
type: "string",
|
|
29
|
+
enum: [
|
|
30
|
+
...options.sort.allowed,
|
|
31
|
+
...options.sort.allowed.map((field) => `-${field}`),
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
maxItems: options.sort.multiple ? undefined : 1,
|
|
35
|
+
default: options.sort.default?.map((field) => `${field.order === "desc" ? "-" : ""}${field.field}`),
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (options.fields) {
|
|
40
|
+
parameters.push({
|
|
41
|
+
name: "fields",
|
|
42
|
+
in: "query",
|
|
43
|
+
style: "deepObject",
|
|
44
|
+
schema: {
|
|
45
|
+
type: "object",
|
|
46
|
+
properties: Object.fromEntries(Object.entries(options.fields.allowed).map(([type, fields]) => [
|
|
47
|
+
type,
|
|
48
|
+
{
|
|
49
|
+
type: "string",
|
|
50
|
+
description: `Comma-separated list of fields to include for this type. Leave empty to omit all fields. Allowed fields are: ${fields.map((field) => `\`${field}\``).join(", ")}`,
|
|
51
|
+
},
|
|
52
|
+
])),
|
|
53
|
+
default: options.fields.default,
|
|
54
|
+
additionalProperties: false,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (options.filter) {
|
|
59
|
+
let required = true;
|
|
60
|
+
if (options.filter._zod.optin === "optional") {
|
|
61
|
+
required = undefined;
|
|
62
|
+
}
|
|
63
|
+
parameters.push({
|
|
64
|
+
name: "filter",
|
|
65
|
+
in: "query",
|
|
66
|
+
style: "deepObject",
|
|
67
|
+
schema: toJSONSchema(options.filter),
|
|
68
|
+
required,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (options.page) {
|
|
72
|
+
let required = true;
|
|
73
|
+
if (options.page._zod.optin === "optional") {
|
|
74
|
+
required = undefined;
|
|
75
|
+
}
|
|
76
|
+
parameters.push({
|
|
77
|
+
name: "page",
|
|
78
|
+
in: "query",
|
|
79
|
+
style: "deepObject",
|
|
80
|
+
schema: toJSONSchema(options.page),
|
|
81
|
+
required,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return parameters;
|
|
85
|
+
};
|
|
86
|
+
const expandDotNotation = (input) => {
|
|
87
|
+
const parts = input.split(".");
|
|
88
|
+
const result = [];
|
|
89
|
+
for (let i = 1; i <= parts.length; ++i) {
|
|
90
|
+
result.push(parts.slice(0, i).join("."));
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ResponseObject, SchemaObject } from "openapi3-ts/oas31";
|
|
2
|
+
export type Cardinality = "one" | "one_nullable" | "many";
|
|
3
|
+
export type RelationshipDefinition = {
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
cardinality: Cardinality;
|
|
7
|
+
};
|
|
8
|
+
export type MetaSchemaObject = SchemaObject & {
|
|
9
|
+
type: "object";
|
|
10
|
+
};
|
|
11
|
+
export type LinkSchemaObjects = Record<string, SchemaObject>;
|
|
12
|
+
export type BuildResourceSchemaObjectOptions = {
|
|
13
|
+
type: string;
|
|
14
|
+
id?: SchemaObject;
|
|
15
|
+
attributes?: SchemaObject;
|
|
16
|
+
relationships?: RelationshipDefinition[];
|
|
17
|
+
meta?: MetaSchemaObject;
|
|
18
|
+
links?: LinkSchemaObjects;
|
|
19
|
+
title?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const linkStringSchemaObject: SchemaObject;
|
|
23
|
+
export declare const linkObjectSchemaObject: SchemaObject;
|
|
24
|
+
export declare const linkSchemaObject: SchemaObject;
|
|
25
|
+
/**
|
|
26
|
+
* Builds an OpenAPI 3.1 SchemaObject for a resource, including id, type, attributes, relationships, meta, and links
|
|
27
|
+
*/
|
|
28
|
+
export declare const buildResourceSchemaObject: (options: BuildResourceSchemaObjectOptions) => SchemaObject;
|
|
29
|
+
type BuildDataResponseObjectOptions = {
|
|
30
|
+
resourceSchema: SchemaObject;
|
|
31
|
+
cardinality: Cardinality;
|
|
32
|
+
meta?: MetaSchemaObject;
|
|
33
|
+
description?: string;
|
|
34
|
+
links?: LinkSchemaObjects;
|
|
35
|
+
included?: SchemaObject[];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Builds an OpenAPI 3.1 ResponseObject for data responses including data, meta, links, and included
|
|
39
|
+
*/
|
|
40
|
+
export declare const buildDataResponseObject: (options: BuildDataResponseObjectOptions) => ResponseObject;
|
|
41
|
+
export type BuildErrorResponseObjectOptions = {
|
|
42
|
+
description: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Builds an OpenAPI 3.1 ResponseObject for error responses containing an errors array
|
|
46
|
+
*/
|
|
47
|
+
export declare const buildErrorResponseObject: (options: BuildErrorResponseObjectOptions) => ResponseObject;
|
|
48
|
+
export {};
|
package/dist/response.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
export const linkStringSchemaObject = { type: "string", format: "uri-reference" };
|
|
2
|
+
export const linkObjectSchemaObject = {
|
|
3
|
+
type: "object",
|
|
4
|
+
properties: {
|
|
5
|
+
href: { type: "string", format: "uri-reference" },
|
|
6
|
+
rel: { type: "string" },
|
|
7
|
+
describedby: { type: "string" },
|
|
8
|
+
title: { type: "string" },
|
|
9
|
+
type: { type: "string" },
|
|
10
|
+
hreflang: { type: "string" },
|
|
11
|
+
meta: {
|
|
12
|
+
type: "object",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
required: ["href"],
|
|
16
|
+
};
|
|
17
|
+
export const linkSchemaObject = {
|
|
18
|
+
oneOf: [linkStringSchemaObject, linkObjectSchemaObject],
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Builds an OpenAPI 3.1 SchemaObject for a resource, including id, type, attributes, relationships, meta, and links
|
|
22
|
+
*/
|
|
23
|
+
export const buildResourceSchemaObject = (options) => {
|
|
24
|
+
const properties = {
|
|
25
|
+
id: options.id ?? {
|
|
26
|
+
type: "string",
|
|
27
|
+
example: "abc",
|
|
28
|
+
},
|
|
29
|
+
type: {
|
|
30
|
+
type: "string",
|
|
31
|
+
enum: [options.type],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const required = ["id", "type"];
|
|
35
|
+
if (options.attributes) {
|
|
36
|
+
properties.attributes = options.attributes;
|
|
37
|
+
required.push("attributes");
|
|
38
|
+
}
|
|
39
|
+
if (options.relationships) {
|
|
40
|
+
properties.relationships = {
|
|
41
|
+
type: "object",
|
|
42
|
+
properties: Object.fromEntries(options.relationships.map((relationship) => {
|
|
43
|
+
const resourceIdentifierSchema = {
|
|
44
|
+
type: "object",
|
|
45
|
+
properties: {
|
|
46
|
+
id: { type: "string", example: "12345" },
|
|
47
|
+
type: { type: "string", enum: [relationship.type] },
|
|
48
|
+
},
|
|
49
|
+
required: ["id", "type"],
|
|
50
|
+
};
|
|
51
|
+
const schemaObject = {
|
|
52
|
+
type: "object",
|
|
53
|
+
properties: {
|
|
54
|
+
data: expandSchema(resourceIdentifierSchema, relationship.cardinality),
|
|
55
|
+
},
|
|
56
|
+
required: ["data"],
|
|
57
|
+
};
|
|
58
|
+
return [relationship.name, schemaObject];
|
|
59
|
+
})),
|
|
60
|
+
required: options.relationships.map((relationship) => relationship.name),
|
|
61
|
+
};
|
|
62
|
+
required.push("relationships");
|
|
63
|
+
}
|
|
64
|
+
if (options.links) {
|
|
65
|
+
properties.links = buildLinksSchemaObject(options.links);
|
|
66
|
+
required.push("links");
|
|
67
|
+
}
|
|
68
|
+
if (options.meta) {
|
|
69
|
+
properties.meta = options.meta;
|
|
70
|
+
required.push("meta");
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
type: "object",
|
|
74
|
+
properties,
|
|
75
|
+
required,
|
|
76
|
+
title: options.title,
|
|
77
|
+
description: options.description,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Builds an OpenAPI 3.1 ResponseObject for data responses including data, meta, links, and included
|
|
82
|
+
*/
|
|
83
|
+
export const buildDataResponseObject = (options) => {
|
|
84
|
+
const properties = {
|
|
85
|
+
data: expandSchema(options.resourceSchema, options.cardinality),
|
|
86
|
+
};
|
|
87
|
+
const required = ["data"];
|
|
88
|
+
if (options.meta) {
|
|
89
|
+
properties.meta = options.meta;
|
|
90
|
+
required.push("meta");
|
|
91
|
+
}
|
|
92
|
+
if (options.links) {
|
|
93
|
+
properties.links = buildLinksSchemaObject(options.links);
|
|
94
|
+
}
|
|
95
|
+
if (options.included) {
|
|
96
|
+
properties.included = {
|
|
97
|
+
type: "array",
|
|
98
|
+
items: {
|
|
99
|
+
oneOf: options.included,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
description: options.description ?? "OK",
|
|
105
|
+
content: {
|
|
106
|
+
"application/vnd.api+json": {
|
|
107
|
+
schema: {
|
|
108
|
+
type: "object",
|
|
109
|
+
properties,
|
|
110
|
+
required,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Builds an OpenAPI 3.1 ResponseObject for error responses containing an errors array
|
|
118
|
+
*/
|
|
119
|
+
export const buildErrorResponseObject = (options) => ({
|
|
120
|
+
description: options.description,
|
|
121
|
+
content: {
|
|
122
|
+
"application/vnd.api+json": {
|
|
123
|
+
schema: {
|
|
124
|
+
type: "object",
|
|
125
|
+
properties: {
|
|
126
|
+
errors: {
|
|
127
|
+
type: "array",
|
|
128
|
+
minLength: 1,
|
|
129
|
+
items: {
|
|
130
|
+
type: "object",
|
|
131
|
+
properties: {
|
|
132
|
+
status: { type: "string", description: "HTTP status code" },
|
|
133
|
+
code: { type: "string" },
|
|
134
|
+
title: { type: "string" },
|
|
135
|
+
detail: { type: "string" },
|
|
136
|
+
source: {
|
|
137
|
+
type: "object",
|
|
138
|
+
properties: {
|
|
139
|
+
pointer: { type: "string" },
|
|
140
|
+
parameter: { type: "string" },
|
|
141
|
+
header: { type: "string" },
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
required: ["status"],
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
required: ["errors"],
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
const buildLinksSchemaObject = (links) => ({
|
|
155
|
+
type: "object",
|
|
156
|
+
properties: Object.fromEntries(Object.entries(links).map(([name, schemaObject]) => [
|
|
157
|
+
name,
|
|
158
|
+
{
|
|
159
|
+
oneOf: [schemaObject, { type: "null" }],
|
|
160
|
+
},
|
|
161
|
+
])),
|
|
162
|
+
});
|
|
163
|
+
const expandSchema = (schema, cardinality) => {
|
|
164
|
+
switch (cardinality) {
|
|
165
|
+
case "one":
|
|
166
|
+
return schema;
|
|
167
|
+
case "one_nullable":
|
|
168
|
+
return {
|
|
169
|
+
oneOf: [schema, { type: "null" }],
|
|
170
|
+
};
|
|
171
|
+
case "many":
|
|
172
|
+
return {
|
|
173
|
+
type: "array",
|
|
174
|
+
items: schema,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jsonapi-serde/openapi",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "OpenAPI schema generation for JSON:API serde",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"author": "Ben Scholzen 'DASPRiD'",
|
|
7
|
+
"license": "BSD-3-Clause",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"jsonapi",
|
|
10
|
+
"typescript",
|
|
11
|
+
"zod",
|
|
12
|
+
"openapi"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/dasprid/jsonapi-serde-js.git"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/**/*"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
"./index": {
|
|
23
|
+
"types": [
|
|
24
|
+
"./dist/index/index.d.ts",
|
|
25
|
+
"./src/index/index.ts"
|
|
26
|
+
],
|
|
27
|
+
"default": "./dist/index/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"openapi3-ts": "^4.4.0",
|
|
32
|
+
"zod": "^3.25.42",
|
|
33
|
+
"@jsonapi-serde/server": "0.0.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"openapi3-ts": "^4.4.0",
|
|
37
|
+
"zod": "^3.25.42",
|
|
38
|
+
"@jsonapi-serde/server": "0.0.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc -p tsconfig.build.json",
|
|
42
|
+
"test": "tsx --test --test-reporter=spec",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"ci:test": "c8 --reporter=lcov pnpm test"
|
|
45
|
+
}
|
|
46
|
+
}
|