@novice1/api-doc-json-helper 0.1.0 → 0.1.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
@@ -95,6 +95,52 @@ const router = routing()
95
95
  //...
96
96
  ```
97
97
 
98
+ ## Postman Specification
99
+
100
+ ```ts
101
+ import {
102
+ Postman
103
+ } from '@novice1/api-doc-generator';
104
+ import {
105
+ PostmanJsonHelper
106
+ } from '@novice1/api-doc-json-helper';
107
+ import routing from '@novice1/routing';
108
+
109
+ PostmanJsonHelper.schemaProperty = 'jsonSchemas'
110
+
111
+ const postman = new Postman(PostmanJsonHelper);
112
+
113
+ const router = routing()
114
+ .get({
115
+ name: 'Main app',
116
+ path: '/app',
117
+ auth: true,
118
+ tags: ['default'],
119
+ parameters: {
120
+
121
+ jsonSchemas: {
122
+ query: {
123
+ '$schema': 'http://json-schema.org/draft-07/schema#',
124
+ type: 'object',
125
+ properties: {
126
+ version: {
127
+ type: 'string',
128
+ description: 'version number',
129
+ enum: ['1','2','3'],
130
+ default: '2'
131
+ }
132
+ }
133
+ }
134
+ }
135
+
136
+ }
137
+ }, function (req, res) {
138
+ res.json(req.query.version)
139
+ });
140
+
141
+ //...
142
+ ```
143
+
98
144
  ## References
99
145
 
100
146
  - [@novice1/api-doc-generator](https://kisiwu.github.io/novice-api-doc-generator/latest/)
package/lib/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './openapi';
2
+ export * from './postman';
package/lib/index.js CHANGED
@@ -2,4 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./openapi"), exports);
5
+ tslib_1.__exportStar(require("./postman"), exports);
5
6
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,oDAAyB"}
@@ -0,0 +1,29 @@
1
+ import { PostmanHelperInterface } from '@novice1/api-doc-generator';
2
+ import { XMLObject } from '@novice1/api-doc-generator/lib/generators/openapi/definitions';
3
+ export declare class PostmanJsonHelper implements PostmanHelperInterface {
4
+ protected _schema: object;
5
+ protected _isRequired: boolean;
6
+ static schemaProperty: string;
7
+ constructor(schema?: object | unknown, isRequired?: boolean);
8
+ getFirstItem(): PostmanJsonHelper | undefined;
9
+ getChildren(): Record<string, PostmanJsonHelper>;
10
+ getAlternatives(): PostmanJsonHelper[];
11
+ getXml?(): XMLObject | undefined;
12
+ isValid(): boolean;
13
+ getType(): string;
14
+ getDescription(): string;
15
+ isRequired(): boolean;
16
+ isUnique(): boolean;
17
+ hasDefaultValue(): boolean;
18
+ getDefaultValue(): unknown;
19
+ hasExampleValue(): boolean;
20
+ getExampleValue(): unknown;
21
+ isDeprecated(): boolean;
22
+ allowsEmptyValue(): boolean;
23
+ getEnum(): unknown[];
24
+ hasMin(): boolean;
25
+ hasMax(): boolean;
26
+ getMin(): number | undefined;
27
+ getMax(): number | undefined;
28
+ getUnit(): string;
29
+ }
package/lib/postman.js ADDED
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PostmanJsonHelper = void 0;
4
+ class PostmanJsonHelper {
5
+ constructor(schema = {}, isRequired) {
6
+ this._isRequired = false;
7
+ this._schema = {};
8
+ if (schema && typeof schema === 'object') {
9
+ const s = schema;
10
+ this._schema = s;
11
+ if (PostmanJsonHelper.schemaProperty && PostmanJsonHelper.schemaProperty in s) {
12
+ const s2 = s[PostmanJsonHelper.schemaProperty];
13
+ if (s2 && typeof s2 === 'object') {
14
+ this._schema = s2;
15
+ }
16
+ }
17
+ if (!('type' in this._schema)) {
18
+ this._schema = {
19
+ type: 'object',
20
+ properties: this._schema
21
+ };
22
+ }
23
+ }
24
+ if (isRequired) {
25
+ this._isRequired = isRequired;
26
+ }
27
+ }
28
+ getFirstItem() {
29
+ const schema = this._schema;
30
+ if ('items' in schema && typeof schema.items === 'object') {
31
+ return new PostmanJsonHelper(schema.items);
32
+ }
33
+ return;
34
+ }
35
+ getChildren() {
36
+ const r = {};
37
+ const schema = this._schema;
38
+ if ('properties' in schema && typeof schema.properties === 'object' && schema.properties) {
39
+ const properties = schema.properties;
40
+ for (const p in properties) {
41
+ const isRequired = 'required' in schema && Array.isArray(schema.required) && schema.required.includes(p);
42
+ r[p] = new PostmanJsonHelper(properties[p], isRequired);
43
+ }
44
+ }
45
+ return r;
46
+ }
47
+ getAlternatives() {
48
+ const r = [];
49
+ const schema = this._schema;
50
+ if ('oneOf' in schema && Array.isArray(schema.oneOf)) {
51
+ for (const p of schema.oneOf) {
52
+ r.push(new PostmanJsonHelper(p));
53
+ }
54
+ }
55
+ return r;
56
+ }
57
+ getXml() {
58
+ return;
59
+ }
60
+ isValid() {
61
+ return !!(this._schema && typeof this._schema === 'object');
62
+ }
63
+ getType() {
64
+ let r = '';
65
+ if ('type' in this._schema && typeof this._schema.type === 'string') {
66
+ r = this._schema.type;
67
+ }
68
+ if ('format' in this._schema && typeof this._schema.format === 'string') {
69
+ r = this._schema.format;
70
+ }
71
+ return r;
72
+ }
73
+ getDescription() {
74
+ let r = '';
75
+ if ('description' in this._schema && typeof this._schema.description === 'string') {
76
+ r = this._schema.description;
77
+ }
78
+ return r;
79
+ }
80
+ isRequired() {
81
+ return this._isRequired;
82
+ }
83
+ isUnique() {
84
+ return !!('uniqueItems' in this._schema && this._schema.uniqueItems);
85
+ }
86
+ hasDefaultValue() {
87
+ return !!('default' in this._schema && typeof this._schema.default != 'undefined');
88
+ }
89
+ getDefaultValue() {
90
+ return 'default' in this._schema ? this._schema.default : undefined;
91
+ }
92
+ hasExampleValue() {
93
+ const schema = this._schema;
94
+ return !!('examples' in schema && Array.isArray(schema.examples) && schema.examples.length);
95
+ }
96
+ getExampleValue() {
97
+ const schema = this._schema;
98
+ if ('examples' in schema && Array.isArray(schema.examples) && schema.examples.length) {
99
+ return schema.examples[0];
100
+ }
101
+ return;
102
+ }
103
+ isDeprecated() {
104
+ return !!('deprecated' in this._schema && this._schema.deprecated);
105
+ }
106
+ allowsEmptyValue() {
107
+ let r = false;
108
+ if ('enum' in this._schema && Array.isArray(this._schema.enum)) {
109
+ const enume = this._schema.enum;
110
+ r = ['', null].some(v => enume.includes(v));
111
+ }
112
+ return r;
113
+ }
114
+ getEnum() {
115
+ let r = [];
116
+ if ('enum' in this._schema && Array.isArray(this._schema.enum)) {
117
+ r = this._schema.enum;
118
+ }
119
+ return r;
120
+ }
121
+ hasMin() {
122
+ return 'minProperties' in this._schema || 'minItems' in this._schema || 'minimum' in this._schema || 'minLength' in this._schema;
123
+ }
124
+ hasMax() {
125
+ return 'maxProperties' in this._schema || 'maxItems' in this._schema || 'maximum' in this._schema || 'maxLength' in this._schema;
126
+ }
127
+ getMin() {
128
+ if ('minProperties' in this._schema && typeof this._schema.minProperties === 'number') {
129
+ return this._schema.minProperties;
130
+ }
131
+ if ('minItems' in this._schema && typeof this._schema.minItems === 'number') {
132
+ return this._schema.minItems;
133
+ }
134
+ if ('minimum' in this._schema && typeof this._schema.minimum === 'number') {
135
+ return this._schema.minimum;
136
+ }
137
+ if ('minLength' in this._schema && typeof this._schema.minLength === 'number') {
138
+ return this._schema.minLength;
139
+ }
140
+ return;
141
+ }
142
+ getMax() {
143
+ if ('maxProperties' in this._schema && typeof this._schema.maxProperties === 'number') {
144
+ return this._schema.maxProperties;
145
+ }
146
+ if ('maxItems' in this._schema && typeof this._schema.maxItems === 'number') {
147
+ return this._schema.maxItems;
148
+ }
149
+ if ('maximum' in this._schema && typeof this._schema.maximum === 'number') {
150
+ return this._schema.maximum;
151
+ }
152
+ if ('maxLength' in this._schema && typeof this._schema.maxLength === 'number') {
153
+ return this._schema.maxLength;
154
+ }
155
+ return;
156
+ }
157
+ getUnit() {
158
+ return '';
159
+ }
160
+ }
161
+ exports.PostmanJsonHelper = PostmanJsonHelper;
162
+ PostmanJsonHelper.schemaProperty = '';
163
+ //# sourceMappingURL=postman.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postman.js","sourceRoot":"","sources":["../src/postman.ts"],"names":[],"mappings":";;;AAIA,MAAa,iBAAiB;IAM1B,YAAY,SAA2B,EAAE,EAAE,UAAoB;QAJrD,gBAAW,GAAG,KAAK,CAAA;QAKzB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;QACjB,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YACvC,MAAM,CAAC,GAAG,MAAiC,CAAA;YAC3C,IAAI,CAAC,OAAO,GAAG,CAAC,CAAA;YAChB,IAAI,iBAAiB,CAAC,cAAc,IAAI,iBAAiB,CAAC,cAAc,IAAI,CAAC,EAAE,CAAC;gBAC5E,MAAM,EAAE,GAAG,CAAC,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAA;gBAC9C,IAAI,EAAE,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;oBAC/B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;gBACrB,CAAC;YACL,CAAC;YACD,IAAI,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC5B,IAAI,CAAC,OAAO,GAAG;oBACX,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE,IAAI,CAAC,OAAO;iBAC3B,CAAA;YACL,CAAC;QACL,CAAC;QACD,IAAI,UAAU,EAAE,CAAC;YACb,IAAI,CAAC,WAAW,GAAG,UAAU,CAAA;QACjC,CAAC;IACL,CAAC;IACD,YAAY;QAER,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAA;QAE3B,IAAI,OAAO,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACxD,OAAO,I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AAE,CAAC;YACpF,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAA;QACrC,CAAC;QACD,IAAI,UAAU,IAAI,IAAI,CAAC,OAAO,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC1E,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAA;QAChC,CAAC;QACD,IAAI,SAAS,IAAI,IAAI,CAAC,OAAO,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACxE,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAA;QAC/B,CAAC;QACD,IAAI,WAAW,IAAI,IAAI,CAAC,OAAO,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YAC5E,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAA;QACjC,CAAC;QACD,OAAM;IACV,CAAC;IACD,OAAO;QACH,OAAO,EAAE,CAAA;IACb,CAAC;;AAvKL,8CAwKC;AApKU,gCAAc,GAAW,EAAE,AAAb,CAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novice1/api-doc-json-helper",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {