apollo-conn-gen 0.4.4 → 0.4.5

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.
@@ -18,6 +18,7 @@ export declare class OasContext {
18
18
  refCount: Map<string, number>;
19
19
  private parser;
20
20
  constructor(parser: Oas, options?: GenerateOptions);
21
+ reset(): void;
21
22
  enter(type: IType): void;
22
23
  leave(type: IType): void;
23
24
  size(): number;
@@ -19,6 +19,14 @@ export class OasContext {
19
19
  showParentInSelections: true, // by default, we don't show where the fields are coming from
20
20
  };
21
21
  }
22
+ // reset the state of the context
23
+ reset() {
24
+ this.indent = 0;
25
+ this.stack = new Array();
26
+ this.types.clear();
27
+ this.refCount.clear();
28
+ this.generatedSet.clear();
29
+ }
22
30
  enter(type) {
23
31
  this.stack.push(type);
24
32
  trace(this, '-> [context::enter]', type.id);
@@ -1 +1 @@
1
- {"version":3,"file":"oasContext.js","sourceRoot":"","sources":["../../src/oas/oasContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAQ,MAAM,gBAAgB,CAAC;AAI7C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAQ3C,MAAM,OAAO,UAAU;IACd,MAAM,CAAU,kBAAkB,GAAW,uBAAuB,CAAC;IACrE,MAAM,CAAU,oBAAoB,GAAW,yBAAyB,CAAC;IACzE,MAAM,CAAU,iBAAiB,GAAW,0BAA0B,CAAC;IAEvE,YAAY,GAAgB,IAAI,GAAG,EAAE,CAAC;IACtC,MAAM,CAAS;IAEf,KAAK,GAAY,IAAI,KAAK,EAAS,CAAC;IACpC,KAAK,GAAmC,IAAI,GAAG,EAAE,CAAC;IAClD,eAAe,CAAkB;IACjC,QAAQ,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEzC,MAAM,CAAM;IAEpB,YAAY,MAAW,EAAE,OAAyB;QAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,C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CAAC;YACrC,OAAQ,UAAU,CAAC,IAAI,CAAqB,IAAI,KAAK,CAAC;QACxD,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,WAAW,CAAC,IAAY,EAAE,IAAW;QAC1C,UAAU;QACV,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAChD,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC3B,SAAS;YACX,CAAC;YAED,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBAC5C,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC","sourcesContent":["import { trace, warn } from './log/trace.js';\nimport Oas from 'oas';\nimport { ParameterObject, ResponseObject, SchemaObject } from 'oas/types';\nimport { ReferenceObject } from './nodes/internal.js';\nimport { Naming } from './utils/naming.js';\nimport { IType } from './nodes/internal.js';\n\nexport type GenerateOptions = {\n consolidateUnions: boolean;\n showParentInSelections: boolean;\n};\n\nexport class OasContext {\n public static readonly COMPONENTS_SCHEMAS: string = '#/components/schemas/';\n public static readonly COMPONENTS_RESPONSES: string = '#/components/responses/';\n public static readonly PARAMETER_SCHEMAS: string = '#/components/parameters/';\n\n public generatedSet: Set<string> = new Set();\n public indent: number;\n\n public stack: IType[] = new Array<IType>();\n public types: Map<string, IType | undefined> = new Map();\n public generateOptions: GenerateOptions;\n public refCount: Map<string, number> = new Map();\n\n private parser: Oas;\n\n constructor(parser: Oas, options?: GenerateOptions) {\n this.parser = parser;\n this.indent = 0;\n this.generateOptions = options || {\n consolidateUnions: true, // by default, we consolidate fields until unions are supported\n showParentInSelections: true, // by default, we don't show where the fields are coming from\n };\n }\n\n public enter(type: IType): void {\n this.stack.push(type);\n trace(this, '-> [context::enter]', type.id);\n }\n\n public leave(type: IType): void {\n this.stack.pop();\n trace(this, '<- [context::leave]', type.id);\n }\n\n public size() {\n return this.stack.length;\n }\n\n public store(name: string, type: IType): void {\n trace(this, '[context::store]', 'store ' + type.id);\n this.types.set(name, undefined);\n }\n\n public lookupResponse(ref: string): ResponseObject | ReferenceObject | null {\n if (ref && ref.startsWith(OasContext.COMPONENTS_RESPONSES)) {\n const definition = this.parser.getDefinition();\n const responses = definition.components?.responses ?? {};\n\n // get the response schema\n return responses[Naming.getRefName(ref)!] ?? null;\n }\n\n return null;\n }\n\n public lookupRef(ref: string | null): SchemaObject | null {\n if (ref && ref.startsWith(OasContext.COMPONENTS_SCHEMAS)) {\n const currentCount = this.refCount.get(ref) || 0;\n this.refCount.set(ref, currentCount + 1);\n\n const definition = this.parser.getDefinition();\n const schemas = definition.components?.schemas ?? {};\n\n return schemas ? schemas[Naming.getRefName(ref)!] : null;\n }\n\n return null;\n }\n\n public decRefCount(ref: string): void {\n if (ref && ref.startsWith(OasContext.COMPONENTS_SCHEMAS)) {\n const currentCount = this.refCount.get(ref) || 0;\n if (currentCount > 0) {\n this.refCount.set(ref, currentCount - 1);\n }\n }\n }\n\n public lookupParam(ref: string): ParameterObject | boolean {\n if (ref && ref.startsWith(OasContext.PARAMETER_SCHEMAS)) {\n const definition = this.parser.getDefinition();\n const parameters = definition.components?.parameters ?? {};\n\n // get the parameter schema\n const name = Naming.getRefName(ref)!;\n return (parameters[name] as ParameterObject) ?? false;\n }\n\n return false;\n }\n\n public inContextOf(type: string, node: IType): boolean {\n // console\n for (let i = this.stack.length - 1; i >= 0; i--) {\n if (this.stack[i] === node) {\n continue;\n }\n\n if (this.stack[i].constructor.name === type) {\n return true;\n }\n }\n\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"oasContext.js","sourceRoot":"","sources":["../../src/oas/oasContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAQ,MAAM,gBAAgB,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IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBAC5C,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC","sourcesContent":["import { trace, warn } from './log/trace.js';\nimport Oas from 'oas';\nimport { ParameterObject, ResponseObject, SchemaObject } from 'oas/types';\nimport { ReferenceObject } from './nodes/internal.js';\nimport { Naming } from './utils/naming.js';\nimport { IType } from './nodes/internal.js';\n\nexport type GenerateOptions = {\n consolidateUnions: boolean;\n showParentInSelections: boolean;\n};\n\nexport class OasContext {\n public static readonly COMPONENTS_SCHEMAS: string = '#/components/schemas/';\n public static readonly COMPONENTS_RESPONSES: string = '#/components/responses/';\n public static readonly PARAMETER_SCHEMAS: string = '#/components/parameters/';\n\n public generatedSet: Set<string> = new Set();\n public indent: number;\n\n public stack: IType[] = new Array<IType>();\n public types: Map<string, IType | undefined> = new Map();\n public generateOptions: GenerateOptions;\n public refCount: Map<string, number> = new Map();\n\n private parser: Oas;\n\n constructor(parser: Oas, options?: GenerateOptions) {\n this.parser = parser;\n this.indent = 0;\n this.generateOptions = options || {\n consolidateUnions: true, // by default, we consolidate fields until unions are supported\n showParentInSelections: true, // by default, we don't show where the fields are coming from\n };\n }\n\n // reset the state of the context\n public reset(): void {\n this.indent = 0;\n this.stack = new Array<IType>();\n this.types.clear();\n this.refCount.clear();\n this.generatedSet.clear();\n }\n\n public enter(type: IType): void {\n this.stack.push(type);\n trace(this, '-> [context::enter]', type.id);\n }\n\n public leave(type: IType): void {\n this.stack.pop();\n trace(this, '<- [context::leave]', type.id);\n }\n\n public size() {\n return this.stack.length;\n }\n\n public store(name: string, type: IType): void {\n trace(this, '[context::store]', 'store ' + type.id);\n this.types.set(name, undefined);\n }\n\n public lookupResponse(ref: string): ResponseObject | ReferenceObject | null {\n if (ref && ref.startsWith(OasContext.COMPONENTS_RESPONSES)) {\n const definition = this.parser.getDefinition();\n const responses = definition.components?.responses ?? {};\n\n // get the response schema\n return responses[Naming.getRefName(ref)!] ?? null;\n }\n\n return null;\n }\n\n public lookupRef(ref: string | null): SchemaObject | null {\n if (ref && ref.startsWith(OasContext.COMPONENTS_SCHEMAS)) {\n const currentCount = this.refCount.get(ref) || 0;\n this.refCount.set(ref, currentCount + 1);\n\n const definition = this.parser.getDefinition();\n const schemas = definition.components?.schemas ?? {};\n\n return schemas ? schemas[Naming.getRefName(ref)!] : null;\n }\n\n return null;\n }\n\n public decRefCount(ref: string): void {\n if (ref && ref.startsWith(OasContext.COMPONENTS_SCHEMAS)) {\n const currentCount = this.refCount.get(ref) || 0;\n if (currentCount > 0) {\n this.refCount.set(ref, currentCount - 1);\n }\n }\n }\n\n public lookupParam(ref: string): ParameterObject | boolean {\n if (ref && ref.startsWith(OasContext.PARAMETER_SCHEMAS)) {\n const definition = this.parser.getDefinition();\n const parameters = definition.components?.parameters ?? {};\n\n // get the parameter schema\n const name = Naming.getRefName(ref)!;\n return (parameters[name] as ParameterObject) ?? false;\n }\n\n return false;\n }\n\n public inContextOf(type: string, node: IType): boolean {\n // console\n for (let i = this.stack.length - 1; i >= 0; i--) {\n if (this.stack[i] === node) {\n continue;\n }\n\n if (this.stack[i].constructor.name === type) {\n return true;\n }\n }\n\n return false;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apollo-conn-gen",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Library to generate Apollo connector schemas from OpenAPI specs or JSON payloads. Also includes a CLI to generate connectors from the command line.",
5
5
  "author": "Fernando @ Apollo",
6
6
  "license": "MIT",