@byyuurin/nitro-openapi 0.0.7 → 0.1.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/dist/index.mjs CHANGED
@@ -4,11 +4,11 @@ function createOpenApiRegister(options) {
4
4
  const { paths = {}, components = {}, security = [], servers = [], info, tags = [] } = options;
5
5
  const defineOperation = (operation) => operation;
6
6
  function register(route, routeOperation, method = "get") {
7
- const _route = normalizeRoute(route);
8
- paths[_route] = defu(
9
- { [method]: routeOperation },
10
- paths[_route]
11
- );
7
+ const path = normalizeRoute(route);
8
+ paths[path] = {
9
+ ...paths[path],
10
+ [method]: routeOperation
11
+ };
12
12
  }
13
13
  function merge(config) {
14
14
  return mergeConfig(
@@ -43,33 +43,31 @@ function normalizeRoute(_route) {
43
43
  return route;
44
44
  }
45
45
  function mergeConfig(defaults, appends) {
46
- const methods = /* @__PURE__ */ new Set(["delete", "get", "head", "options", "patch", "post", "put", "trace"]);
47
46
  const { info } = appends;
48
- const { paths = {} } = defaults;
47
+ const { openapi, servers, security, tags, paths = {} } = defaults;
49
48
  for (const path in paths) {
50
49
  const operations = paths[path];
50
+ const operationsAppend = appends.paths?.[path] ?? {};
51
+ if ("$ref" in operationsAppend) {
52
+ paths[path] = operationsAppend;
53
+ continue;
54
+ }
51
55
  if ("$ref" in operations)
52
56
  continue;
53
- paths[path] = Object.fromEntries(Object.entries(operations).map(([key, obj]) => {
54
- if (methods.has(key))
55
- return [key, normalizeSchema(obj)];
56
- return [key, obj];
57
+ paths[path] = Object.fromEntries(Object.entries(operations).map(([method, operation]) => {
58
+ const extendOperation = operationsAppend[method] ?? {};
59
+ return [method, defu(operation, extendOperation)];
57
60
  }));
58
61
  }
59
- return defu({ info }, defaults, appends);
60
- }
61
- function normalizeSchema(obj) {
62
- if ("$ref" in obj)
63
- return obj;
64
- const { parameters = [] } = obj;
65
- obj.parameters = parameters.map((p) => {
66
- if ("$ref" in p)
67
- return p;
68
- return defu(p, {
69
- schema: { type: "string" }
70
- });
71
- });
72
- return obj;
62
+ return {
63
+ openapi,
64
+ info,
65
+ servers,
66
+ security,
67
+ tags,
68
+ ...defu(defaults, appends),
69
+ paths
70
+ };
73
71
  }
74
72
 
75
73
  function toExampleSchema(example, description, options = {}) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@byyuurin/nitro-openapi",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.1.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/byyuurin/nitro-openapi",
@@ -23,18 +23,17 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "defu": "^6.1.4",
27
- "openapi-typescript": "^6.7.6"
26
+ "defu": "^6.1.4"
28
27
  },
29
28
  "devDependencies": {
30
- "@byyuurin/eslint-config": "^1.6.3",
31
- "bumpp": "^9.8.1",
32
- "eslint": "^9.14.0",
33
- "eslint-plugin-format": "^0.1.2",
34
- "nitropack": "^2.10.4",
35
- "typescript": "^5.6.3",
29
+ "@byyuurin/eslint-config": "^1.8.3",
30
+ "bumpp": "^9.11.1",
31
+ "eslint": "^9.30.1",
32
+ "eslint-plugin-format": "^0.1.3",
33
+ "nitropack": "^2.11.13",
34
+ "typescript": "^5.8.3",
36
35
  "unbuild": "^2.0.0",
37
- "vitest": "^1.6.0"
36
+ "vitest": "^1.6.1"
38
37
  },
39
38
  "resolutions": {
40
39
  "@byyuurin/nitro-openapi": "link:."