@xyd-js/openapi 0.1.0-xyd.1 → 0.1.0-xyd.2
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/CHANGELOG.md +9 -0
- package/dist/index.cjs +14 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/examples/dist/index.cjs +2 -0
- package/examples/dist/index.cjs.map +1 -0
- package/examples/dist/index.d.cts +2 -0
- package/examples/dist/index.d.ts +2 -0
- package/examples/dist/index.js +2 -0
- package/examples/dist/index.js.map +1 -0
- package/examples/semi/index.ts +16 -0
- package/examples/semi/openapi.yaml +365 -0
- package/examples/semi/references.json +500 -0
- package/examples/webhooks/references.json +895 -0
- package/package.json +4 -3
- package/src/paths.ts +4 -5
- package/src/properties.ts +6 -0
- package/src/schema.ts +10 -4
- package/tsup.examples-config.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyd-js/openapi",
|
|
3
|
-
"version": "0.1.0-xyd.
|
|
3
|
+
"version": "0.1.0-xyd.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
"oas": "^25.0.3",
|
|
12
12
|
"openapi-sampler": "^1.5.1",
|
|
13
13
|
"openapi-types": "^12.1.3",
|
|
14
|
-
"@xyd-js/uniform": "0.1.0-xyd.
|
|
14
|
+
"@xyd-js/uniform": "0.1.0-xyd.6"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/js-yaml": "^4.0.9",
|
|
18
|
-
"tsup": "^8.3.0"
|
|
18
|
+
"tsup": "^8.3.0",
|
|
19
|
+
"rimraf": "^3.0.2"
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|
|
21
22
|
"clean": "rimraf build",
|
package/src/paths.ts
CHANGED
|
@@ -11,14 +11,14 @@ import {
|
|
|
11
11
|
|
|
12
12
|
// oapPathToReference converts an OpenAPI path to a uniform Reference
|
|
13
13
|
export function oapPathToReference(
|
|
14
|
-
httpMethod: "get" | "put" | "post" | "delete", // TODO: ts type
|
|
14
|
+
httpMethod: "get" | "put" | "post" | "delete" | "patch", // TODO: ts type
|
|
15
15
|
path: string,
|
|
16
16
|
oapPath: OpenAPIV3.PathItemObject,
|
|
17
17
|
): Reference | null {
|
|
18
18
|
const mType = httpMethodToUniformMethod(httpMethod)
|
|
19
19
|
|
|
20
20
|
if (!mType) {
|
|
21
|
-
console.error(`Unsupported method: ${httpMethod}`)
|
|
21
|
+
console.error(`Unsupported method v222: ${httpMethod}`)
|
|
22
22
|
return null
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -42,7 +42,7 @@ export function oapPathToReference(
|
|
|
42
42
|
context: {
|
|
43
43
|
method: httpMethod,
|
|
44
44
|
|
|
45
|
-
path
|
|
45
|
+
path: `${encodeURIComponent(path)}`,
|
|
46
46
|
},
|
|
47
47
|
|
|
48
48
|
examples: {
|
|
@@ -59,10 +59,9 @@ export function oapPathToReference(
|
|
|
59
59
|
Object.entries(paramtersMap).forEach(([key, definitionProperties]) => {
|
|
60
60
|
let title: string
|
|
61
61
|
|
|
62
|
-
// TODO: add context to definition
|
|
63
62
|
switch (key) {
|
|
64
63
|
case 'path':
|
|
65
|
-
title = "
|
|
64
|
+
title = "Path parameters"
|
|
66
65
|
break
|
|
67
66
|
case 'query':
|
|
68
67
|
title = "Query"
|
package/src/properties.ts
CHANGED
|
@@ -17,6 +17,12 @@ export function schemaObjectToDefinitionProperties(v: OpenAPIV3.SchemaObject): D
|
|
|
17
17
|
}, [] as DefinitionProperty[])
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
if (objProp.type === "array") {
|
|
21
|
+
const items = objProp.items as OpenAPIV3.SchemaObject
|
|
22
|
+
|
|
23
|
+
merged = schemaObjectToDefinitionProperties(items)
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
return {
|
|
21
27
|
name: name,
|
|
22
28
|
type: objProp.type || "",
|
package/src/schema.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {OpenAPIV3} from "openapi-types";
|
|
2
2
|
import Oas from "oas";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
import type {Reference, OpenAPIReferenceContext} from "@xyd-js/uniform";
|
|
4
5
|
|
|
5
6
|
import {SUPPORTED_HTTP_METHODS} from "./const";
|
|
6
7
|
import {oapPathToReference} from "./paths";
|
|
@@ -17,9 +18,9 @@ export function oapSchemaToReferences(
|
|
|
17
18
|
const references: Reference[] = [];
|
|
18
19
|
const oas = new Oas(schema as any);
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
let type: ReferenceType;
|
|
21
|
+
const server = schema.servers?.[0]?.url || ""
|
|
22
22
|
|
|
23
|
+
Object.entries(schema.paths).forEach(([path, oapPath]) => {
|
|
23
24
|
SUPPORTED_HTTP_METHODS.forEach((eachMethod) => {
|
|
24
25
|
const httpMethod = eachMethod.toLowerCase()
|
|
25
26
|
|
|
@@ -32,8 +33,10 @@ export function oapSchemaToReferences(
|
|
|
32
33
|
break
|
|
33
34
|
case 'delete':
|
|
34
35
|
break
|
|
36
|
+
case 'patch':
|
|
37
|
+
break
|
|
35
38
|
default:
|
|
36
|
-
console.error(`Unsupported method: ${httpMethod}`)
|
|
39
|
+
console.error(`Unsupported method v111: ${httpMethod}`)
|
|
37
40
|
return
|
|
38
41
|
}
|
|
39
42
|
|
|
@@ -44,6 +47,9 @@ export function oapSchemaToReferences(
|
|
|
44
47
|
)
|
|
45
48
|
|
|
46
49
|
if (reference) {
|
|
50
|
+
const ctx = reference.context as OpenAPIReferenceContext
|
|
51
|
+
ctx.path = `${encodeURIComponent(server)}${encodeURIComponent(path)}` // TODO: it should be inside `oapPathToReference` ?
|
|
52
|
+
|
|
47
53
|
const operation = oas.operation(path, httpMethod);
|
|
48
54
|
reference.examples.groups = oapExamples(oas, operation)
|
|
49
55
|
|
package/tsup.examples-config.ts
CHANGED
|
@@ -6,12 +6,12 @@ const isDebugMode = !!process.env.DEBUG
|
|
|
6
6
|
|
|
7
7
|
export default defineConfig({
|
|
8
8
|
entry: [
|
|
9
|
-
"./examples/
|
|
9
|
+
"./examples/semi/index.ts"
|
|
10
10
|
],
|
|
11
11
|
format: ['esm', 'cjs'], // Output both ESM and CJS formats
|
|
12
12
|
target: 'node16', // Ensure compatibility with Node.js 16
|
|
13
13
|
dts: {
|
|
14
|
-
entry: "./examples/
|
|
14
|
+
entry: "./examples/semi/index.ts",
|
|
15
15
|
resolve: true, // Resolve external types
|
|
16
16
|
},
|
|
17
17
|
splitting: false, // Disable code splitting
|