apollo-conn-gen 0.2.1 → 0.3.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/dist/cli/oas-helpers/index.js +5 -5
- package/dist/cli/oas-helpers/index.js.map +1 -1
- package/dist/cli/oas.js +5 -0
- package/dist/cli/oas.js.map +1 -1
- package/dist/oas/index.d.ts +2 -2
- package/dist/oas/index.js +2 -2
- package/dist/oas/index.js.map +1 -1
- package/dist/oas/io/writer.d.ts +1 -2
- package/dist/oas/io/writer.js +14 -17
- package/dist/oas/io/writer.js.map +1 -1
- package/dist/oas/nodes/arr.js +1 -1
- package/dist/oas/nodes/arr.js.map +1 -1
- package/dist/oas/nodes/body.js +3 -1
- package/dist/oas/nodes/body.js.map +1 -1
- package/dist/oas/nodes/circularRef.d.ts +1 -1
- package/dist/oas/nodes/circularRef.js.map +1 -1
- package/dist/oas/nodes/comp.d.ts +2 -0
- package/dist/oas/nodes/comp.js +44 -7
- package/dist/oas/nodes/comp.js.map +1 -1
- package/dist/oas/nodes/en.d.ts +1 -1
- package/dist/oas/nodes/en.js +3 -3
- package/dist/oas/nodes/en.js.map +1 -1
- package/dist/oas/nodes/factory.d.ts +6 -3
- package/dist/oas/nodes/factory.js +149 -105
- package/dist/oas/nodes/factory.js.map +1 -1
- package/dist/oas/nodes/iType.d.ts +2 -2
- package/dist/oas/nodes/iType.js.map +1 -1
- package/dist/oas/nodes/internal.d.ts +3 -3
- package/dist/oas/nodes/internal.js +3 -3
- package/dist/oas/nodes/internal.js.map +1 -1
- package/dist/oas/nodes/obj.d.ts +1 -1
- package/dist/oas/nodes/obj.js +35 -44
- package/dist/oas/nodes/obj.js.map +1 -1
- package/dist/oas/nodes/param.js +3 -1
- package/dist/oas/nodes/param.js.map +1 -1
- package/dist/oas/nodes/prop.d.ts +1 -1
- package/dist/oas/nodes/prop.js +4 -1
- package/dist/oas/nodes/prop.js.map +1 -1
- package/dist/oas/nodes/propArray.d.ts +2 -3
- package/dist/oas/nodes/propArray.js +13 -19
- package/dist/oas/nodes/propArray.js.map +1 -1
- package/dist/oas/nodes/propCircRef.d.ts +14 -0
- package/dist/oas/nodes/propCircRef.js +35 -0
- package/dist/oas/nodes/propCircRef.js.map +1 -0
- package/dist/oas/nodes/propComp.d.ts +1 -2
- package/dist/oas/nodes/propComp.js +5 -12
- package/dist/oas/nodes/propComp.js.map +1 -1
- package/dist/oas/nodes/propEn.d.ts +15 -0
- package/dist/oas/nodes/propEn.js +38 -0
- package/dist/oas/nodes/propEn.js.map +1 -0
- package/dist/oas/nodes/propObj.d.ts +1 -2
- package/dist/oas/nodes/propObj.js +4 -5
- package/dist/oas/nodes/propObj.js.map +1 -1
- package/dist/oas/nodes/propRef.d.ts +5 -4
- package/dist/oas/nodes/propRef.js +27 -21
- package/dist/oas/nodes/propRef.js.map +1 -1
- package/dist/oas/nodes/propScalar.d.ts +2 -3
- package/dist/oas/nodes/propScalar.js +11 -7
- package/dist/oas/nodes/propScalar.js.map +1 -1
- package/dist/oas/nodes/ref.d.ts +3 -0
- package/dist/oas/nodes/ref.js +8 -3
- package/dist/oas/nodes/ref.js.map +1 -1
- package/dist/oas/nodes/{response.d.ts → res.d.ts} +1 -1
- package/dist/oas/nodes/{response.js → res.js} +6 -4
- package/dist/oas/nodes/res.js.map +1 -0
- package/dist/oas/nodes/type.d.ts +2 -3
- package/dist/oas/nodes/type.js +3 -18
- package/dist/oas/nodes/type.js.map +1 -1
- package/dist/oas/nodes/typeUtils.d.ts +3 -0
- package/dist/oas/nodes/typeUtils.js +23 -4
- package/dist/oas/nodes/typeUtils.js.map +1 -1
- package/dist/oas/nodes/union.d.ts +0 -1
- package/dist/oas/nodes/union.js +62 -60
- package/dist/oas/nodes/union.js.map +1 -1
- package/dist/oas/oasContext.d.ts +3 -3
- package/dist/oas/oasContext.js +4 -7
- package/dist/oas/oasContext.js.map +1 -1
- package/dist/oas/oasGen.d.ts +5 -2
- package/dist/oas/oasGen.js +9 -6
- package/dist/oas/oasGen.js.map +1 -1
- package/dist/oas/prompts/prompt.js +11 -3
- package/dist/oas/prompts/prompt.js.map +1 -1
- package/dist/tests/runners.js +7 -3
- package/dist/tests/runners.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/oas/nodes/response.js.map +0 -1
|
@@ -14,14 +14,14 @@ export { Patch } from './patch.js';
|
|
|
14
14
|
export { Delete } from './delete.js';
|
|
15
15
|
export { Body } from './body.js';
|
|
16
16
|
export { Obj } from './obj.js';
|
|
17
|
-
export {
|
|
18
|
-
export { Response } from './response.js';
|
|
17
|
+
export { Res } from './res.js';
|
|
19
18
|
export { Scalar } from './scalar.js';
|
|
20
19
|
export { Union } from './union.js';
|
|
21
20
|
export { PropArray } from './propArray.js';
|
|
22
21
|
export { PropObj } from './propObj.js';
|
|
23
22
|
export { PropComp } from './propComp.js';
|
|
24
|
-
export {
|
|
23
|
+
export { PropCircRef } from './propCircRef.js';
|
|
24
|
+
export { PropEn } from './propEn.js';
|
|
25
25
|
export { PropScalar } from './propScalar.js';
|
|
26
26
|
export { T } from './typeUtils.js';
|
|
27
27
|
//# sourceMappingURL=internal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/oas/nodes/internal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/oas/nodes/internal.ts"],"names":[],"mappings":"AA+BA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["// -- internal.js --\nimport { IType } from './iType.js';\nimport { Type } from './type.js';\nimport { Prop } from './prop.js';\nimport { Param } from './param.js';\nimport { PropArray } from './propArray.js';\nimport { PropObj } from './propObj.js';\nimport { PropComp } from './propComp.js';\nimport { PropCircRef } from './propCircRef.js';\nimport { PropEn } from './propEn.js';\nimport { PropScalar } from './propScalar.js';\nimport { ReferenceObject } from './referenceObject.js';\nimport { Arr } from './arr.js';\nimport { CircularRef } from './circularRef.js';\nimport { Composed } from './comp.js';\nimport { En } from './en.js';\nimport { Factory } from './factory.js';\nimport { Get } from './get.js';\nimport { Post } from './post.js';\nimport { Put } from './put.js';\nimport { Patch } from './patch.js';\nimport { Delete } from './delete.js';\nimport { Body } from './body.js';\nimport { Obj } from './obj.js';\nimport { Ref } from './ref.js';\nimport { Res } from './res.js';\nimport { Scalar } from './scalar.js';\nimport { Union } from './union.js';\nimport { T } from './typeUtils.js';\nimport { Op } from './op.js';\n\nexport * from './iType.js';\nexport { Type } from './type.js';\nexport { type ReferenceObject } from './referenceObject.js';\nexport { Prop } from './prop.js';\nexport { Param } from './param.js';\nexport { Arr } from './arr.js';\nexport { CircularRef } from './circularRef.js';\nexport { Composed } from './comp.js';\nexport { En } from './en.js';\nexport { Factory } from './factory.js';\nexport { Get } from './get.js';\nexport { Post } from './post.js';\nexport { Put } from './put.js';\nexport { Patch } from './patch.js';\nexport { Delete } from './delete.js';\nexport { Body } from './body.js';\nexport { Obj } from './obj.js';\nexport { Res } from './res.js';\nexport { Scalar } from './scalar.js';\nexport { Union } from './union.js';\nexport { PropArray } from './propArray.js';\nexport { PropObj } from './propObj.js';\nexport { PropComp } from './propComp.js';\nexport { PropCircRef } from './propCircRef.js';\nexport { PropEn } from './propEn.js';\nexport { PropScalar } from './propScalar.js';\nexport { T } from './typeUtils.js';\nexport { type Op } from './op.js';\n"]}
|
package/dist/oas/nodes/obj.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export declare class Obj extends Type {
|
|
|
11
11
|
visit(context: OasContext): void;
|
|
12
12
|
generate(context: OasContext, writer: Writer, selection: string[]): void;
|
|
13
13
|
select(context: OasContext, writer: Writer, selection: string[]): void;
|
|
14
|
-
private updateName;
|
|
15
14
|
private visitProperties;
|
|
15
|
+
private updateName;
|
|
16
16
|
}
|
package/dist/oas/nodes/obj.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { Body, Type } from './internal.js';
|
|
1
|
+
import { Arr, Body, Factory, PropArray, Type, Res } from './internal.js';
|
|
2
2
|
import { trace } from '../log/trace.js';
|
|
3
3
|
import { Naming } from '../utils/naming.js';
|
|
4
|
-
import { Arr } from './arr.js';
|
|
5
|
-
import { Factory } from './factory.js';
|
|
6
|
-
import { PropArray } from './propArray.js';
|
|
7
|
-
import { Ref } from './ref.js';
|
|
8
|
-
import { Response } from './response.js';
|
|
9
4
|
import _ from 'lodash';
|
|
10
5
|
export class Obj extends Type {
|
|
11
6
|
schema;
|
|
@@ -16,7 +11,7 @@ export class Obj extends Type {
|
|
|
16
11
|
this.updateName();
|
|
17
12
|
}
|
|
18
13
|
forPrompt(_context) {
|
|
19
|
-
return
|
|
14
|
+
return `[object] ${Naming.getRefName(this.name)}`;
|
|
20
15
|
}
|
|
21
16
|
get id() {
|
|
22
17
|
return `obj:${this.kind}:${this.name}`;
|
|
@@ -42,7 +37,7 @@ export class Obj extends Type {
|
|
|
42
37
|
if (_.isEmpty(this.props)) {
|
|
43
38
|
return;
|
|
44
39
|
}
|
|
45
|
-
if (context.inContextOf('
|
|
40
|
+
if (context.inContextOf('Res', this)) {
|
|
46
41
|
writer.append(Naming.genTypeName(this.name));
|
|
47
42
|
return;
|
|
48
43
|
}
|
|
@@ -72,41 +67,6 @@ export class Obj extends Type {
|
|
|
72
67
|
}
|
|
73
68
|
trace(context, '<- [obj::select]', `-> out: ${this.name}`);
|
|
74
69
|
}
|
|
75
|
-
updateName() {
|
|
76
|
-
let name = this.name;
|
|
77
|
-
// If we are an inline object named "items", try to create a better name.
|
|
78
|
-
if (!name || name === 'items') {
|
|
79
|
-
const parent = this.parent;
|
|
80
|
-
const parentName = parent.name;
|
|
81
|
-
// if the parent is a reference, we can use the name of the obj itself
|
|
82
|
-
if (parent instanceof Ref) {
|
|
83
|
-
name = parentName.replace('ref:', 'obj:');
|
|
84
|
-
}
|
|
85
|
-
// else is our parent an array?
|
|
86
|
-
else if (parent instanceof Arr || parent instanceof PropArray) {
|
|
87
|
-
// if so, synthesize a name based on the parent name
|
|
88
|
-
name = Naming.genTypeName(Naming.getRefName(parentName) + 'Item');
|
|
89
|
-
}
|
|
90
|
-
// if the parent is a response, we can use the operation name and append "Response"
|
|
91
|
-
else if (parent instanceof Response) {
|
|
92
|
-
const op = parent.parent;
|
|
93
|
-
name = op.getGqlOpName() + 'Response';
|
|
94
|
-
}
|
|
95
|
-
else if (parent instanceof Body) {
|
|
96
|
-
// const op = parent.parent as Post;
|
|
97
|
-
name = this.name + 'Input';
|
|
98
|
-
}
|
|
99
|
-
// if the parent is an object then we can use the parent name
|
|
100
|
-
else if (parent instanceof Obj) {
|
|
101
|
-
name = parentName + 'Obj';
|
|
102
|
-
}
|
|
103
|
-
// extreme case -- we synthesize an anonymous name
|
|
104
|
-
else {
|
|
105
|
-
name = `[anonymous:${this.parent.name}]`;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
this.name = name;
|
|
109
|
-
}
|
|
110
70
|
visitProperties(context) {
|
|
111
71
|
if (!this.schema.properties) {
|
|
112
72
|
return;
|
|
@@ -122,7 +82,6 @@ export class Obj extends Type {
|
|
|
122
82
|
for (const [key, schemaValue] of sorted) {
|
|
123
83
|
const prop = Factory.fromProp(context, this, key, schemaValue);
|
|
124
84
|
this.props.set(prop.name, prop);
|
|
125
|
-
// TODO: we should not be adding this twice
|
|
126
85
|
if (!this.children.includes(prop)) {
|
|
127
86
|
this.add(prop);
|
|
128
87
|
}
|
|
@@ -137,5 +96,37 @@ export class Obj extends Type {
|
|
|
137
96
|
}
|
|
138
97
|
trace(context, '<- [obj::props]', 'out props ' + this.props.size);
|
|
139
98
|
}
|
|
99
|
+
updateName() {
|
|
100
|
+
let name = this.name;
|
|
101
|
+
// If we are an inline object named "items", try to create a better name.
|
|
102
|
+
if (!name || name === 'items') {
|
|
103
|
+
const parent = this.parent;
|
|
104
|
+
const parentName = parent.name;
|
|
105
|
+
// is our parent an array?
|
|
106
|
+
if (parent instanceof Arr || parent instanceof PropArray) {
|
|
107
|
+
// if so, synthesize a name based on the parent name
|
|
108
|
+
name = Naming.genTypeName(Naming.getRefName(parentName) + 'Item');
|
|
109
|
+
}
|
|
110
|
+
// if the parent is a response, we can use the operation name and append "Response"
|
|
111
|
+
else if (parent instanceof Res) {
|
|
112
|
+
const op = parent.parent;
|
|
113
|
+
name = op.getGqlOpName() + 'Response';
|
|
114
|
+
}
|
|
115
|
+
// for posts
|
|
116
|
+
else if (parent instanceof Body) {
|
|
117
|
+
// const op = parent.parent as Post;
|
|
118
|
+
name = this.name + 'Input';
|
|
119
|
+
}
|
|
120
|
+
// if the parent is an object then we can use the parent name
|
|
121
|
+
else if (parent instanceof Obj) {
|
|
122
|
+
name = parentName + 'Obj';
|
|
123
|
+
}
|
|
124
|
+
// extreme case -- we synthesize an anonymous name
|
|
125
|
+
else {
|
|
126
|
+
name = `[inline:${this.parent.name}]`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
this.name = name;
|
|
130
|
+
}
|
|
140
131
|
}
|
|
141
132
|
//# sourceMappingURL=obj.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"obj.js","sourceRoot":"","sources":["../../../src/oas/nodes/obj.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAe,IAAI,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,CAAc,MAAM,QAAQ,CAAC;AAEpC,MAAM,OAAO,GAAI,SAAQ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AED,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QAE/G,KAAK,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,IAAI,MAAM,EAAE,CAAC;YACxC,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;YAC/D,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAEhC,2CAA2C;YAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;gBAClC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC;QACH,CAAC;QAED,+DAA+D;QAC/D,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACpC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAClC,IAAI,IAAI;oBAAE,IAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;YAClC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,iBAAiB,EAAE,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;CACF","sourcesContent":["import { Body, IType, Post, Type } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\nimport { Arr } from './arr.js';\nimport { Factory } from './factory.js';\nimport { Get } from './get.js';\nimport { PropArray } from './propArray.js';\nimport { Ref } from './ref.js';\nimport { Response } from './response.js';\nimport _, { isArray } from 'lodash';\n\nexport class Obj extends Type {\n synthetic: boolean = false;\n\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: SchemaObject,\n ) {\n super(parent, name);\n this.updateName();\n }\n\n public forPrompt(_context: OasContext): string {\n return `${Naming.getRefName(this.name)} (Obj)`;\n }\n\n get id(): string {\n return `obj:${this.kind}:${this.name}`;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n trace(context, '-> [obj:visit]', 'in ' + this.name);\n\n if (!context.inContextOf('Composed', this)) {\n trace(context, '[obj]', 'In object: ' + (this.name ? this.name : this.parent?.name));\n }\n\n this.visitProperties(context);\n this.visited = true;\n\n if (this.name) {\n context.store(this.name, this);\n }\n\n trace(context, '<- [obj:visit]', 'out ' + this.name);\n context.leave(this);\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n if (_.isEmpty(this.props)) {\n return;\n }\n\n if (context.inContextOf('Response', this)) {\n writer.append(Naming.genTypeName(this.name));\n return;\n }\n\n context.enter(this);\n trace(context, '-> [obj::generate]', `-> in: ${this.name}`);\n\n const sanitised = Naming.genTypeName(this.name);\n const refName = Naming.getRefName(this.name);\n\n writer\n .append(this.kind + ' ')\n .append(sanitised === refName ? refName : sanitised)\n .append(this.nameSuffix())\n .append(' {\\n');\n\n const selected = this.selectedProps(selection);\n\n for (const prop of selected) {\n trace(context, '-> [obj::generate]', `-> property: ${prop.name} (parent: ${prop.parent!.name})`);\n prop.generate(context, writer, selection);\n }\n\n writer.append('}\\n\\n');\n\n trace(context, '<- [obj::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [obj::select]', `-> in: ${this.name}`);\n\n const selected = this.selectedProps(selection);\n for (const prop of selected) {\n prop.select(context, writer, selection);\n }\n\n trace(context, '<- [obj::select]', `-> out: ${this.name}`);\n }\n\n private updateName(): void {\n let name = this.name;\n // If we are an inline object named \"items\", try to create a better name.\n if (!name || name === 'items') {\n const parent = this.parent;\n const parentName = parent!.name;\n\n // if the parent is a reference, we can use the name of the obj itself\n if (parent instanceof Ref) {\n name = parentName.replace('ref:', 'obj:');\n }\n // else is our parent an array?\n else if (parent instanceof Arr || parent instanceof PropArray) {\n // if so, synthesize a name based on the parent name\n name = Naming.genTypeName(Naming.getRefName(parentName) + 'Item');\n }\n // if the parent is a response, we can use the operation name and append \"Response\"\n else if (parent instanceof Response) {\n const op = parent.parent as Get;\n name = op.getGqlOpName() + 'Response';\n } else if (parent instanceof Body) {\n // const op = parent.parent as Post;\n name = this.name + 'Input';\n }\n // if the parent is an object then we can use the parent name\n else if (parent instanceof Obj) {\n name = parentName + 'Obj';\n }\n // extreme case -- we synthesize an anonymous name\n else {\n name = `[anonymous:${this.parent!.name}]`;\n }\n }\n\n this.name = name;\n }\n\n private visitProperties(context: OasContext): void {\n if (!this.schema.properties) {\n return;\n }\n\n const properties = this.schema.properties as Record<string, SchemaObject>;\n const propKeys = Object.keys(properties);\n trace(context, '-> [obj::props]', 'in props ' + (propKeys.length === 0 ? '0' : propKeys.length.toString()));\n\n if (propKeys.length === 0) {\n trace(context, '<- [obj::props]', 'no props ' + this.props.size);\n return;\n }\n\n const sorted = Object.entries(properties).sort((a, b) => a[0].toLowerCase().localeCompare(b[0].toLowerCase()));\n\n for (const [key, schemaValue] of sorted) {\n const prop = Factory.fromProp(context, this, key, schemaValue);\n this.props.set(prop.name, prop);\n\n // TODO: we should not be adding this twice\n if (!this.children.includes(prop)) {\n this.add(prop);\n }\n }\n\n // required can also be set in a separate array too, apparently\n if (_.isArray(this.schema.required)) {\n this.schema.required.forEach((name) => {\n const prop = this.props.get(name);\n if (prop) prop!.required = true;\n });\n }\n\n trace(context, '<- [obj::props]', 'out props ' + this.props.size);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"obj.js","sourceRoot":"","sources":["../../../src/oas/nodes/obj.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAc,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAErF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,MAAM,OAAO,GAAI,SAAQ,IAAI;IAMlB;IALT,SAAS,GAAY,KAAK,CAAC;IAE3B,YACE,MAAyB,EACzB,IAAY,EACL,MAAoB;QAE3B,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAFb,WAAM,GAAN,MAAM,CAAc;QAG3B,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAEM,SAAS,CAAC,QAAoB;QACnC,OAAO,YAAY,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IACpD,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,OAAO,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;IACzC,CAAC;IAEM,KAAK,CAAC,OAAmB;QAC9B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpD,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC;YAC3C,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,aAAa,GAAG,CAAC,IAAI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B,CAAC;YACD,kDAAkD;iBAC7C,CAAC;gBACJ,IAAI,GAAG,WAAW,IAAI,CAAC,MAAO,CAAC,IAAI,GAAG,CAAC;YACzC,CAAC;QACH,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { Arr, Body, Factory, Get, IType, PropArray, Type, Res } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nimport _ from 'lodash';\n\nexport class Obj extends Type {\n synthetic: boolean = false;\n\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: SchemaObject,\n ) {\n super(parent, name);\n this.updateName();\n }\n\n public forPrompt(_context: OasContext): string {\n return `[object] ${Naming.getRefName(this.name)}`;\n }\n\n get id(): string {\n return `obj:${this.kind}:${this.name}`;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n trace(context, '-> [obj:visit]', 'in ' + this.name);\n\n if (!context.inContextOf('Composed', this)) {\n trace(context, '[obj]', 'In object: ' + (this.name ? this.name : this.parent?.name));\n }\n\n this.visitProperties(context);\n this.visited = true;\n\n if (this.name) {\n context.store(this.name, this);\n }\n\n trace(context, '<- [obj:visit]', 'out ' + this.name);\n context.leave(this);\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n if (_.isEmpty(this.props)) {\n return;\n }\n\n if (context.inContextOf('Res', this)) {\n writer.append(Naming.genTypeName(this.name));\n return;\n }\n\n context.enter(this);\n trace(context, '-> [obj::generate]', `-> in: ${this.name}`);\n\n const sanitised = Naming.genTypeName(this.name);\n const refName = Naming.getRefName(this.name);\n\n writer\n .append(this.kind + ' ')\n .append(sanitised === refName ? refName : sanitised)\n .append(this.nameSuffix())\n .append(' {\\n');\n\n const selected = this.selectedProps(selection);\n\n for (const prop of selected) {\n trace(context, '-> [obj::generate]', `-> property: ${prop.name} (parent: ${prop.parent!.name})`);\n prop.generate(context, writer, selection);\n }\n\n writer.append('}\\n\\n');\n\n trace(context, '<- [obj::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [obj::select]', `-> in: ${this.name}`);\n\n const selected = this.selectedProps(selection);\n for (const prop of selected) {\n prop.select(context, writer, selection);\n }\n\n trace(context, '<- [obj::select]', `-> out: ${this.name}`);\n }\n\n private visitProperties(context: OasContext): void {\n if (!this.schema.properties) {\n return;\n }\n\n const properties = this.schema.properties as Record<string, SchemaObject>;\n const propKeys = Object.keys(properties);\n trace(context, '-> [obj::props]', 'in props ' + (propKeys.length === 0 ? '0' : propKeys.length.toString()));\n\n if (propKeys.length === 0) {\n trace(context, '<- [obj::props]', 'no props ' + this.props.size);\n return;\n }\n\n const sorted = Object.entries(properties).sort((a, b) => a[0].toLowerCase().localeCompare(b[0].toLowerCase()));\n\n for (const [key, schemaValue] of sorted) {\n const prop = Factory.fromProp(context, this, key, schemaValue);\n this.props.set(prop.name, prop);\n\n if (!this.children.includes(prop)) {\n this.add(prop);\n }\n }\n\n // required can also be set in a separate array too, apparently\n if (_.isArray(this.schema.required)) {\n this.schema.required.forEach((name) => {\n const prop = this.props.get(name);\n if (prop) prop!.required = true;\n });\n }\n\n trace(context, '<- [obj::props]', 'out props ' + this.props.size);\n }\n\n private updateName(): void {\n let name = this.name;\n // If we are an inline object named \"items\", try to create a better name.\n if (!name || name === 'items') {\n const parent = this.parent;\n const parentName = parent!.name;\n\n // is our parent an array?\n if (parent instanceof Arr || parent instanceof PropArray) {\n // if so, synthesize a name based on the parent name\n name = Naming.genTypeName(Naming.getRefName(parentName) + 'Item');\n }\n // if the parent is a response, we can use the operation name and append \"Response\"\n else if (parent instanceof Res) {\n const op = parent.parent as Get;\n name = op.getGqlOpName() + 'Response';\n }\n // for posts\n else if (parent instanceof Body) {\n // const op = parent.parent as Post;\n name = this.name + 'Input';\n }\n // if the parent is an object then we can use the parent name\n else if (parent instanceof Obj) {\n name = parentName + 'Obj';\n }\n // extreme case -- we synthesize an anonymous name\n else {\n name = `[inline:${this.parent!.name}]`;\n }\n }\n\n this.name = name;\n }\n}\n"]}
|
package/dist/oas/nodes/param.js
CHANGED
|
@@ -20,7 +20,9 @@ export class Param extends Type {
|
|
|
20
20
|
}
|
|
21
21
|
context.enter(this);
|
|
22
22
|
trace(context, '-> [param:visit]', 'in: ' + this.name);
|
|
23
|
-
|
|
23
|
+
const type = Factory.fromSchema(context, this, this.schema);
|
|
24
|
+
this.add(type);
|
|
25
|
+
this.resultType = type;
|
|
24
26
|
trace(context, ' [param:visit]', 'type: ' + this.resultType);
|
|
25
27
|
this.resultType.visit(context);
|
|
26
28
|
trace(context, '<- [param:visit]', 'out: ' + this.name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"param.js","sourceRoot":"","sources":["../../../src/oas/nodes/param.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,KAAM,SAAQ,IAAI;IAMpB;IACA;IACA;IACA;IARF,UAAU,CAAS;IAE1B,YACE,MAAa,EACb,IAAY,EACL,MAAoB,EACpB,QAAiB,EACjB,YAAqB,EACrB,SAA0B;QAEjC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QALb,WAAM,GAAN,MAAM,CAAc;QACpB,aAAQ,GAAR,QAAQ,CAAS;QACjB,iBAAY,GAAZ,YAAY,CAAS;QACrB,cAAS,GAAT,SAAS,CAAiB;IAGnC,CAAC;IAEM,KAAK,CAAC,OAAmB;QAC9B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QAED,OAAO,CAAC,KAA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AE,MAAc,EAAE,SAAmB;QACpE,aAAa;IACf,CAAC;IAEO,iBAAiB,CAAC,MAAc;QACtC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpB,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC;QAEhC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjC,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAClB,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAC5B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { Factory, IType, Type } from './internal.js';\nimport { ParameterObject, SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class Param extends Type {\n public resultType!: IType;\n\n constructor(\n parent: IType,\n name: string,\n public schema: SchemaObject,\n public required: boolean,\n public defaultValue: unknown,\n public parameter: ParameterObject,\n ) {\n super(parent, name);\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n trace(context, '-> [param:visit]', 'in: ' + this.name);\n\n const type = Factory.fromSchema(context, this, this.schema);\n this.add(type);\n\n this.resultType = type;\n trace(context, ' [param:visit]', 'type: ' + this.resultType);\n this.resultType.visit(context);\n\n trace(context, '<- [param:visit]', 'out: ' + this.name);\n context.leave(this);\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n context.enter(this);\n trace(context, '-> [param::generate]', `-> in: ${this.name}`);\n\n writer.write(Naming.genParamName(this.name));\n writer.write(': ');\n\n this.resultType.generate(context, writer, selection);\n\n if (this.required) {\n writer.write('!');\n }\n\n if (this.defaultValue !== null && this.defaultValue !== undefined) {\n this.writeDefaultValue(writer);\n }\n\n trace(context, '<- [param::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public forPrompt(context: OasContext): string {\n return `Param{ name=${this.name}, required=${this.required}, defaultValue=${this.defaultValue}, props=${this.props}, resultType=${this.resultType} }`;\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n // do nothing\n }\n\n private writeDefaultValue(writer: Writer): void {\n writer.write(' = ');\n const value = this.defaultValue;\n\n if (typeof value === 'number') {\n writer.write(value.toString());\n } else if (typeof value === 'string') {\n writer.write('\"');\n writer.write(String(value));\n writer.write('\"');\n }\n }\n}\n"]}
|
package/dist/oas/nodes/prop.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export declare abstract class Prop extends Type {
|
|
|
8
8
|
constructor(parent: IType | undefined, name: string, schema: SchemaObject);
|
|
9
9
|
generate(context: OasContext, writer: Writer, _selection: string[]): void;
|
|
10
10
|
abstract getValue(context: OasContext): string;
|
|
11
|
-
|
|
11
|
+
generateValue(context: OasContext, writer: Writer): void;
|
|
12
12
|
}
|
package/dist/oas/nodes/prop.js
CHANGED
|
@@ -10,7 +10,10 @@ export class Prop extends Type {
|
|
|
10
10
|
generate(context, writer, _selection) {
|
|
11
11
|
const description = this.schema.description;
|
|
12
12
|
if (description != null) {
|
|
13
|
-
if (description.includes('\n') ||
|
|
13
|
+
if (description.includes('\n') ||
|
|
14
|
+
description.includes('\r') ||
|
|
15
|
+
description.includes('"') ||
|
|
16
|
+
description.includes('\\')) {
|
|
14
17
|
writer.append(' """\n').append(' ').append(description).append('\n """\n');
|
|
15
18
|
}
|
|
16
19
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prop.js","sourceRoot":"","sources":["../../../src/oas/nodes/prop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CAAC;AAI5C,OAAO,EA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AAC,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAChF,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEzE,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAEpC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAID,aAAa,CAAC,OAAmB,EAAE,MAAc;QAC/C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import { IType, Type } from './internal.js';\nimport { SchemaObject } from 'oas/types';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport abstract class Prop extends Type {\n public required: boolean = false;\n\n constructor(\n parent: IType | undefined,\n name: string,\n public schema: SchemaObject,\n ) {\n super(parent, name);\n }\n\n public generate(context: OasContext, writer: Writer, _selection: string[]): void {\n const description = this.schema.description;\n if (description != null) {\n if (\n description.includes('\\n') ||\n description.includes('\\r') ||\n description.includes('\"') ||\n description.includes('\\\\')\n ) {\n writer.append(' \"\"\"\\n').append(' ').append(description).append('\\n \"\"\"\\n');\n } else {\n writer.append(' \"').append(description).append('\"\\n');\n }\n }\n\n writer.append(' ').append(Naming.sanitiseField(this.name)).append(': ');\n\n this.generateValue(context, writer);\n\n if (this.required) {\n writer.append('!');\n }\n\n writer.append('\\n');\n }\n\n public abstract getValue(context: OasContext): string;\n\n generateValue(context: OasContext, writer: Writer): void {\n writer.append(this.getValue(context));\n }\n}\n"]}
|
|
@@ -2,12 +2,11 @@ import { IType, Prop } from './internal.js';
|
|
|
2
2
|
import { OasContext } from '../oasContext.js';
|
|
3
3
|
import { Writer } from '../io/writer.js';
|
|
4
4
|
export declare class PropArray extends Prop {
|
|
5
|
-
items?:
|
|
5
|
+
items?: IType;
|
|
6
6
|
get id(): string;
|
|
7
7
|
visit(context: OasContext): void;
|
|
8
|
-
setItems(items:
|
|
8
|
+
setItems(items: IType): void;
|
|
9
9
|
getValue(context: OasContext): string;
|
|
10
|
-
add(child: IType): void;
|
|
11
10
|
forPrompt(context: OasContext): string;
|
|
12
11
|
select(context: OasContext, writer: Writer, selection: string[]): void;
|
|
13
12
|
needsBrackets(child?: IType): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Prop, T } from './internal.js';
|
|
2
2
|
import { trace } from '../log/trace.js';
|
|
3
3
|
import { Naming } from '../utils/naming.js';
|
|
4
4
|
export class PropArray extends Prop {
|
|
@@ -25,24 +25,17 @@ export class PropArray extends Prop {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
getValue(context) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const paths = this.ancestors();
|
|
32
|
-
const contains = paths.map((p) => p.id).includes(child.id);
|
|
33
|
-
trace(null, '-> [prop-array:add]', 'contains child? ' + contains);
|
|
34
|
-
if (contains) {
|
|
35
|
-
const ancestor = paths[paths.map((p) => p.id).indexOf(child.id)];
|
|
36
|
-
const wrapper = Factory.fromCircularRef(this, ancestor);
|
|
37
|
-
super.add(wrapper);
|
|
38
|
-
this.visited = true;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
super.add(child);
|
|
28
|
+
if (this.items && T.isContainer(this.items)) {
|
|
29
|
+
const type = Naming.genTypeName(this.items.name) + this.items.nameSuffix();
|
|
30
|
+
return `[${type}]`;
|
|
42
31
|
}
|
|
32
|
+
return `[${this.items.name}]`;
|
|
43
33
|
}
|
|
44
34
|
forPrompt(context) {
|
|
45
|
-
|
|
35
|
+
if (this.items && T.isContainer(this.items)) {
|
|
36
|
+
return `[prop] ${this.name}: [${Naming.genTypeName(this.items?.name)}] (Array)`;
|
|
37
|
+
}
|
|
38
|
+
return `[prop] ${this.name}: [${this.items.name}] (Array)`;
|
|
46
39
|
}
|
|
47
40
|
select(context, writer, selection) {
|
|
48
41
|
trace(context, '-> [prop-array:select]', 'in: ' + this.name);
|
|
@@ -56,7 +49,8 @@ export class PropArray extends Prop {
|
|
|
56
49
|
}
|
|
57
50
|
// Select each child of the items Prop.
|
|
58
51
|
if (this.needsBrackets(this.items)) {
|
|
59
|
-
|
|
52
|
+
const selected = Array.from(this.items.children.values()).filter((prop) => selection.find((s) => s.startsWith(prop.path())));
|
|
53
|
+
for (const child of selected) {
|
|
60
54
|
child.select(context, writer, selection);
|
|
61
55
|
}
|
|
62
56
|
}
|
|
@@ -65,7 +59,7 @@ export class PropArray extends Prop {
|
|
|
65
59
|
writer.append(' '.repeat(context.indent + context.stack.length)).append('}');
|
|
66
60
|
}
|
|
67
61
|
// writer.append('\n');
|
|
68
|
-
if (context.generateOptions.
|
|
62
|
+
if (context.generateOptions.showParentInSelections) {
|
|
69
63
|
writer.append(' # ').append(Naming.getRefName(this.parent.name));
|
|
70
64
|
}
|
|
71
65
|
writer.append('\n');
|
|
@@ -74,7 +68,7 @@ export class PropArray extends Prop {
|
|
|
74
68
|
needsBrackets(child) {
|
|
75
69
|
if (!child)
|
|
76
70
|
return false;
|
|
77
|
-
return child
|
|
71
|
+
return T.isContainer(child);
|
|
78
72
|
}
|
|
79
73
|
}
|
|
80
74
|
//# sourceMappingURL=propArray.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propArray.js","sourceRoot":"","sources":["../../../src/oas/nodes/propArray.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"propArray.js","sourceRoot":"","sources":["../../../src/oas/nodes/propArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,IAAI,EAAE,CAAC,EAAQ,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,SAAU,SAAQ,IAAI;IAC1B,KAAK,CAAS;IAErB,IAAI,EAAE;QACJ,OAAO,eAAe,IAAI,CAAC,IAAI,EAAE,CAAC;IACpC,CAAC;IAEe,KAAK,CAAC,OAAmB;QACvC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,IAAI,CAAC,CAAC;QAE9C,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/D,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAEpB,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAEM,QAAQ,CAAC,KAAY;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAEe,QAAQ,CAAC,OAAmB;QAC1C,IAAI,I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AEM,aAAa,CAAC,KAAa;QAChC,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QACzB,OAAO,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { IType, Prop, T, Type } from './internal.js';\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class PropArray extends Prop {\n public items?: IType;\n\n get id(): string {\n return `prop:array:#${this.name}`;\n }\n\n public override visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n trace(context, '-> [prop-array:visit]', 'in');\n\n trace(context, ' [prop-array:visit]', 'type: ' + this.items);\n this.items?.visit(context);\n this.visited = true;\n\n trace(context, '<- [prop:array:visit]', 'out');\n context.leave(this);\n }\n\n public setItems(items: IType): void {\n this.items = items;\n if (!this.children.includes(items)) {\n this.add(items);\n }\n }\n\n public override getValue(context: OasContext): string {\n if (this.items && T.isContainer(this.items)) {\n const type = Naming.genTypeName(this.items.name) + (this.items as Type).nameSuffix();\n return `[${type}]`;\n }\n\n return `[${this.items!.name}]`;\n }\n\n public forPrompt(context: OasContext): string {\n if (this.items && T.isContainer(this.items)) {\n return `[prop] ${this.name}: [${Naming.genTypeName(this.items?.name)}] (Array)`;\n }\n\n return `[prop] ${this.name}: [${this.items!.name}] (Array)`;\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [prop-array:select]', 'in: ' + this.name);\n\n const fieldName = this.name;\n const sanitised = Naming.sanitiseFieldForSelect(fieldName);\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n if (this.needsBrackets(this.items!)) {\n writer.append(' {');\n writer.append('\\n');\n context.enter(this);\n }\n\n // Select each child of the items Prop.\n if (this.needsBrackets(this.items)) {\n const selected = Array.from(this.items!.children.values()).filter((prop) =>\n selection.find((s) => s.startsWith(prop.path())),\n );\n\n for (const child of selected) {\n child.select(context, writer, selection);\n }\n }\n\n if (this.needsBrackets(this.items!)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n }\n // writer.append('\\n');\n if (context.generateOptions.showParentInSelections) {\n writer.append(' # ').append(Naming.getRefName(this.parent!.name));\n }\n\n writer.append('\\n');\n\n trace(context, '<- [prop:array:select]', 'out');\n }\n\n public needsBrackets(child?: IType): boolean {\n if (!child) return false;\n return T.isContainer(child);\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OasContext } from '../oasContext.js';
|
|
2
|
+
import { IType, Prop } from './internal.js';
|
|
3
|
+
import { Writer } from '../io/writer.js';
|
|
4
|
+
export declare class PropCircRef extends Prop {
|
|
5
|
+
private ref;
|
|
6
|
+
constructor(parent: IType, child: Prop);
|
|
7
|
+
get id(): string;
|
|
8
|
+
add(child: IType): IType;
|
|
9
|
+
visit(context: OasContext): void;
|
|
10
|
+
getValue(_context: OasContext): string;
|
|
11
|
+
forPrompt(context: OasContext): string;
|
|
12
|
+
generateValue(context: OasContext, writer: Writer): void;
|
|
13
|
+
select(context: OasContext, writer: Writer, selection: string[]): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Prop } from './internal.js';
|
|
2
|
+
export class PropCircRef extends Prop {
|
|
3
|
+
ref;
|
|
4
|
+
constructor(parent, child) {
|
|
5
|
+
super(parent, child.name, child.schema);
|
|
6
|
+
this.ref = child;
|
|
7
|
+
}
|
|
8
|
+
get id() {
|
|
9
|
+
return `prop:circular-ref:#${this.name}`;
|
|
10
|
+
}
|
|
11
|
+
add(child) {
|
|
12
|
+
// do nothing
|
|
13
|
+
return child;
|
|
14
|
+
}
|
|
15
|
+
visit(context) {
|
|
16
|
+
// do nothing
|
|
17
|
+
}
|
|
18
|
+
getValue(_context) {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
forPrompt(context) {
|
|
22
|
+
return `[prop] ${this.name}: Circular reference to: ${this.ref.forPrompt(context)} `;
|
|
23
|
+
}
|
|
24
|
+
generateValue(context, writer) {
|
|
25
|
+
writer.append('# ');
|
|
26
|
+
this.ref.generateValue(context, writer);
|
|
27
|
+
writer.append(`# Circular reference detected! Please re-visit the schema and remove the reference.\n`);
|
|
28
|
+
}
|
|
29
|
+
select(context, writer, selection) {
|
|
30
|
+
// do nothing
|
|
31
|
+
writer.append('# ');
|
|
32
|
+
this.ref.select(context, writer, selection);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=propCircRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propCircRef.js","sourceRoot":"","sources":["../../../src/oas/nodes/propCircRef.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,OAAO,WAAY,SAAQ,IAAI;IAC3B,GAAG,CAAO;IAElB,YAAY,MAAa,EAAE,KAAW;QACpC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QACxC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC;IACnB,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,sBAAsB,IAAI,CAAC,IAAI,EAAE,CAAC;IAC3C,CAAC;IAEe,GAAG,CAAC,KAAY;QAC9B,aAAa;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,OAAmB;QAC9B,aAAa;IACf,CAAC;IAEM,QAAQ,CAAC,QAAoB;QAClC,OAAO,EAAE,CAAC;IACZ,CAAC;IAEM,SAAS,CAAC,OAAmB;QAClC,OAAO,UAAU,IAAI,CAAC,IAAI,4BAA4B,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC;IACvF,CAAC;IAED,aAAa,CAAC,OAAmB,EAAE,MAAc;QAC/C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,MAAM,CAAC,uFAAuF,CAAC,CAAC;IACzG,CAAC;IAEM,MAAM,CAAC,OAAmB,EAAE,MAAc,EAAE,SAAmB;QACpE,aAAa;QACb,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAC9C,CAAC;CACF","sourcesContent":["import { OasContext } from '../oasContext.js';\nimport { IType, Prop } from './internal.js';\nimport { Writer } from '../io/writer.js';\n\nexport class PropCircRef extends Prop {\n private ref: Prop;\n\n constructor(parent: IType, child: Prop) {\n super(parent, child.name, child.schema);\n this.ref = child;\n }\n\n get id(): string {\n return `prop:circular-ref:#${this.name}`;\n }\n\n public override add(child: IType): IType {\n // do nothing\n return child;\n }\n\n public visit(context: OasContext): void {\n // do nothing\n }\n\n public getValue(_context: OasContext): string {\n return '';\n }\n\n public forPrompt(context: OasContext): string {\n return `[prop] ${this.name}: Circular reference to: ${this.ref.forPrompt(context)} `;\n }\n\n generateValue(context: OasContext, writer: Writer) {\n writer.append('# ');\n this.ref.generateValue(context, writer);\n writer.append(`# Circular reference detected! Please re-visit the schema and remove the reference.\\n`);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n // do nothing\n writer.append('# ');\n this.ref.select(context, writer, selection);\n }\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Obj, Union } from './internal.js';
|
|
2
|
-
import { Prop } from './prop.js';
|
|
1
|
+
import { Obj, Union, Prop } from './internal.js';
|
|
3
2
|
import _ from 'lodash';
|
|
4
3
|
import { trace } from '../log/trace.js';
|
|
5
4
|
import { Composed } from './comp.js';
|
|
@@ -12,8 +11,8 @@ export class PropComp extends Prop {
|
|
|
12
11
|
this.schema = schema;
|
|
13
12
|
}
|
|
14
13
|
forPrompt(_context) {
|
|
15
|
-
const type = this.schema.oneOf ? '
|
|
16
|
-
return _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.comp.name) + ` (${type})`;
|
|
14
|
+
const type = this.schema.oneOf ? 'Union' : this.schema.allOf ? 'Composed' : 'Unknown';
|
|
15
|
+
return '[prop] ' + _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.comp.name) + ` (${type})`;
|
|
17
16
|
}
|
|
18
17
|
get id() {
|
|
19
18
|
return 'prop:comp:' + this.name;
|
|
@@ -34,12 +33,6 @@ export class PropComp extends Prop {
|
|
|
34
33
|
context.leave(this);
|
|
35
34
|
}
|
|
36
35
|
getValue(_context) {
|
|
37
|
-
// we'll make an assumption here: that if the child obj has no properties,
|
|
38
|
-
// then it's a free-form JSON payload. not sure if the right one, but it will
|
|
39
|
-
// compose for now.
|
|
40
|
-
if (_.isEmpty(this.comp?.props))
|
|
41
|
-
return 'JSON';
|
|
42
|
-
// return Naming.genTypeName(this.name);
|
|
43
36
|
return Naming.genTypeName(this.comp.name) + this.comp.nameSuffix();
|
|
44
37
|
}
|
|
45
38
|
select(context, writer, selection) {
|
|
@@ -60,14 +53,14 @@ export class PropComp extends Prop {
|
|
|
60
53
|
writer.append(' '.repeat(context.indent + context.stack.length)).append('}');
|
|
61
54
|
}
|
|
62
55
|
// writer.append('\n');
|
|
63
|
-
if (context.generateOptions.
|
|
56
|
+
if (context.generateOptions.showParentInSelections) {
|
|
64
57
|
writer.append(' # ').append(Naming.getRefName(this.parent.name));
|
|
65
58
|
}
|
|
66
59
|
writer.append('\n');
|
|
67
60
|
trace(context, '<- [prop-comp:select]', 'out ' + this.name + ', obj: ' + comp?.name);
|
|
68
61
|
}
|
|
69
62
|
needsBrackets(child) {
|
|
70
|
-
return
|
|
63
|
+
return child instanceof Union || child instanceof Composed || (child instanceof Obj && !_.isEmpty(child.props));
|
|
71
64
|
}
|
|
72
65
|
}
|
|
73
66
|
//# sourceMappingURL=propComp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propComp.js","sourceRoot":"","sources":["../../../src/oas/nodes/propComp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"propComp.js","sourceRoot":"","sources":["../../../src/oas/nodes/propComp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,QAAS,SAAQ,IAAI;IAMvB;IALF,IAAI,CAAS;IAEpB,YACE,MAAa,EACb,IAAY,EACL,MAAoB;QAE3B,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAFrB,WAAM,GAAN,MAAM,CAAc;IAG7B,CAAC;IAEM,SAAS,CAAC,QAAoB;QACnC,MAAM,IAAI,GAAW,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9F,OAAO,SAAS,GAAG,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAK,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,GAAG,CAAC;IACxG,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC;IAClC,CAAC;IAEM,KAAK,CAAC,OAAmB;QAC9B,IAAI,IAAI,CAAC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AAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAClH,CAAC;CACF","sourcesContent":["import { IType, Obj, Union, Prop } from './internal.js';\nimport _ from 'lodash';\nimport { SchemaObject } from 'oas/types';\nimport { trace } from '../log/trace.js';\nimport { Composed } from './comp.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class PropComp extends Prop {\n public comp?: IType;\n\n constructor(\n parent: IType,\n name: string,\n public schema: SchemaObject,\n ) {\n super(parent, name, schema);\n }\n\n public forPrompt(_context: OasContext): string {\n const type: string = this.schema.oneOf ? 'Union' : this.schema.allOf ? 'Composed' : 'Unknown';\n return '[prop] ' + _.lowerFirst(this.name) + ': ' + Naming.getRefName(this.comp!.name) + ` (${type})`;\n }\n\n get id(): string {\n return 'prop:comp:' + this.name;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n const comp = this.comp!;\n trace(context, '-> [prop-comp:visit]', 'in ' + this.name + ', obj: ' + comp.name);\n\n comp.visit(context);\n if (!this.children.includes(comp)) {\n this.add(comp);\n }\n this.visited = true;\n\n trace(context, '<- [prop-comp:visit]', 'out ' + this.name + ', obj: ' + comp.name);\n context.leave(this);\n }\n\n public getValue(_context: OasContext): string {\n return Naming.genTypeName(this.comp!.name!) + (this.comp as Composed).nameSuffix();\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n const comp = this.comp!;\n trace(context, '-> [prop-comp:select]', 'in ' + this.name + ', obj: ' + comp.name);\n\n const fieldName = this.name;\n const sanitised = Naming.sanitiseFieldForSelect(fieldName);\n\n writer.append(' '.repeat(context.indent + context.stack.length)).append(sanitised);\n\n if (this.needsBrackets(comp)) {\n writer.append(' {').append('\\n');\n context.enter(this);\n }\n\n for (const child of this.children) {\n child.select(context, writer, selection);\n }\n\n if (this.needsBrackets(comp)) {\n context.leave(this);\n writer.append(' '.repeat(context.indent + context.stack.length)).append('}');\n }\n // writer.append('\\n');\n if (context.generateOptions.showParentInSelections) {\n writer.append(' # ').append(Naming.getRefName(this.parent!.name));\n }\n\n writer.append('\\n');\n\n trace(context, '<- [prop-comp:select]', 'out ' + this.name + ', obj: ' + comp?.name);\n }\n\n private needsBrackets(child: IType): boolean {\n return child instanceof Union || child instanceof Composed || (child instanceof Obj && !_.isEmpty(child.props));\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SchemaObject } from 'oas/types';
|
|
2
|
+
import { IType, Prop } from './internal.js';
|
|
3
|
+
import { Writer } from '../io/writer.js';
|
|
4
|
+
import { OasContext } from '../oasContext.js';
|
|
5
|
+
export declare class PropEn extends Prop {
|
|
6
|
+
private type;
|
|
7
|
+
constructor(parent: IType, name: string, type: string, schema: SchemaObject);
|
|
8
|
+
get id(): string;
|
|
9
|
+
generate(context: OasContext, writer: Writer, _selection: string[]): void;
|
|
10
|
+
visit(context: OasContext): void;
|
|
11
|
+
forPrompt(context: OasContext): string;
|
|
12
|
+
getValue(_context: OasContext): string;
|
|
13
|
+
dependencies(): IType[];
|
|
14
|
+
select(context: OasContext, writer: Writer, selection: string[]): void;
|
|
15
|
+
}
|