@innet/server 2.0.0-beta.6 → 2.0.0-beta.7

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
@@ -1556,6 +1556,34 @@ export default (
1556
1556
  )
1557
1557
  ```
1558
1558
 
1559
+ #### group
1560
+
1561
+ You can organize tags into groups using the `group` property.
1562
+ This adds tag groups support to the OpenAPI specification,
1563
+ which is displayed in documentation viewers.
1564
+
1565
+ *src/app.tsx*
1566
+ ```typescript jsx
1567
+ export default (
1568
+ <server>
1569
+ <api>
1570
+ <tag group='Authentication' name='auth'>
1571
+ <endpoint method='post' path='/login' />
1572
+ <endpoint method='post' path='/logout' />
1573
+ </tag>
1574
+ <tag group='Users' name='users'>
1575
+ <endpoint method='get' path='/users' />
1576
+ <endpoint method='post' path='/users' />
1577
+ </tag>
1578
+ </api>
1579
+ </server>
1580
+ )
1581
+ ```
1582
+
1583
+ This will create tag groups in your OpenAPI documentation:
1584
+ - **Authentication** group containing the `auth` tag
1585
+ - **Users** group containing the `users` tag
1586
+
1559
1587
  ### \<param>
1560
1588
 
1561
1589
  [← back](#endpoints)
package/index.es6.js CHANGED
@@ -49,7 +49,7 @@ export { preset } from './plugins/main/preset/preset.es6.js';
49
49
  export { response, statuses } from './plugins/main/response/response.es6.js';
50
50
  export { returnPlugin } from './plugins/main/return/return.es6.js';
51
51
  export { server } from './plugins/main/server/server.es6.js';
52
- export { tag } from './plugins/main/tag/tag.es6.js';
52
+ export { TAG_GROUP_NAME, tag } from './plugins/main/tag/tag.es6.js';
53
53
  export { variable } from './plugins/main/variable/variable.es6.js';
54
54
  export { cms } from './plugins/request/cms/cms.es6.js';
55
55
  export { cookie } from './plugins/request/cookie/cookie.es6.js';
package/index.js CHANGED
@@ -196,6 +196,7 @@ exports.response = response.response;
196
196
  exports.statuses = response.statuses;
197
197
  exports.returnPlugin = _return.returnPlugin;
198
198
  exports.server = server.server;
199
+ exports.TAG_GROUP_NAME = tag.TAG_GROUP_NAME;
199
200
  exports.tag = tag.tag;
200
201
  exports.variable = variable.variable;
201
202
  exports.cms = cms.cms;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "2.0.0-beta.6",
3
+ "version": "2.0.0-beta.7",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -1 +1 @@
1
- export { tag } from './tag.es6.js';
1
+ export { TAG_GROUP_NAME, tag } from './tag.es6.js';
@@ -6,4 +6,5 @@ var tag = require('./tag.js');
6
6
 
7
7
 
8
8
 
9
+ exports.TAG_GROUP_NAME = tag.TAG_GROUP_NAME;
9
10
  exports.tag = tag.tag;
@@ -1,4 +1,9 @@
1
1
  import { type HandlerPlugin } from 'innet';
2
+ export interface TagGroup {
3
+ name: string;
4
+ tags: string[];
5
+ }
6
+ export declare const TAG_GROUP_NAME = "x-tagGroups";
2
7
  export interface TagProps {
3
8
  children?: any;
4
9
  /**
@@ -6,7 +11,9 @@ export interface TagProps {
6
11
  * [CommonMark syntax](https://spec.commonmark.org) MAY be used for rich text representation.
7
12
  * */
8
13
  description?: string;
9
- /** The name of the tag. */
14
+ /** A name of the tag group. */
15
+ group?: string;
16
+ /** A name of the tag. */
10
17
  name: string;
11
18
  }
12
19
  export declare const tag: HandlerPlugin;
@@ -4,11 +4,12 @@ import '../../../hooks/index.es6.js';
4
4
  import { tagContext } from '../../../hooks/useTag/useTag.es6.js';
5
5
  import { useApi } from '../../../hooks/useApi/useApi.es6.js';
6
6
 
7
+ const TAG_GROUP_NAME = 'x-tagGroups';
7
8
  const tag = () => {
8
9
  if (useContext(tagContext)) {
9
10
  throw Error('You cannot use a <tag> inside another one');
10
11
  }
11
- const { children, description, name, } = useProps();
12
+ const { children, description, group, name, } = useProps();
12
13
  const { docs } = useApi();
13
14
  const tag = { name };
14
15
  if (description) {
@@ -23,9 +24,25 @@ const tag = () => {
23
24
  else {
24
25
  throw Error(`You cannot use two tags with the same name (${name})`);
25
26
  }
27
+ if (group) {
28
+ if (docs[TAG_GROUP_NAME]) {
29
+ const groups = docs[TAG_GROUP_NAME];
30
+ const tagGroup = groups.find(({ name }) => name === group);
31
+ if (tagGroup) {
32
+ tagGroup.tags.push(name);
33
+ }
34
+ else {
35
+ groups.push({ name: group, tags: [name] });
36
+ }
37
+ }
38
+ else {
39
+ // @ts-expect-error Custom field
40
+ docs[TAG_GROUP_NAME] = [{ name: group, tags: [name] }];
41
+ }
42
+ }
26
43
  const handler = useNewHandler();
27
44
  handler[tagContext.key] = tag;
28
45
  innet(children, handler);
29
46
  };
30
47
 
31
- export { tag };
48
+ export { TAG_GROUP_NAME, tag };
@@ -8,11 +8,12 @@ require('../../../hooks/index.js');
8
8
  var useTag = require('../../../hooks/useTag/useTag.js');
9
9
  var useApi = require('../../../hooks/useApi/useApi.js');
10
10
 
11
+ const TAG_GROUP_NAME = 'x-tagGroups';
11
12
  const tag = () => {
12
13
  if (jsx.useContext(useTag.tagContext)) {
13
14
  throw Error('You cannot use a <tag> inside another one');
14
15
  }
15
- const { children, description, name, } = jsx.useProps();
16
+ const { children, description, group, name, } = jsx.useProps();
16
17
  const { docs } = useApi.useApi();
17
18
  const tag = { name };
18
19
  if (description) {
@@ -27,9 +28,26 @@ const tag = () => {
27
28
  else {
28
29
  throw Error(`You cannot use two tags with the same name (${name})`);
29
30
  }
31
+ if (group) {
32
+ if (docs[TAG_GROUP_NAME]) {
33
+ const groups = docs[TAG_GROUP_NAME];
34
+ const tagGroup = groups.find(({ name }) => name === group);
35
+ if (tagGroup) {
36
+ tagGroup.tags.push(name);
37
+ }
38
+ else {
39
+ groups.push({ name: group, tags: [name] });
40
+ }
41
+ }
42
+ else {
43
+ // @ts-expect-error Custom field
44
+ docs[TAG_GROUP_NAME] = [{ name: group, tags: [name] }];
45
+ }
46
+ }
30
47
  const handler = innet.useNewHandler();
31
48
  handler[useTag.tagContext.key] = tag;
32
49
  innet.innet(children, handler);
33
50
  };
34
51
 
52
+ exports.TAG_GROUP_NAME = TAG_GROUP_NAME;
35
53
  exports.tag = tag;