@tim-smart/openapi-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.
Files changed (2) hide show
  1. package/main.js +55 -38
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -34825,18 +34825,37 @@ var make64 = gen2(function* () {
34825
34825
  const refStore = /* @__PURE__ */ new Map();
34826
34826
  function cleanupSchema(schema) {
34827
34827
  if ("type" in schema && Array.isArray(schema.type) && schema.type.includes("null")) {
34828
- schema.type = schema.type.filter((_) => _ !== "null")[0];
34829
- schema.nullable = true;
34828
+ schema = {
34829
+ ...schema,
34830
+ type: schema.type.filter((_) => _ !== "null"),
34831
+ nullable: true
34832
+ };
34830
34833
  }
34831
34834
  if ("type" in schema && "oneOf" in schema && Array.isArray(schema.oneOf) && schema.oneOf.length === 0) {
34832
- delete schema.oneOf;
34835
+ schema = omit3(schema, "oneOf");
34836
+ }
34837
+ if ("allOf" in schema && schema.allOf.length === 1 || "oneOf" in schema && schema.oneOf.length === 1 || "anyOf" in schema && schema.anyOf.length === 1) {
34838
+ if ("allOf" in schema) {
34839
+ const item = schema.allOf[0];
34840
+ schema = omit3(schema, "allOf");
34841
+ Object.assign(schema, item);
34842
+ } else if ("anyOf" in schema) {
34843
+ const item = schema.anyOf[0];
34844
+ schema = omit3(schema, "anyOf");
34845
+ Object.assign(schema, item);
34846
+ } else {
34847
+ const item = schema.oneOf[0];
34848
+ schema = omit3(schema, "oneOf");
34849
+ Object.assign(schema, item);
34850
+ }
34833
34851
  }
34834
34852
  return schema;
34835
34853
  }
34836
34854
  const addSchema = (name2, root2, context7, asStruct = false) => {
34837
- cleanupSchema(root2);
34855
+ root2 = cleanupSchema(root2);
34838
34856
  function addRefs(schema, childName, asStruct2 = true) {
34839
- cleanupSchema(schema);
34857
+ schema = cleanupSchema(schema);
34858
+ const enumSuffix = childName?.endsWith("Enum") ? "" : "Enum";
34840
34859
  if ("$ref" in schema) {
34841
34860
  const resolved = resolveRef(schema, {
34842
34861
  ...root2,
@@ -34865,32 +34884,26 @@ var make64 = gen2(function* () {
34865
34884
  addRefs(schema.items, void 0);
34866
34885
  }
34867
34886
  } else if ("allOf" in schema) {
34868
- if (schema.allOf.length === 1) {
34869
- const resolved = { ...schema, ...schema.allOf[0] };
34870
- delete resolved.allOf;
34871
- addRefs(resolved, childName, asStruct2);
34887
+ const resolved = resolveAllOf(schema, {
34888
+ ...root2,
34889
+ ...context7
34890
+ });
34891
+ if (childName !== void 0) {
34892
+ addRefs(resolved, childName + enumSuffix, asStruct2);
34893
+ store.set(childName, resolved);
34872
34894
  } else {
34873
- const resolved = resolveAllOf(schema, {
34874
- ...root2,
34875
- ...context7
34876
- });
34877
- if (childName !== void 0) {
34878
- addRefs(resolved, childName + "Enum", asStruct2);
34879
- store.set(childName, resolved);
34880
- } else {
34881
- addRefs(resolved, void 0, asStruct2);
34882
- }
34895
+ addRefs(resolved, void 0, asStruct2);
34883
34896
  }
34884
34897
  } else if ("anyOf" in schema) {
34885
34898
  schema.anyOf.forEach(
34886
- (s) => addRefs(s, childName ? childName + "Enum" : void 0)
34899
+ (s) => addRefs(s, childName ? childName + enumSuffix : void 0)
34887
34900
  );
34888
34901
  } else if ("oneOf" in schema) {
34889
34902
  schema.oneOf.forEach(
34890
- (s) => addRefs(s, childName ? childName + "Enum" : void 0)
34903
+ (s) => addRefs(s, childName ? childName + enumSuffix : void 0)
34891
34904
  );
34892
34905
  } else if ("enum" in schema) {
34893
- if (childName !== void 0) {
34906
+ if (childName !== void 0 && !("const" in schema)) {
34894
34907
  store.set(childName, schema);
34895
34908
  enums.add(childName);
34896
34909
  }
@@ -34954,6 +34967,10 @@ var make64 = gen2(function* () {
34954
34967
  };
34955
34968
  const transformer = yield* JsonSchemaTransformer;
34956
34969
  const toSource = (importName, schema, currentIdentifier, topLevel = false) => {
34970
+ schema = cleanupSchema(schema);
34971
+ if (currentIdentifier.startsWith("FunctionCall")) {
34972
+ console.error(schema, currentIdentifier);
34973
+ }
34957
34974
  if ("properties" in schema) {
34958
34975
  const obj = schema;
34959
34976
  const required2 = obj.required ?? [];
@@ -34990,11 +35007,22 @@ var make64 = gen2(function* () {
34990
35007
  return some2(transformer.onNull({ importName }));
34991
35008
  } else if ("type" in schema && schema.type === "object") {
34992
35009
  return some2(transformer.onRecord({ importName }));
35010
+ } else if ("const" in schema) {
35011
+ return some2(
35012
+ transformer.onEnum({
35013
+ importName,
35014
+ items: [JSON.stringify(schema.const)]
35015
+ })
35016
+ );
34993
35017
  } else if ("enum" in schema) {
34994
35018
  if (!topLevel && enums.has(currentIdentifier)) {
34995
35019
  return some2(
34996
35020
  transformer.onRef({ importName, name: currentIdentifier })
34997
35021
  );
35022
+ } else if (!topLevel && enums.has(currentIdentifier + "Enum")) {
35023
+ return some2(
35024
+ transformer.onRef({ importName, name: currentIdentifier + "Enum" })
35025
+ );
34998
35026
  }
34999
35027
  const items = schema.enum.map((_) => JSON.stringify(_));
35000
35028
  return some2(
@@ -35025,13 +35053,6 @@ var make64 = gen2(function* () {
35025
35053
  const sources = schema.allOf;
35026
35054
  if (sources.length === 0) {
35027
35055
  return none2();
35028
- } else if (sources.length === 1) {
35029
- return toSource(
35030
- importName,
35031
- sources[0],
35032
- currentIdentifier + "Enum",
35033
- topLevel
35034
- );
35035
35056
  }
35036
35057
  const flattened2 = flattenAllOf(schema);
35037
35058
  return toSource(
@@ -35068,16 +35089,12 @@ var make64 = gen2(function* () {
35068
35089
  )
35069
35090
  )
35070
35091
  );
35071
- if (items.length === 0) return none2();
35072
- else if (items.length === 1) return some2(items[0].source);
35092
+ if (items.length === 0) {
35093
+ return none2();
35094
+ } else if (items.length === 1) {
35095
+ return some2(items[0].source);
35096
+ }
35073
35097
  return some2(transformer.onUnion({ importName, items, topLevel }));
35074
- } else if ("const" in schema) {
35075
- return some2(
35076
- transformer.onEnum({
35077
- importName,
35078
- items: [JSON.stringify(schema.const)]
35079
- })
35080
- );
35081
35098
  } else if ("type" in schema && schema.type) {
35082
35099
  switch (schema.type) {
35083
35100
  case "string": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-smart/openapi-gen",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Generate Effect http clients from OpenAPI specs",
5
5
  "bin": "main.js",
6
6
  "repository": {