apollo-conn-gen 0.2.1 → 0.3.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.
Files changed (86) hide show
  1. package/dist/cli/oas-helpers/index.js +5 -5
  2. package/dist/cli/oas-helpers/index.js.map +1 -1
  3. package/dist/cli/oas.js +5 -0
  4. package/dist/cli/oas.js.map +1 -1
  5. package/dist/oas/index.d.ts +2 -2
  6. package/dist/oas/index.js +2 -2
  7. package/dist/oas/index.js.map +1 -1
  8. package/dist/oas/io/writer.d.ts +1 -2
  9. package/dist/oas/io/writer.js +14 -17
  10. package/dist/oas/io/writer.js.map +1 -1
  11. package/dist/oas/nodes/arr.js +1 -1
  12. package/dist/oas/nodes/arr.js.map +1 -1
  13. package/dist/oas/nodes/body.js +3 -1
  14. package/dist/oas/nodes/body.js.map +1 -1
  15. package/dist/oas/nodes/circularRef.d.ts +1 -1
  16. package/dist/oas/nodes/circularRef.js.map +1 -1
  17. package/dist/oas/nodes/comp.d.ts +2 -0
  18. package/dist/oas/nodes/comp.js +44 -7
  19. package/dist/oas/nodes/comp.js.map +1 -1
  20. package/dist/oas/nodes/en.d.ts +1 -1
  21. package/dist/oas/nodes/en.js +3 -3
  22. package/dist/oas/nodes/en.js.map +1 -1
  23. package/dist/oas/nodes/factory.d.ts +6 -3
  24. package/dist/oas/nodes/factory.js +149 -105
  25. package/dist/oas/nodes/factory.js.map +1 -1
  26. package/dist/oas/nodes/iType.d.ts +2 -2
  27. package/dist/oas/nodes/iType.js.map +1 -1
  28. package/dist/oas/nodes/internal.d.ts +3 -3
  29. package/dist/oas/nodes/internal.js +3 -3
  30. package/dist/oas/nodes/internal.js.map +1 -1
  31. package/dist/oas/nodes/obj.d.ts +1 -1
  32. package/dist/oas/nodes/obj.js +35 -44
  33. package/dist/oas/nodes/obj.js.map +1 -1
  34. package/dist/oas/nodes/param.js +3 -1
  35. package/dist/oas/nodes/param.js.map +1 -1
  36. package/dist/oas/nodes/prop.d.ts +1 -1
  37. package/dist/oas/nodes/prop.js +4 -1
  38. package/dist/oas/nodes/prop.js.map +1 -1
  39. package/dist/oas/nodes/propArray.d.ts +2 -3
  40. package/dist/oas/nodes/propArray.js +12 -18
  41. package/dist/oas/nodes/propArray.js.map +1 -1
  42. package/dist/oas/nodes/propCircRef.d.ts +14 -0
  43. package/dist/oas/nodes/propCircRef.js +35 -0
  44. package/dist/oas/nodes/propCircRef.js.map +1 -0
  45. package/dist/oas/nodes/propComp.d.ts +1 -2
  46. package/dist/oas/nodes/propComp.js +4 -11
  47. package/dist/oas/nodes/propComp.js.map +1 -1
  48. package/dist/oas/nodes/propEn.d.ts +15 -0
  49. package/dist/oas/nodes/propEn.js +38 -0
  50. package/dist/oas/nodes/propEn.js.map +1 -0
  51. package/dist/oas/nodes/propObj.d.ts +1 -2
  52. package/dist/oas/nodes/propObj.js +3 -4
  53. package/dist/oas/nodes/propObj.js.map +1 -1
  54. package/dist/oas/nodes/propRef.d.ts +5 -4
  55. package/dist/oas/nodes/propRef.js +27 -21
  56. package/dist/oas/nodes/propRef.js.map +1 -1
  57. package/dist/oas/nodes/propScalar.d.ts +2 -3
  58. package/dist/oas/nodes/propScalar.js +10 -6
  59. package/dist/oas/nodes/propScalar.js.map +1 -1
  60. package/dist/oas/nodes/ref.d.ts +3 -0
  61. package/dist/oas/nodes/ref.js +8 -3
  62. package/dist/oas/nodes/ref.js.map +1 -1
  63. package/dist/oas/nodes/{response.d.ts → res.d.ts} +1 -1
  64. package/dist/oas/nodes/{response.js → res.js} +6 -4
  65. package/dist/oas/nodes/res.js.map +1 -0
  66. package/dist/oas/nodes/type.d.ts +2 -3
  67. package/dist/oas/nodes/type.js +3 -18
  68. package/dist/oas/nodes/type.js.map +1 -1
  69. package/dist/oas/nodes/typeUtils.d.ts +3 -0
  70. package/dist/oas/nodes/typeUtils.js +23 -4
  71. package/dist/oas/nodes/typeUtils.js.map +1 -1
  72. package/dist/oas/nodes/union.d.ts +0 -1
  73. package/dist/oas/nodes/union.js +61 -59
  74. package/dist/oas/nodes/union.js.map +1 -1
  75. package/dist/oas/oasContext.js +2 -5
  76. package/dist/oas/oasContext.js.map +1 -1
  77. package/dist/oas/oasGen.d.ts +1 -0
  78. package/dist/oas/oasGen.js +2 -1
  79. package/dist/oas/oasGen.js.map +1 -1
  80. package/dist/oas/prompts/prompt.js +11 -3
  81. package/dist/oas/prompts/prompt.js.map +1 -1
  82. package/dist/tests/runners.js +2 -2
  83. package/dist/tests/runners.js.map +1 -1
  84. package/dist/tsconfig.tsbuildinfo +1 -1
  85. package/package.json +1 -1
  86. package/dist/oas/nodes/response.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"comp.js","sourceRoot":"","sources":["../../../src/oas/nodes/comp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,IAAI,EAAE,GAAG,EAAmB,IAAI,EAAS,MAAM,eAAe,CAAC;AAGxF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,QAAS,SAAQ,IAAI;IAGvB;IACA;IACA;IAJT,YACE,MAAyB,EAClB,IAAY,EACZ,MAAoB,EACpB,eAAwB,KAAK;QAEpC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAJb,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAc;QACpB,iBAAY,GAAZ,YAAY,CAAiB;IAGtC,CAAC;IAED,IAAI,EAAE;QACJ,8BAA8B;QAC9B,OAAO,QAAQ,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;IAC1C,CAAC;IAEM,SAAS,CAAC,QAAoB;QACnC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IAClD,CAAC;IAEM,KAAK,CAAC,OAAmB;QAC9B,IAAI,IAAI,C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IAAI,CAAC,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;QAC5E,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/B,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,SAAS,IAAI,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,YAAY,IAAI,EAAE,CAAC,CAAC;IACtG,CAAC;IAEO,cAAc,CAAC,OAAmB,EAAE,MAAoB;QAC9D,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;QAClC,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,aAAa,IAAI,CAAC,IAAI,eAAe,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QAE9F,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,MAAwB,CAAC,CAAC;QAC1E,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEtB,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,YAAY,IAAI,CAAC,IAAI,UAAU,IAAI,EAAE,CAAC,CAAC;QAC/E,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACjC,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,cAAc,IAAI,CAAC,IAAI,eAAe,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACjG,CAAC;CACF","sourcesContent":["import { Factory, IType, Prop, Ref, ReferenceObject, Type, Union } from './internal.js';\nimport { SchemaObject } from 'oas/types';\n\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 Composed extends Type {\n constructor(\n parent: IType | undefined,\n public name: string,\n public schema: SchemaObject,\n public consolidated: boolean = false,\n ) {\n super(parent, name);\n }\n\n get id(): string {\n // return `comp:${this.name}`;\n return `comp:${this.kind}:${this.name}`;\n }\n\n public forPrompt(_context: OasContext): string {\n return `${Naming.getRefName(this.name)} (Comp)`;\n }\n\n public visit(context: OasContext): void {\n if (this.visited) {\n return;\n }\n\n context.enter(this);\n trace(context, '-> [composed:visit]', 'in: ' + (this.name == null ? '[object]' : this.name));\n\n // If not in the context of a Composed or Param, log the composed schema.\n if (!context.inContextOf('Composed', this) && !context.inContextOf('Param', this)) {\n trace(context, '[comp]', 'In composed schema: ' + this.name);\n }\n\n const composedSchema = this.schema;\n // this will be a type declaration\n if (composedSchema.allOf != null) {\n this.visitAllOfNode(context, composedSchema);\n }\n // represents a Union type\n else if (composedSchema.oneOf != null) {\n throw new Error('Unions should be constructed by its own object');\n // deprecated\n // this.visitOneOfNode(context, composedSchema);\n }\n // can't hand this yet\n else {\n throw new Error('Composed.visit: unsupported composed schema: ' + this.schema);\n }\n\n this.visited = true;\n trace(context, '<- [composed: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, '-> [comp::generate]', `-> in: ${this.name}`);\n\n const composedSchema = this.schema;\n if (composedSchema.oneOf != null) {\n if (this.children.length > 0) {\n this.children[0].generate(context, writer, selection);\n }\n } else if (composedSchema.allOf != null) {\n const selected = this.selectedProps(selection);\n\n if (selected.length > 0) {\n // writer.write('type ');\n writer.write(this.kind + ' ');\n writer.write(Naming.getRefName(this.name));\n writer.append(this.nameSuffix());\n writer.write(' {\\n');\n\n for (const prop of selected) {\n trace(context, ' [comp::generate]', `-> property: ${prop.name} (parent: ${prop.parent!.name})`);\n prop.generate(context, writer, selection);\n }\n\n writer.write('}\\n\\n');\n }\n }\n\n trace(context, '<- [comp::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [comp::select]', `-> in: ${this.name}`);\n if (!this.consolidated) {\n this.consolidate(selection);\n }\n\n const composedSchema = this.schema;\n if (composedSchema.allOf != null) {\n const selected = this.selectedProps(selection);\n\n for (const prop of selected) {\n prop.select(context, writer, selection);\n }\n } else if (composedSchema.oneOf != null) {\n if (this.children.length === 1) {\n this.children[0].select(context, writer, selection);\n } else {\n throw new Error('Expected exactly one child for a oneOf schema');\n }\n }\n\n trace(context, '<- [comp::select]', `-> out: ${this.name}`);\n }\n\n public consolidate(selection: string[]): Set<string> {\n const ids: Set<string> = new Set();\n let props: Map<string, Prop> = new Map();\n\n const queue: IType[] = Array.from(this.children.values()).filter((child) => !(child instanceof Prop));\n\n while (queue.length > 0) {\n const node = queue.shift()!;\n\n ids.add(node instanceof Ref ? (node as Ref).refType!.id : node.id);\n\n if (selection.length > 0) {\n node.props.forEach((prop) => {\n if (selection.find((s) => s.startsWith(prop.path()))) {\n props.set(prop.name, prop);\n }\n });\n } else {\n node.props.forEach((prop) => props.set(prop.name, prop));\n }\n\n // sort props\n props = new Map([...props.entries()].sort());\n\n const children = Array.from(node.children.values()).filter((child) => !(child instanceof Prop));\n\n queue.push(...children);\n }\n\n // copy all collected props from children into this node\n props.forEach((prop, name) => this.props.set(name, prop));\n\n this.consolidated = true;\n\n // and return the types.ts we've used\n return ids;\n }\n\n private visitAllOfNode(context: OasContext, schema: SchemaObject): void {\n const allOfs = schema.allOf || [];\n const refs = allOfs.map((s) => (s as ReferenceObject).$ref);\n\n trace(context, '-> [composed::all-of]', `in: '${this.name}' of: ${allOfs.length} - refs: ${refs}`);\n\n for (let i = 0; i < allOfs.length; i++) {\n const allOfItemSchema = allOfs[i];\n\n const type = Factory.fromSchema(this, allOfItemSchema as SchemaObject);\n trace(context, ' [composed::all-of]', 'allOf type: ' + type);\n\n if (type) {\n type.visit(context);\n }\n }\n\n trace(context, '-> [composed]', 'storing: ' + this.name + ' with: ' + this);\n context.store(this.name, this);\n trace(context, '<- [composed::all-of]', `out: '${this.name}' of: ${allOfs.length} - refs: ${refs}`);\n }\n\n private visitOneOfNode(context: OasContext, schema: SchemaObject): void {\n const oneOfs = schema.oneOf || [];\n trace(context, '-> [composed::one-of]', `in: OneOf ${this.name} with size: ${oneOfs.length}`);\n\n const result = Factory.fromUnion(context, this, oneOfs as SchemaObject[]);\n if (!result) {\n throw new Error('Failed to create union type');\n }\n\n result.visit(context);\n\n trace(context, '-> [composed::one-of]', `storing: ${this.name} with: ${this}`);\n if (this.name != null) {\n context.store(this.name, this);\n }\n\n trace(context, '<- [composed::one-of]', `out: OneOf ${this.name} with size: ${oneOfs.length}`);\n }\n}\n"]}
1
+ {"version":3,"file":"comp.js","sourceRoot":"","sources":["../../../src/oas/nodes/comp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAc,IAAI,EAAmB,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAGzF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,MAAM,OAAO,QAAS,SAAQ,IAAI;IAGvB;IACA;IACA;IAJT,YACE,MAAyB,EAClB,IAAY,EACZ,MAAoB,EACpB,eAAwB,KAAK;QAEpC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAJb,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAc;QACpB,iBAAY,GAAZ,YAAY,CAAiB;QAGpC,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED,IAAI,EAAE;QACJ,8BAA8B;QAC9B,OAAO,QAAQ,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;IAC1C,CAAC;IAEM,SAAS,CAA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,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACjC,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,uBAAuB,EAAE,cAAc,IAAI,CAAC,IAAI,eAAe,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACjG,CAAC;IAED,GAAG,CAAC,KAAY;QACd,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACtB,IAAI,GAAG,GAAG,CAAC,CAAC;QAEZ,8CAA8C;QAC9C,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YAClD,IAAI,GAAG,GAAG,KAAK,CAAC,IAAI,IAAI,EAAE,GAAG,EAAE,CAAC;QAClC,CAAC;QAED,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAEO,UAAU;QAChB,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAErB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,IAAI,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;gBAC/B,MAAM,EAAE,GAAG,IAAI,CAAC,MAAO,CAAC,MAAa,CAAC;gBACtC,IAAI,GAAG,EAAE,CAAC,YAAY,EAAE,GAAG,UAAU,CAAC;YACxC,CAAC;iBAAM,CAAC;gBACN,IAAI,GAAG,WAAW,IAAI,CAAC,MAAO,CAAC,IAAI,GAAG,CAAC;YACzC,CAAC;QACH,CAAC;QACD,8CAA8C;QAC9C,wCAAwC;QACxC,IAAI;QAEJ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { Factory, Get, IType, Prop, ReferenceObject, Res, T, Type } from './internal.js';\nimport { SchemaObject } from 'oas/types';\n\nimport { trace } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\nimport { Naming } from '../utils/naming.js';\nimport _ from 'lodash';\n\nexport class Composed extends Type {\n constructor(\n parent: IType | undefined,\n public name: string,\n public schema: SchemaObject,\n public consolidated: boolean = false,\n ) {\n super(parent, name);\n this.updateName();\n }\n\n get id(): string {\n // return `comp:${this.name}`;\n return `comp:${this.kind}:${this.name}`;\n }\n\n public forPrompt(_context: OasContext): string {\n return `[comp] ${Naming.getRefName(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, '-> [composed:visit]', 'in: ' + (this.name == null ? '[object]' : this.name));\n\n // If not in the context of a Composed or Param, log the composed schema.\n if (!context.inContextOf('Composed', this) && !context.inContextOf('Param', this)) {\n trace(context, '[comp]', ' in composed schema: ' + this.name);\n }\n\n const composedSchema = this.schema;\n // this will be a type declaration\n if (composedSchema.allOf != null) {\n this.visitAllOfNode(context, composedSchema);\n }\n // represents a Union type\n else if (composedSchema.oneOf != null) {\n throw new Error('Unions should be constructed by its own object');\n // deprecated\n // this.visitOneOfNode(context, composedSchema);\n }\n // can't hand this yet\n else {\n throw new Error('Composed.visit: unsupported composed schema: ' + this.schema);\n }\n\n this.visited = true;\n trace(context, '<- [composed: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, '-> [comp::generate]', `-> in: ${this.name}`);\n\n if (context.inContextOf('Res', this)) {\n writer.append(Naming.genTypeName(this.name));\n return;\n }\n\n const composedSchema = this.schema;\n if (composedSchema.oneOf != null) {\n if (this.children.length > 0) {\n this.children[0].generate(context, writer, selection);\n }\n } else if (composedSchema.allOf != null) {\n const selected = this.selectedProps(selection);\n\n if (selected.length > 0) {\n // writer.write('type ');\n writer.write(this.kind + ' ');\n writer.write(_.upperFirst(Naming.getRefName(this.name)));\n writer.append(this.nameSuffix());\n writer.write(' {\\n');\n\n for (const prop of selected) {\n trace(context, ' [comp::generate]', `-> property: ${prop.name} (parent: ${prop.parent!.name})`);\n prop.generate(context, writer, selection);\n }\n\n writer.write('}\\n\\n');\n }\n }\n\n trace(context, '<- [comp::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [comp::select]', `-> in: ${this.name}`);\n if (!this.consolidated) {\n this.consolidate(selection);\n }\n\n const composedSchema = this.schema;\n if (composedSchema.allOf != null) {\n const selected = this.selectedProps(selection);\n\n for (const prop of selected) {\n prop.select(context, writer, selection);\n }\n } else if (composedSchema.oneOf != null) {\n if (this.children.length === 1) {\n this.children[0].select(context, writer, selection);\n } else {\n throw new Error('Expected exactly one child for a oneOf schema');\n }\n }\n\n trace(context, '<- [comp::select]', `-> out: ${this.name}`);\n }\n\n public consolidate(selection: string[]): Set<string> {\n /*T.composables(this).forEach((child) => {\n (child as (Composed)).consolidate(selection);\n });*/\n\n const ids: Set<string> = new Set();\n let props: Map<string, Prop> = new Map();\n\n const tree = T.print(this);\n const queue: IType[] = Array.from(this.children.values()).filter((child) => !(child instanceof Prop));\n\n while (queue.length > 0) {\n const node = queue.shift()!;\n ids.add(node.id);\n\n if (selection.length > 0) {\n node.props.forEach((prop) => {\n if (selection.find((s) => s.startsWith(prop.path()))) {\n props.set(prop.name, prop);\n }\n });\n } else {\n node.props.forEach((prop) => props.set(prop.name, prop));\n }\n\n // sort props\n props = new Map([...props.entries()].sort());\n\n const children = Array.from(node.children.values()).filter((child) => !(child instanceof Prop));\n queue.push(...children);\n }\n\n // copy all collected props from children into this node\n props.forEach((prop, name) => this.props.set(name, prop));\n\n this.consolidated = true;\n\n // and return the types.ts we've used\n return ids;\n }\n\n private visitAllOfNode(context: OasContext, schema: SchemaObject): void {\n const allOfs = schema.allOf || [];\n const refs = allOfs.map((s) => (s as ReferenceObject).$ref);\n\n trace(context, '-> [composed::all-of]', `in: '${this.name}' of: ${allOfs.length} - refs: ${refs}`);\n\n for (let i = 0; i < allOfs.length; i++) {\n const allOfItemSchema = allOfs[i];\n\n const type = Factory.fromSchema(context, this, allOfItemSchema as SchemaObject);\n this.add(type);\n\n trace(context, ' [composed::all-of]', 'allOf type: ' + type);\n\n if (type) {\n type.visit(context);\n }\n }\n\n const tree = T.print(this);\n context.store(this.name, this);\n trace(context, '<- [composed::all-of]', `out: '${this.name}' of: ${allOfs.length} - refs: ${refs}`);\n }\n\n private visitOneOfNode(context: OasContext, schema: SchemaObject): void {\n const oneOfs = schema.oneOf || [];\n trace(context, '-> [composed::one-of]', `in: OneOf ${this.name} with size: ${oneOfs.length}`);\n\n const result = Factory.fromUnion(context, this, oneOfs as SchemaObject[]);\n if (!result) {\n throw new Error('Failed to create union type');\n }\n\n result.visit(context);\n\n trace(context, '-> [composed::one-of]', `storing: ${this.name} with: ${this}`);\n if (this.name != null) {\n context.store(this.name, this);\n }\n\n trace(context, '<- [composed::one-of]', `out: OneOf ${this.name} with size: ${oneOfs.length}`);\n }\n\n add(child: IType): IType {\n let name = child.name;\n let idx = 0;\n\n // TODO: this should not be applicable to Refs\n while (this.children.some((c) => c.name === name)) {\n name = `${child.name}:${++idx}`;\n }\n\n child.name = name;\n return super.add(child);\n }\n\n private updateName(): void {\n let name = this.name;\n\n if (!name) {\n if (this.parent instanceof Res) {\n const op = this.parent!.parent as Get;\n name = op.getGqlOpName() + 'Response';\n } else {\n name = `[inline:${this.parent!.name}]`;\n }\n }\n // else if (this.parent instanceof Composed) {\n // name = this.parent!.name + 'AllOf';\n // }\n\n this.name = name;\n }\n}\n"]}
@@ -5,7 +5,7 @@ import { Writer } from '../io/writer.js';
5
5
  export declare class En extends Type {
6
6
  schema: SchemaObject;
7
7
  items: string[];
8
- constructor(parent: IType, schema: SchemaObject, items?: string[]);
8
+ constructor(parent: IType, name: string | undefined, schema: SchemaObject, items?: string[]);
9
9
  get id(): string;
10
10
  visit(context: OasContext): void;
11
11
  forPrompt(_context: OasContext): string;
@@ -5,8 +5,8 @@ import { Naming } from '../utils/naming.js';
5
5
  export class En extends Type {
6
6
  schema;
7
7
  items;
8
- constructor(parent, schema, items = []) {
9
- super(parent, 'enum');
8
+ constructor(parent, name = 'enum', schema, items = []) {
9
+ super(parent, name);
10
10
  this.schema = schema;
11
11
  this.items = items;
12
12
  }
@@ -27,7 +27,7 @@ export class En extends Type {
27
27
  context.leave(this);
28
28
  }
29
29
  forPrompt(_context) {
30
- return `${Naming.getRefName(this.name)} (Enum): ${this.items.join(', ')}`;
30
+ return `[enum] ${Naming.getRefName(this.name)}: ${this.items.join(', ')}`;
31
31
  }
32
32
  generate(context, writer, selection) {
33
33
  context.enter(this);
@@ -1 +1 @@
1
- {"version":3,"file":"en.js","sourceRoot":"","sources":["../../../src/oas/nodes/en.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,EAAG,SAAQ,IAAI;IAGjB;IACA;IAHT,YACE,MAAa,EACN,MAAoB,EACpB,QAAkB,EAAE;QAE3B,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAHf,WAAM,GAAN,MAAM,CAAc;QACpB,UAAK,GAAL,KAAK,CAAe;IAG7B,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;IAC7B,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,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC,KAAK,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AC7C,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QACvD,CAAC;QAED,yBAAyB;QACzB,KAAK,CAAC,OAAO,EAAE,qBAAqB,EAAE,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9D,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAEM,MAAM,CAAC,OAAmB,EAAE,MAAc,EAAE,SAAmB;QACpE,KAAK,CAAC,OAAO,EAAE,mBAAmB,EAAE,UAAU,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAE3D,cAAc;QACd;;;aAGK;QAEL,KAAK,CAAC,OAAO,EAAE,mBAAmB,EAAE,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF","sourcesContent":["import { IType, 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 { GqlUtils } from '../utils/gql.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class En extends Type {\n constructor(\n parent: IType,\n public schema: SchemaObject,\n public items: string[] = [],\n ) {\n super(parent, 'enum');\n }\n\n get id(): string {\n return 'enum:' + 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, '-> [enum:visit]', 'in: ' + this.items.toString());\n\n if (!context.inContextOf('Param', this)) {\n context.store(this.name, this);\n }\n\n this.visited = true;\n\n trace(context, '<- [enum:visit]', 'out: ' + this.items.toString());\n context.leave(this);\n }\n\n public forPrompt(_context: OasContext): string {\n return `${Naming.getRefName(this.name)} (Enum): ${this.items.join(', ')}`;\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n context.enter(this);\n trace(context, '-> [enum::generate]', `-> in: ${this.name}`);\n\n if (!context.inContextOf('Param', this)) {\n const builder =\n 'enum ' + Naming.getRefName(this.name) + ' {\\n' + this.items.map((s) => ' ' + s).join(',\\n') + '\\n}\\n\\n';\n writer.write(builder);\n }\n // this covers the case where a union combines a scalar with an enum.\n else if (!context.inContextOf('Union', this)) {\n writer.write(GqlUtils.getGQLScalarType(this.schema));\n }\n\n // Otherwise, do nothing.\n trace(context, '<- [enum::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [enum::select]', `-> in: ${this.name}`);\n\n // do nothing?\n /*const dependencies = this.dependencies(context);\n dependencies.forEach((dependency) => {\n dependency.select(context, writer);\n });*/\n\n trace(context, '<- [enum::select]', `-> out: ${this.name}`);\n }\n}\n"]}
1
+ {"version":3,"file":"en.js","sourceRoot":"","sources":["../../../src/oas/nodes/en.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,IAAI,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,OAAO,EAAG,SAAQ,IAAI;IAIjB;IACA;IAJT,YACE,MAAa,EACb,OAAe,MAAM,EACd,MAAoB,EACpB,QAAkB,EAAE;QAE3B,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAHb,WAAM,GAAN,MAAM,CAAc;QACpB,UAAK,GAAL,KAAK,CAAe;IAG7B,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;IAC7B,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,iBAAiB,EAAE,MAAM,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AAI,CAAC,EAAE,CAAC;YAC7C,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QACvD,CAAC;QAED,yBAAyB;QACzB,KAAK,CAAC,OAAO,EAAE,qBAAqB,EAAE,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9D,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAEM,MAAM,CAAC,OAAmB,EAAE,MAAc,EAAE,SAAmB;QACpE,KAAK,CAAC,OAAO,EAAE,mBAAmB,EAAE,UAAU,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAE3D,cAAc;QACd;;;aAGK;QAEL,KAAK,CAAC,OAAO,EAAE,mBAAmB,EAAE,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF","sourcesContent":["import { IType, 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 { GqlUtils } from '../utils/gql.js';\nimport { Naming } from '../utils/naming.js';\n\nexport class En extends Type {\n constructor(\n parent: IType,\n name: string = 'enum',\n public schema: SchemaObject,\n public items: string[] = [],\n ) {\n super(parent, name);\n }\n\n get id(): string {\n return 'enum:' + 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, '-> [enum:visit]', 'in: ' + this.items.toString());\n\n if (!context.inContextOf('Param', this)) {\n context.store(this.name, this);\n }\n\n this.visited = true;\n\n trace(context, '<- [enum:visit]', 'out: ' + this.items.toString());\n context.leave(this);\n }\n\n public forPrompt(_context: OasContext): string {\n return `[enum] ${Naming.getRefName(this.name)}: ${this.items.join(', ')}`;\n }\n\n public generate(context: OasContext, writer: Writer, selection: string[]): void {\n context.enter(this);\n trace(context, '-> [enum::generate]', `-> in: ${this.name}`);\n\n if (!context.inContextOf('Param', this)) {\n const builder =\n 'enum ' + Naming.getRefName(this.name) + ' {\\n' + this.items.map((s) => ' ' + s).join(',\\n') + '\\n}\\n\\n';\n writer.write(builder);\n }\n // this covers the case where a union combines a scalar with an enum.\n else if (!context.inContextOf('Union', this)) {\n writer.write(GqlUtils.getGQLScalarType(this.schema));\n }\n\n // Otherwise, do nothing.\n trace(context, '<- [enum::generate]', `-> out: ${this.name}`);\n context.leave(this);\n }\n\n public select(context: OasContext, writer: Writer, selection: string[]) {\n trace(context, '-> [enum::select]', `-> in: ${this.name}`);\n\n // do nothing?\n /*const dependencies = this.dependencies(context);\n dependencies.forEach((dependency) => {\n dependency.select(context, writer);\n });*/\n\n trace(context, '<- [enum::select]', `-> out: ${this.name}`);\n }\n}\n"]}
@@ -1,11 +1,14 @@
1
- import { Get, Post, IType, ReferenceObject, Prop, Param } from './internal.js';
1
+ import { Get, IType, Param, Post, Prop, ReferenceObject } from './internal.js';
2
2
  import { Operation } from 'oas/operation';
3
3
  import { ParameterObject, SchemaObject } from 'oas/types';
4
4
  import { OasContext } from '../oasContext.js';
5
5
  export declare class Factory {
6
6
  static createGet(name: string, op: Operation): Get;
7
- static fromSchema(parent: IType, schema: SchemaObject | ReferenceObject): IType;
8
- static fromProp(context: OasContext, parent: IType, propertyName: string, schema: SchemaObject): Prop;
7
+ static fromSchema(context: OasContext, parent: IType, inputSchema: SchemaObject | ReferenceObject): IType;
8
+ private static createScalarType;
9
+ private static createContainerType;
10
+ private static createArrayType;
11
+ static fromProp(context: OasContext, parent: IType, propName: string, inputSchema: SchemaObject | ReferenceObject): Prop;
9
12
  static fromResponse(_context: OasContext, parent: IType, mediaSchema: SchemaObject): IType;
10
13
  static fromParam(context: OasContext, parent: IType, p: ParameterObject | ReferenceObject): Param;
11
14
  static fromCircularRef(parent: IType, child: IType): IType;
@@ -1,133 +1,174 @@
1
- import { Get, Post, Ref, Arr, Composed, Obj, En, Scalar, PropRef, PropArray, PropObj, PropScalar, CircularRef, Union, Response, Param, Body, Put, Patch, Delete, PropComp, } from './internal.js';
1
+ import { Arr, Body, CircularRef, Composed, Delete, En, Get, Obj, Param, Patch, Post, PropArray, PropCircRef, PropComp, PropObj, PropScalar, Put, Res, Scalar, T, Union, PropEn, } from './internal.js';
2
2
  import _ from 'lodash';
3
- import { trace, warn } from '../log/trace.js';
4
- import { Naming } from '../utils/naming.js';
3
+ import { warn } from '../log/trace.js';
5
4
  import { GqlUtils } from '../utils/gql.js';
6
5
  import { APOLLO_SYNTHETIC_OBJ } from '../schemas/index.js';
7
6
  export class Factory {
8
7
  static createGet(name, op) {
9
8
  return new Get(name, op);
10
9
  }
11
- static fromSchema(parent, schema) {
10
+ static fromSchema(context, parent, inputSchema) {
12
11
  let result = null;
12
+ let schema = inputSchema;
13
+ let ref;
14
+ // resolve first if reference
13
15
  if ('$ref' in schema) {
14
- result = new Ref(parent, schema.$ref, schema);
15
- }
16
+ // result = new Ref(parent, schema.$ref as string, schema as ReferenceObject);
17
+ ref = schema?.$ref;
18
+ if (ref)
19
+ schema = context.lookupRef(ref);
20
+ }
21
+ if (!schema)
22
+ throw new Error('Unknown or undefined schema');
23
+ const schemaObj = schema;
16
24
  // array case
17
- else if (schema.type === 'array' && schema.items) {
18
- // Array schema case.
19
- let parentName = parent.name;
20
- if (parent instanceof Response) {
21
- // Assume parent.parent is a GetOp.
22
- const get = parent.parent;
23
- parentName = _.upperFirst(get.getGqlOpName());
24
- }
25
- else {
26
- trace(null, '[factory]', 'Factory.fromSchema >>> HERE');
27
- }
28
- // result = new Arr(parent, parentName, schema.items as ArraySchemaObject);
29
- // (result as Arr).itemsType = Factory.fromSchema(result, schema.items as ArraySchemaObject);
30
- const arr = new Arr(parent, parentName);
31
- const items = schema.items;
32
- arr.items = items;
33
- arr.itemsType = Factory.fromSchema(arr, items);
34
- result = arr;
25
+ if (schemaObj.type === 'array' && schemaObj.items) {
26
+ result = this.createArrayType(parent, schemaObj, context);
35
27
  }
36
28
  // array case
37
- else if (schema.type === 'object') {
38
- // it's either a union or a composed object
39
- if (schema.allOf) {
40
- result = new Composed(parent, _.get(schema, 'name') || parent.name, schema);
41
- }
42
- else if (schema.oneOf) {
43
- const oneOfs = schema.oneOf || [];
44
- result = new Union(parent, _.get(schema, 'name') || parent.name, oneOfs);
45
- }
46
- // or a plain obj
47
- else {
48
- if (!schema.properties) {
49
- warn(null, '[factory]', 'Object has no properties: ' + JSON.stringify(schema, null, 2) + ' in: ' + parent.pathToRoot());
50
- }
51
- result = new Obj(parent, _.get(schema, 'name') || null, schema);
52
- if (schema.format == APOLLO_SYNTHETIC_OBJ) {
53
- result.synthetic = true;
54
- }
55
- }
56
- }
57
- // Composed schema case.
58
- else if (schema.oneOf) {
59
- const oneOfs = schema.oneOf || [];
60
- result = new Union(parent, _.get(schema, 'name') || parent.name, oneOfs);
61
- }
62
- else if (schema.allOf) {
63
- result = new Composed(parent, _.get(schema, 'name') || parent.name, schema);
29
+ else if (schemaObj?.type === 'object' || schemaObj?.oneOf || schemaObj?.allOf || !_.isEmpty(schemaObj.properties)) {
30
+ result = this.createContainerType(parent, schemaObj, ref);
64
31
  }
65
32
  // scalar
66
33
  else {
67
- const typeStr = schema.type;
68
- if (typeStr != null) {
69
- if (typeStr === 'array') {
70
- throw new Error(`Should have been handled already? ${typeStr}, schema: ${JSON.stringify(schema)}`);
71
- }
72
- else if (schema.enum != null) {
73
- result = new En(parent, schema, schema.enum);
74
- }
75
- // scalar case
76
- else if (GqlUtils.gqlScalar(typeStr)) {
77
- const scalarType = GqlUtils.getGQLScalarType(schema);
78
- result = new Scalar(parent, scalarType, schema);
79
- }
80
- // or we have no idea how to handle this
81
- else {
82
- throw new Error(`Cannot handle property type ${typeStr}, schema: ${JSON.stringify(schema)}`);
83
- }
34
+ result = this.createScalarType(schemaObj, parent);
35
+ }
36
+ // we could not infer a proper type
37
+ if (result == null) {
38
+ throw new Error(`Not yet implemented for ${JSON.stringify(schemaObj)}`);
39
+ }
40
+ return result;
41
+ }
42
+ static createScalarType(schema, parent) {
43
+ const typeStr = schema?.type;
44
+ if (typeStr != null) {
45
+ if (typeStr === 'array') {
46
+ throw new Error(`Should have been handled already? ${typeStr}, schema: ${JSON.stringify(schema)}`);
47
+ }
48
+ else if (schema?.enum != null) {
49
+ return new En(parent, 'enum', schema, schema.enum);
84
50
  }
85
- else if (schema.enum != null) {
86
- result = new En(parent, schema, _.get(schema, 'enum'));
51
+ // scalar case
52
+ else if (GqlUtils.gqlScalar(typeStr)) {
53
+ const scalarType = GqlUtils.getGQLScalarType(schema);
54
+ return new Scalar(parent, scalarType, schema);
87
55
  }
88
56
  // or we have no idea how to handle this
89
57
  else {
90
- throw new Error(`Cannot handle schema ${parent.pathToRoot()}, schema: ${JSON.stringify(schema)}`);
58
+ throw new Error(`Cannot handle property type ${typeStr}, schema: ${JSON.stringify(schema)}`);
91
59
  }
92
60
  }
93
- if (result != null) {
94
- parent.add(result);
61
+ else if (schema?.enum != null) {
62
+ return new En(parent, 'enum', schema, _.get(schema, 'enum'));
95
63
  }
96
- // we could not infer a proper type
64
+ // or we have no idea how to handle this
97
65
  else {
98
- throw new Error(`Not yet implemented for ${JSON.stringify(schema)}`);
66
+ throw new Error(`Cannot handle schema ${parent.pathToRoot()}, schema: ${JSON.stringify(schema)}`);
67
+ }
68
+ }
69
+ static createContainerType(parent, schema, ref) {
70
+ let result;
71
+ // composed object
72
+ if (schema.allOf) {
73
+ result = new Composed(parent, ref || _.get(schema, 'name'), schema);
74
+ }
75
+ // union
76
+ else if (schema.oneOf) {
77
+ const oneOfs = schema.oneOf || [];
78
+ result = new Union(parent, ref || _.get(schema, 'name'), oneOfs);
79
+ }
80
+ // or a plain obj
81
+ else {
82
+ if (!schema.properties) {
83
+ warn(null, '[factory]', 'Object has no properties: ' + JSON.stringify(schema, null, 2) + ' in: ' + parent.pathToRoot());
84
+ }
85
+ result = new Obj(parent, ref || _.get(schema, 'name') || null, schema);
86
+ // if we want to syntethise an object:
87
+ if (schema.format == APOLLO_SYNTHETIC_OBJ) {
88
+ result.synthetic = true;
89
+ }
99
90
  }
100
91
  return result;
101
92
  }
102
- static fromProp(context, parent, propertyName, schema) {
103
- if (!schema) {
104
- throw new Error(`Should have a schema defined for property '${propertyName}' (parent: '${parent.name}')`);
93
+ static createArrayType(parent, schema, context) {
94
+ // Array schema case.
95
+ let parentName = parent.name;
96
+ if (parent instanceof Res) {
97
+ const get = parent.parent; // Assume parent.parent is a GetOp.
98
+ parentName = _.upperFirst(get.getGqlOpName());
99
+ }
100
+ const arr = new Arr(parent, parentName);
101
+ const items = _.get(schema, 'items');
102
+ arr.items = items;
103
+ // TODO: check this
104
+ arr.itemsType = Factory.fromSchema(context, arr, items);
105
+ arr.add(arr.itemsType); // add it to the children
106
+ return arr;
107
+ }
108
+ static fromProp(context, parent, propName, inputSchema) {
109
+ if (!inputSchema) {
110
+ throw new Error(`Should have a schema defined for property '${propName}' (parent: '${parent.name}')`);
105
111
  }
106
- const type = schema.type;
112
+ let schema = inputSchema;
107
113
  let prop;
108
- if (!type && '$ref' in schema) {
109
- prop = new PropRef(parent, propertyName, schema, schema.$ref);
114
+ let ref;
115
+ if (!_.get(schema, 'type') && '$ref' in schema) {
116
+ ref = schema.$ref;
117
+ schema = context.lookupRef(ref);
118
+ // this was a prop ref, but now needs to be returned as the ref directly?
119
+ // prop = new PropRef(parent, propName, schema, ref);
120
+ // return prop;
110
121
  }
111
122
  // uses the type of the schema to find out what kind of property it is
112
- else if (type) {
123
+ const schemaObj = schema;
124
+ const type = schemaObj.type;
125
+ if (type) {
113
126
  // 1st case is if the type is an array
114
127
  if (type === 'array') {
115
- const array = new PropArray(parent, propertyName, schema);
116
- const itemsName = Naming.genArrayItems(propertyName);
117
- const itemsType = Factory.fromProp(context, array, itemsName, schema.items);
128
+ const array = new PropArray(parent, propName, schema);
129
+ // const itemsName = Naming.genArrayItems(propName);
130
+ const itemsSchema = _.get(schemaObj, 'items');
131
+ // const itemsType = Factory.fromProp(context, array, itemsName, itemsSchema); // TODO: re-test
132
+ const itemsType = Factory.fromSchema(context, array, itemsSchema);
118
133
  array.setItems(itemsType);
119
134
  prop = array;
120
135
  }
121
136
  // 2nd checks for obj property
122
- else if (type === 'object') {
123
- // the type of the property will be an object, which needs to be added as a child
124
- const propType = new Obj(parent, propertyName, schema);
125
- prop = new PropObj(parent, propertyName, schema, propType);
137
+ else if (schemaObj?.type === 'object' ||
138
+ schemaObj?.oneOf ||
139
+ schemaObj?.allOf ||
140
+ !_.isEmpty(schemaObj.properties)) {
141
+ if (schemaObj.oneOf) {
142
+ const inner = new PropComp(parent, propName, schemaObj);
143
+ inner.comp = new Union(inner, ref || _.get(schemaObj, 'name'), schemaObj.oneOf);
144
+ prop = inner;
145
+ }
146
+ else if (schemaObj.allOf) {
147
+ const propComp = new PropComp(parent, propName, schemaObj);
148
+ propComp.comp = new Composed(propComp, ref || _.get(schemaObj, 'name'), schemaObj);
149
+ prop = propComp;
150
+ }
151
+ else if (schemaObj.properties != null) {
152
+ const propType = new Obj(parent, ref || propName, schemaObj);
153
+ prop = new PropObj(parent, propName, schemaObj, propType);
154
+ }
155
+ else {
156
+ // the type of the property will be an object, which needs to be added as a child
157
+ const propType = new Obj(parent, ref || propName, schemaObj);
158
+ prop = new PropObj(parent, propName, schemaObj, propType);
159
+ }
160
+ }
161
+ else if (ref && schemaObj?.enum) {
162
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- for options
163
+ const stringEnum = _.every(schemaObj.enum, (value, _) => typeof value === 'string');
164
+ const en = new En(parent, ref, schemaObj, stringEnum ? schemaObj.enum : []);
165
+ prop = new PropEn(parent, propName, ref, schemaObj);
166
+ prop.add(en);
126
167
  }
127
168
  // 3rd tries for scalar
128
169
  else if (GqlUtils.gqlScalar(type)) {
129
170
  const scalar = GqlUtils.gqlScalar(type);
130
- prop = new PropScalar(parent, propertyName, scalar, schema);
171
+ prop = new PropScalar(parent, propName, scalar, schemaObj);
131
172
  }
132
173
  // or we don't know how to handle this
133
174
  else {
@@ -135,31 +176,33 @@ export class Factory {
135
176
  }
136
177
  }
137
178
  // otherwise let's use the properties instead and assume an Obj
138
- else if (schema.properties != null) {
139
- const propType = new Obj(parent, propertyName, schema);
140
- prop = new PropObj(parent, propertyName, schema, propType);
141
- }
142
- else if (schema.oneOf) {
143
- const propComp = new PropComp(parent, propertyName, schema);
144
- propComp.comp = new Union(propComp, _.get(schema, 'name') || parent.name, schema.oneOf);
179
+ // TODO: repeated code
180
+ else if (schemaObj.oneOf) {
181
+ const inner = new PropComp(parent, propName, schemaObj);
182
+ inner.comp = new Union(inner, ref || _.get(schemaObj, 'name'), schemaObj.oneOf);
183
+ prop = inner;
184
+ }
185
+ else if (schemaObj.allOf) {
186
+ const propComp = new PropComp(parent, propName, schemaObj);
187
+ propComp.comp = new Composed(propComp, ref || _.get(schemaObj, 'name'), schemaObj);
145
188
  prop = propComp;
146
189
  }
147
- else if (schema.allOf) {
148
- const propComp = new PropComp(parent, propertyName, schema);
149
- propComp.comp = new Composed(propComp, _.get(schema, 'name') || parent.name, schema);
150
- prop = propComp;
190
+ else if (schemaObj.properties != null) {
191
+ const propType = new Obj(parent, ref || propName, schemaObj);
192
+ prop = new PropObj(parent, propName, schemaObj, propType);
151
193
  }
152
194
  // default case, we don't know what to do so we'll create a scalar of type JSON
153
195
  else {
154
- prop = new PropScalar(parent, propertyName, 'JSON', schema);
196
+ prop = new PropScalar(parent, propName, 'JSON', schemaObj);
155
197
  }
156
- if (parent.ancestors().includes(prop)) {
157
- console.warn('[factory] Recursion detected! Ancestors already contain this type: \n' + prop.pathToRoot());
198
+ if (parent.ancestors().find((a) => a.id === prop.id)) {
199
+ console.warn('[factory] Recursion detected! Ancestors already contain this type: \n' + prop.id);
200
+ prop = new PropCircRef(parent, prop);
158
201
  }
159
202
  return prop;
160
203
  }
161
204
  static fromResponse(_context, parent, mediaSchema) {
162
- return new Response(parent, 'r', mediaSchema);
205
+ return new Res(parent, 'r', mediaSchema);
163
206
  }
164
207
  static fromParam(context, parent, p) {
165
208
  let param;
@@ -179,6 +222,7 @@ export class Factory {
179
222
  return new Param(parent, param.name, schema, required, schema.default, param);
180
223
  }
181
224
  static fromCircularRef(parent, child) {
225
+ const _tree = T.print(parent);
182
226
  const circularRef = new CircularRef(parent, child.name);
183
227
  circularRef.ref = child;
184
228
  return circularRef;
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/oas/nodes/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,IAAI,EAEJ,GAAG,EAEH,GAAG,EACH,QAAQ,EACR,GAAG,EACH,EAAE,EACF,MAAM,EAEN,OAAO,EACP,SAAS,EACT,OAAO,EACP,UAAU,EACV,WAAW,EACX,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,GAAG,EACH,KAAK,EACL,MAAM,EACN,QAAQ,GACT,MAAM,eAAe,CAAC;AAKvB,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,MAAM,OAAO,OAAO;IACX,MAAM,CAAC,SAAS,CAAC,IAAY,EAAE,EAAa;QACjD,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,UAAU,CAAC,MAAa,EAAE,MAAsC;QAC5E,IAAI,MAAM,GAAiB,IAAI,CAAC;QAEhC,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;YACrB,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,IAAc,EAAE,MAAyB,CAAC,CAAC;QAC7E,CAAC;QACD,aAAa;aACR,IAAI,MAAM,CAAC,I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,CAAC;CACF","sourcesContent":["import {\n Get,\n Post,\n IType,\n Ref,\n ReferenceObject,\n Arr,\n Composed,\n Obj,\n En,\n Scalar,\n Prop,\n PropRef,\n PropArray,\n PropObj,\n PropScalar,\n CircularRef,\n Union,\n Response,\n Param,\n Body,\n Put,\n Patch,\n Delete,\n PropComp,\n} from './internal.js';\nimport { Operation } from 'oas/operation';\nimport { ParameterObject, SchemaObject } from 'oas/types';\nimport { OpenAPIV3 } from 'openapi-types';\nimport ArraySchemaObject = OpenAPIV3.ArraySchemaObject;\nimport _ from 'lodash';\nimport { trace, warn } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { Naming } from '../utils/naming.js';\nimport { GqlUtils } from '../utils/gql.js';\nimport { APOLLO_SYNTHETIC_OBJ } from '../schemas/index.js';\n\nexport class Factory {\n public static createGet(name: string, op: Operation): Get {\n return new Get(name, op);\n }\n\n public static fromSchema(parent: IType, schema: SchemaObject | ReferenceObject): IType {\n let result: IType | null = null;\n\n if ('$ref' in schema) {\n result = new Ref(parent, schema.$ref as string, schema as ReferenceObject);\n }\n // array case\n else if (schema.type === 'array' && schema.items) {\n // Array schema case.\n let parentName = parent.name;\n if (parent instanceof Response) {\n // Assume parent.parent is a GetOp.\n const get = parent.parent as Get;\n parentName = _.upperFirst(get.getGqlOpName());\n } else {\n trace(null, '[factory]', 'Factory.fromSchema >>> HERE');\n }\n\n // result = new Arr(parent, parentName, schema.items as ArraySchemaObject);\n // (result as Arr).itemsType = Factory.fromSchema(result, schema.items as ArraySchemaObject);\n const arr = new Arr(parent, parentName);\n\n const items = schema.items as ArraySchemaObject;\n arr.items = items;\n arr.itemsType = Factory.fromSchema(arr, items);\n\n result = arr;\n }\n // array case\n else if (schema.type === 'object') {\n // it's either a union or a composed object\n if (schema.allOf) {\n result = new Composed(parent, _.get(schema, 'name') || parent.name, schema);\n } else if (schema.oneOf) {\n const oneOfs = schema.oneOf || [];\n result = new Union(parent, _.get(schema, 'name') || parent.name, oneOfs as SchemaObject[]);\n }\n // or a plain obj\n else {\n if (!schema.properties) {\n warn(\n null,\n '[factory]',\n 'Object has no properties: ' + JSON.stringify(schema, null, 2) + ' in: ' + parent.pathToRoot(),\n );\n }\n\n result = new Obj(parent, _.get(schema, 'name') || null, schema);\n if (schema.format == APOLLO_SYNTHETIC_OBJ) {\n (result as Obj).synthetic = true;\n }\n }\n }\n // Composed schema case.\n else if (schema.oneOf) {\n const oneOfs = schema.oneOf || [];\n result = new Union(parent, _.get(schema, 'name') || parent.name, oneOfs as SchemaObject[]);\n } else if (schema.allOf) {\n result = new Composed(parent, _.get(schema, 'name') || parent.name, schema);\n }\n // scalar\n else {\n const typeStr = schema.type;\n if (typeStr != null) {\n if (typeStr === 'array') {\n throw new Error(`Should have been handled already? ${typeStr}, schema: ${JSON.stringify(schema)}`);\n } else if (schema.enum != null) {\n result = new En(parent, schema, schema.enum! as string[]);\n }\n // scalar case\n else if (GqlUtils.gqlScalar(typeStr as string)) {\n const scalarType = GqlUtils.getGQLScalarType(schema);\n result = new Scalar(parent, scalarType, schema);\n }\n // or we have no idea how to handle this\n else {\n throw new Error(`Cannot handle property type ${typeStr}, schema: ${JSON.stringify(schema)}`);\n }\n } else if (schema.enum != null) {\n result = new En(parent, schema, _.get(schema, 'enum') as string[]);\n }\n // or we have no idea how to handle this\n else {\n throw new Error(`Cannot handle schema ${parent.pathToRoot()}, schema: ${JSON.stringify(schema)}`);\n }\n }\n\n if (result != null) {\n parent.add(result);\n }\n // we could not infer a proper type\n else {\n throw new Error(`Not yet implemented for ${JSON.stringify(schema)}`);\n }\n\n return result;\n }\n\n public static fromProp(context: OasContext, parent: IType, propertyName: string, schema: SchemaObject): Prop {\n if (!schema) {\n throw new Error(`Should have a schema defined for property '${propertyName}' (parent: '${parent.name}')`);\n }\n\n const type = schema.type;\n let prop: Prop;\n\n if (!type && '$ref' in schema) {\n prop = new PropRef(parent, propertyName, schema, (schema as ReferenceObject).$ref);\n }\n // uses the type of the schema to find out what kind of property it is\n else if (type) {\n // 1st case is if the type is an array\n if (type === 'array') {\n const array = new PropArray(parent, propertyName, schema);\n\n const itemsName = Naming.genArrayItems(propertyName);\n const itemsType = Factory.fromProp(context, array, itemsName, schema.items as ArraySchemaObject);\n\n array.setItems(itemsType);\n\n prop = array;\n }\n // 2nd checks for obj property\n else if (type === 'object') {\n // the type of the property will be an object, which needs to be added as a child\n const propType: IType = new Obj(parent, propertyName, schema);\n prop = new PropObj(parent, propertyName, schema, propType);\n }\n // 3rd tries for scalar\n else if (GqlUtils.gqlScalar(type as string)) {\n const scalar = GqlUtils.gqlScalar(type as string);\n prop = new PropScalar(parent, propertyName, scalar as string, schema);\n }\n // or we don't know how to handle this\n else {\n throw new Error('Cannot handle property type ' + type);\n }\n }\n // otherwise let's use the properties instead and assume an Obj\n else if (schema.properties != null) {\n const propType: IType = new Obj(parent, propertyName, schema);\n prop = new PropObj(parent, propertyName, schema, propType);\n } else if (schema.oneOf) {\n const propComp: PropComp = new PropComp(parent, propertyName, schema);\n propComp.comp = new Union(propComp, _.get(schema, 'name') || parent.name, schema.oneOf as SchemaObject[]);\n prop = propComp;\n } else if (schema.allOf) {\n const propComp: PropComp = new PropComp(parent, propertyName, schema);\n propComp.comp = new Composed(propComp, _.get(schema, 'name') || parent.name, schema);\n prop = propComp;\n }\n // default case, we don't know what to do so we'll create a scalar of type JSON\n else {\n prop = new PropScalar(parent, propertyName, 'JSON', schema);\n }\n\n if (parent.ancestors().includes(prop)) {\n console.warn('[factory] Recursion detected! Ancestors already contain this type: \\n' + prop.pathToRoot());\n }\n\n return prop;\n }\n\n public static fromResponse(_context: OasContext, parent: IType, mediaSchema: SchemaObject): IType {\n return new Response(parent, 'r', mediaSchema);\n }\n\n public static fromParam(context: OasContext, parent: IType, p: ParameterObject | ReferenceObject): Param {\n let param: ParameterObject;\n\n if ('$ref' in p) {\n const ref: ReferenceObject = p as ReferenceObject;\n const schema = context.lookupParam(ref.$ref);\n\n if (!schema) {\n throw new Error('Schema not found for ref: ' + ref.$ref);\n }\n param = schema as ParameterObject;\n } else {\n param = p as ParameterObject;\n }\n\n const schema = param.schema as SchemaObject;\n const required = param.required === true;\n\n return new Param(parent, param.name, schema, required, schema.default, param);\n }\n\n public static fromCircularRef(parent: IType, child: IType): IType {\n const circularRef = new CircularRef(parent, child.name);\n circularRef.ref = child;\n return circularRef;\n }\n\n public static fromUnion(_context: OasContext, parent: IType, oneOfs: SchemaObject[]): IType {\n const union = new Union(parent, parent.name, oneOfs);\n parent.add(union);\n return union;\n }\n\n public static fromPost(name: string, op: Operation): Post {\n return new Post(name, op);\n }\n\n public static fromPut(name: string, op: Operation): Post {\n return new Put(name, op);\n }\n\n public static fromPatch(name: string, op: Operation): Post {\n return new Patch(name, op);\n }\n\n public static fromDelete(name: string, op: Operation): Post {\n return new Delete(name, op);\n }\n\n public static fromBody(_context: OasContext, parent: IType, schema: SchemaObject): IType {\n const body = new Body(parent, 'b', schema);\n parent.add(body);\n return body;\n }\n}\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/oas/nodes/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,MAAM,EACN,EAAE,EACF,GAAG,EAEH,GAAG,EACH,KAAK,EACL,KAAK,EACL,IAAI,EAEJ,SAAS,EACT,WAAW,EACX,QAAQ,EACR,OAAO,EACP,UAAU,EACV,GAAG,EAEH,GAAG,EACH,MAAM,EACN,CAAC,EACD,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AAIvB,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,MAAM,OAAO,OAAO;IACX,MAAM,CAAC,SAAS,CAAC,IAAY,EAAE,EAAa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MAAM,CAAC,QAAQ,CAAC,QAAoB,EAAE,MAAa,EAAE,MAAoB;QAC9E,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QAC3C,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import {\n Arr,\n Body,\n CircularRef,\n Composed,\n Delete,\n En,\n Get,\n IType,\n Obj,\n Param,\n Patch,\n Post,\n Prop,\n PropArray,\n PropCircRef,\n PropComp,\n PropObj,\n PropScalar,\n Put,\n ReferenceObject,\n Res,\n Scalar,\n T,\n Union,\n PropEn,\n} from './internal.js';\nimport { Operation } from 'oas/operation';\nimport { ParameterObject, SchemaObject } from 'oas/types';\nimport { OpenAPIV3 } from 'openapi-types';\nimport _ from 'lodash';\nimport { warn } from '../log/trace.js';\nimport { OasContext } from '../oasContext.js';\nimport { GqlUtils } from '../utils/gql.js';\nimport { APOLLO_SYNTHETIC_OBJ } from '../schemas/index.js';\nimport ArraySchemaObject = OpenAPIV3.ArraySchemaObject;\n\nexport class Factory {\n public static createGet(name: string, op: Operation): Get {\n return new Get(name, op);\n }\n\n public static fromSchema(context: OasContext, parent: IType, inputSchema: SchemaObject | ReferenceObject): IType {\n let result: IType | null = null;\n let schema: SchemaObject | ReferenceObject | undefined = inputSchema;\n let ref: string | undefined;\n\n // resolve first if reference\n if ('$ref' in schema) {\n // result = new Ref(parent, schema.$ref as string, schema as ReferenceObject);\n ref = schema?.$ref;\n if (ref) schema = context.lookupRef(ref) as SchemaObject;\n }\n\n if (!schema) throw new Error('Unknown or undefined schema');\n const schemaObj: SchemaObject = schema as SchemaObject;\n\n // array case\n if (schemaObj.type === 'array' && schemaObj.items) {\n result = this.createArrayType(parent, schemaObj, context);\n }\n // array case\n else if (schemaObj?.type === 'object' || schemaObj?.oneOf || schemaObj?.allOf || !_.isEmpty(schemaObj.properties)) {\n result = this.createContainerType(parent, schemaObj, ref);\n }\n // scalar\n else {\n result = this.createScalarType(schemaObj, parent);\n }\n\n // we could not infer a proper type\n if (result == null) {\n throw new Error(`Not yet implemented for ${JSON.stringify(schemaObj)}`);\n }\n\n return result;\n }\n\n private static createScalarType(schema: SchemaObject | null, parent: IType) {\n const typeStr = schema?.type;\n if (typeStr != null) {\n if (typeStr === 'array') {\n throw new Error(`Should have been handled already? ${typeStr}, schema: ${JSON.stringify(schema)}`);\n } else if (schema?.enum != null) {\n return new En(parent, 'enum', schema, schema.enum! as string[]);\n }\n // scalar case\n else if (GqlUtils.gqlScalar(typeStr as string)) {\n const scalarType = GqlUtils.getGQLScalarType(schema!);\n return new Scalar(parent, scalarType, schema!);\n }\n // or we have no idea how to handle this\n else {\n throw new Error(`Cannot handle property type ${typeStr}, schema: ${JSON.stringify(schema)}`);\n }\n } else if (schema?.enum != null) {\n return new En(parent, 'enum', schema, _.get(schema, 'enum') as string[]);\n }\n // or we have no idea how to handle this\n else {\n throw new Error(`Cannot handle schema ${parent.pathToRoot()}, schema: ${JSON.stringify(schema)}`);\n }\n }\n\n private static createContainerType(parent: IType, schema: SchemaObject, ref?: string) {\n let result: IType | null;\n\n // composed object\n if (schema.allOf) {\n result = new Composed(parent, ref || _.get(schema, 'name'), schema);\n }\n // union\n else if (schema.oneOf) {\n const oneOfs = schema.oneOf || [];\n result = new Union(parent, ref || _.get(schema, 'name'), oneOfs as SchemaObject[]);\n }\n // or a plain obj\n else {\n if (!schema.properties) {\n warn(\n null,\n '[factory]',\n 'Object has no properties: ' + JSON.stringify(schema, null, 2) + ' in: ' + parent.pathToRoot(),\n );\n }\n\n result = new Obj(parent, ref || _.get(schema, 'name') || null, schema);\n\n // if we want to syntethise an object:\n if (schema.format == APOLLO_SYNTHETIC_OBJ) {\n (result as Obj).synthetic = true;\n }\n }\n\n return result;\n }\n\n private static createArrayType(parent: IType | Res, schema: SchemaObject | null, context: OasContext) {\n // Array schema case.\n let parentName = parent.name;\n if (parent instanceof Res) {\n const get = parent.parent as Get; // Assume parent.parent is a GetOp.\n parentName = _.upperFirst(get.getGqlOpName());\n }\n\n const arr = new Arr(parent, parentName);\n const items = _.get(schema, 'items') as ArraySchemaObject;\n arr.items = items;\n\n // TODO: check this\n arr.itemsType = Factory.fromSchema(context, arr, items);\n arr.add(arr.itemsType); // add it to the children\n\n return arr;\n }\n\n public static fromProp(\n context: OasContext,\n parent: IType,\n propName: string,\n inputSchema: SchemaObject | ReferenceObject,\n ): Prop {\n if (!inputSchema) {\n throw new Error(`Should have a schema defined for property '${propName}' (parent: '${parent.name}')`);\n }\n\n let schema: SchemaObject | ReferenceObject | null = inputSchema;\n\n let prop: Prop;\n let ref: string | undefined;\n\n if (!_.get(schema, 'type') && '$ref' in schema) {\n ref = (schema as ReferenceObject).$ref;\n schema = context.lookupRef(ref);\n // this was a prop ref, but now needs to be returned as the ref directly?\n // prop = new PropRef(parent, propName, schema, ref);\n // return prop;\n }\n\n // uses the type of the schema to find out what kind of property it is\n const schemaObj = schema as SchemaObject;\n const type = schemaObj.type;\n\n if (type) {\n // 1st case is if the type is an array\n if (type === 'array') {\n const array = new PropArray(parent, propName, schema!);\n // const itemsName = Naming.genArrayItems(propName);\n\n const itemsSchema = _.get(schemaObj, 'items') as ArraySchemaObject;\n // const itemsType = Factory.fromProp(context, array, itemsName, itemsSchema); // TODO: re-test\n const itemsType = Factory.fromSchema(context, array, itemsSchema);\n\n array.setItems(itemsType);\n prop = array;\n }\n // 2nd checks for obj property\n else if (\n schemaObj?.type === 'object' ||\n schemaObj?.oneOf ||\n schemaObj?.allOf ||\n !_.isEmpty(schemaObj.properties)\n ) {\n if (schemaObj.oneOf) {\n const inner: PropComp = new PropComp(parent, propName, schemaObj);\n inner.comp = new Union(inner, ref || _.get(schemaObj, 'name'), schemaObj.oneOf as SchemaObject[]);\n prop = inner;\n } else if (schemaObj.allOf) {\n const propComp: PropComp = new PropComp(parent, propName, schemaObj);\n propComp.comp = new Composed(propComp, ref || _.get(schemaObj, 'name'), schemaObj);\n prop = propComp;\n } else if (schemaObj.properties != null) {\n const propType: IType = new Obj(parent, ref || propName, schemaObj);\n prop = new PropObj(parent, propName, schemaObj, propType);\n } else {\n // the type of the property will be an object, which needs to be added as a child\n const propType: IType = new Obj(parent, ref || propName, schemaObj);\n prop = new PropObj(parent, propName, schemaObj, propType);\n }\n } else if (ref && schemaObj?.enum) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- for options\n const stringEnum = _.every(schemaObj.enum, (value: any, _: string) => typeof value === 'string');\n const en: En = new En(parent, ref, schemaObj, stringEnum ? (schemaObj.enum as string[]) : []);\n\n prop = new PropEn(parent, propName, ref, schemaObj);\n prop.add(en);\n }\n // 3rd tries for scalar\n else if (GqlUtils.gqlScalar(type as string)) {\n const scalar = GqlUtils.gqlScalar(type as string);\n prop = new PropScalar(parent, propName, scalar as string, schemaObj);\n }\n // or we don't know how to handle this\n else {\n throw new Error('Cannot handle property type ' + type);\n }\n }\n // otherwise let's use the properties instead and assume an Obj\n // TODO: repeated code\n else if (schemaObj.oneOf) {\n const inner: PropComp = new PropComp(parent, propName, schemaObj);\n inner.comp = new Union(inner, ref || _.get(schemaObj, 'name'), schemaObj.oneOf as SchemaObject[]);\n prop = inner;\n } else if (schemaObj.allOf) {\n const propComp: PropComp = new PropComp(parent, propName, schemaObj);\n propComp.comp = new Composed(propComp, ref || _.get(schemaObj, 'name'), schemaObj);\n prop = propComp;\n } else if (schemaObj.properties != null) {\n const propType: IType = new Obj(parent, ref || propName, schemaObj);\n prop = new PropObj(parent, propName, schemaObj, propType);\n }\n // default case, we don't know what to do so we'll create a scalar of type JSON\n else {\n prop = new PropScalar(parent, propName, 'JSON', schemaObj);\n }\n\n if (parent.ancestors().find((a) => a.id === prop.id)) {\n console.warn('[factory] Recursion detected! Ancestors already contain this type: \\n' + prop.id);\n prop = new PropCircRef(parent, prop);\n }\n\n return prop;\n }\n\n public static fromResponse(_context: OasContext, parent: IType, mediaSchema: SchemaObject): IType {\n return new Res(parent, 'r', mediaSchema);\n }\n\n public static fromParam(context: OasContext, parent: IType, p: ParameterObject | ReferenceObject): Param {\n let param: ParameterObject;\n\n if ('$ref' in p) {\n const ref: ReferenceObject = p as ReferenceObject;\n const schema = context.lookupParam(ref.$ref);\n\n if (!schema) {\n throw new Error('Schema not found for ref: ' + ref.$ref);\n }\n param = schema as ParameterObject;\n } else {\n param = p as ParameterObject;\n }\n\n const schema = param.schema as SchemaObject;\n const required = param.required === true;\n\n return new Param(parent, param.name, schema, required, schema.default, param);\n }\n\n public static fromCircularRef(parent: IType, child: IType): IType {\n const _tree = T.print(parent);\n\n const circularRef = new CircularRef(parent, child.name);\n circularRef.ref = child;\n return circularRef;\n }\n\n public static fromUnion(_context: OasContext, parent: IType, oneOfs: SchemaObject[]): IType {\n const union = new Union(parent, parent.name, oneOfs);\n parent.add(union);\n return union;\n }\n\n public static fromPost(name: string, op: Operation): Post {\n return new Post(name, op);\n }\n\n public static fromPut(name: string, op: Operation): Post {\n return new Put(name, op);\n }\n\n public static fromPatch(name: string, op: Operation): Post {\n return new Patch(name, op);\n }\n\n public static fromDelete(name: string, op: Operation): Post {\n return new Delete(name, op);\n }\n\n public static fromBody(_context: OasContext, parent: IType, schema: SchemaObject): IType {\n const body = new Body(parent, 'b', schema);\n parent.add(body);\n return body;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Prop } from './prop.js';
1
+ import { Prop } from './internal.js';
2
2
  import { OasContext } from '../oasContext.js';
3
3
  import { Writer } from '../io/writer.js';
4
4
  export type Kind = 'input' | 'type';
@@ -12,7 +12,7 @@ export interface IType {
12
12
  kind: Kind;
13
13
  visited: boolean;
14
14
  forPrompt(context: OasContext): string;
15
- add(child: IType): void;
15
+ add(child: IType): IType;
16
16
  ancestors(): IType[];
17
17
  visit(context: OasContext): void;
18
18
  generate(context: OasContext, writer: Writer, selection: string[]): void;
@@ -1 +1 @@
1
- {"version":3,"file":"iType.js","sourceRoot":"","sources":["../../../src/oas/nodes/iType.ts"],"names":[],"mappings":"","sourcesContent":["import { Prop } from './prop.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\n\nexport type Kind = 'input' | 'type';\n\nexport interface IType {\n name: string;\n parent?: IType;\n children: IType[];\n circularRef?: IType;\n props: Map<string, Prop>;\n id: string;\n kind: Kind;\n visited: boolean;\n\n forPrompt(context: OasContext): string;\n\n add(child: IType): void;\n\n ancestors(): IType[];\n\n visit(context: OasContext): void;\n\n generate(context: OasContext, writer: Writer, selection: string[]): void;\n\n pathToRoot(): string;\n\n path(): string;\n\n expand(context: OasContext): IType[];\n\n find(path: string, collection: IType[]): IType | boolean;\n\n select(context: OasContext, writer: Writer, selection: string[]): void;\n}\n"]}
1
+ {"version":3,"file":"iType.js","sourceRoot":"","sources":["../../../src/oas/nodes/iType.ts"],"names":[],"mappings":"","sourcesContent":["import { Prop } from './internal.js';\nimport { OasContext } from '../oasContext.js';\nimport { Writer } from '../io/writer.js';\n\nexport type Kind = 'input' | 'type';\n\nexport interface IType {\n name: string;\n parent?: IType;\n children: IType[];\n circularRef?: IType;\n props: Map<string, Prop>;\n id: string;\n kind: Kind;\n visited: boolean;\n\n forPrompt(context: OasContext): string;\n\n add(child: IType): IType;\n\n ancestors(): IType[];\n\n visit(context: OasContext): void;\n\n generate(context: OasContext, writer: Writer, selection: string[]): void;\n\n pathToRoot(): string;\n\n path(): string;\n\n expand(context: OasContext): IType[];\n\n find(path: string, collection: IType[]): IType | boolean;\n\n select(context: OasContext, writer: Writer, selection: string[]): void;\n}\n"]}
@@ -15,14 +15,14 @@ export { Patch } from './patch.js';
15
15
  export { Delete } from './delete.js';
16
16
  export { Body } from './body.js';
17
17
  export { Obj } from './obj.js';
18
- export { Ref } from './ref.js';
19
- export { Response } from './response.js';
18
+ export { Res } from './res.js';
20
19
  export { Scalar } from './scalar.js';
21
20
  export { Union } from './union.js';
22
21
  export { PropArray } from './propArray.js';
23
22
  export { PropObj } from './propObj.js';
24
23
  export { PropComp } from './propComp.js';
25
- export { PropRef } from './propRef.js';
24
+ export { PropCircRef } from './propCircRef.js';
25
+ export { PropEn } from './propEn.js';
26
26
  export { PropScalar } from './propScalar.js';
27
27
  export { T } from './typeUtils.js';
28
28
  export { type Op } from './op.js';