@tim-smart/openapi-gen 0.3.9 → 0.3.10

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 +70 -21
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -29969,27 +29969,21 @@ var make63 = gen2(function* () {
29969
29969
  const addSchema = (name, root2, context7, asStruct = false) => {
29970
29970
  function addRefs(schema, childName, asStruct2 = true) {
29971
29971
  if ("$ref" in schema) {
29972
- if (!schema.$ref.startsWith("#")) {
29972
+ const resolved = resolveRef(schema, {
29973
+ ...root2,
29974
+ ...context7
29975
+ });
29976
+ if (!resolved) {
29973
29977
  return;
29974
29978
  }
29975
- const path2 = schema.$ref.slice(2).split("/");
29976
- const name2 = identifier2(path2[path2.length - 1]);
29977
- if (store.has(name2)) {
29979
+ if (store.has(resolved.name)) {
29978
29980
  return;
29979
29981
  }
29980
- let current = {
29981
- ...root2,
29982
- ...context7
29983
- };
29984
- for (const key of path2) {
29985
- if (!current) return;
29986
- current = current[key];
29987
- }
29988
- refStore.set(schema.$ref, current);
29989
- addRefs(current, name2);
29990
- store.set(name2, current);
29982
+ refStore.set(schema.$ref, resolved.schema);
29983
+ addRefs(resolved.schema, resolved.name);
29984
+ store.set(resolved.name, resolved.schema);
29991
29985
  if (!asStruct2) {
29992
- classes.add(name2);
29986
+ classes.add(resolved.name);
29993
29987
  }
29994
29988
  } else if ("properties" in schema) {
29995
29989
  Object.entries(schema.properties).forEach(
@@ -30002,9 +29996,16 @@ var make63 = gen2(function* () {
30002
29996
  addRefs(schema.items, void 0);
30003
29997
  }
30004
29998
  } else if ("allOf" in schema) {
30005
- schema.allOf.forEach(
30006
- (s) => addRefs(s, childName ? childName + "Enum" : void 0)
30007
- );
29999
+ const resolved = resolveAllOf(schema, {
30000
+ ...root2,
30001
+ ...context7
30002
+ });
30003
+ if (childName !== void 0) {
30004
+ addRefs(resolved, childName + "Enum", asStruct2);
30005
+ store.set(childName, resolved);
30006
+ } else {
30007
+ addRefs(resolved, void 0, asStruct2);
30008
+ }
30008
30009
  } else if ("anyOf" in schema) {
30009
30010
  schema.anyOf.forEach(
30010
30011
  (s) => addRefs(s, childName ? childName + "Enum" : void 0)
@@ -30037,7 +30038,7 @@ var make63 = gen2(function* () {
30037
30038
  const isEnum = enums.has(name);
30038
30039
  return toSource(S, schema, name, isClass || isEnum).pipe(
30039
30040
  map2((source) => {
30040
- const isObject2 = "properties" in schema || "allOf" in schema;
30041
+ const isObject2 = "properties" in schema;
30041
30042
  if (!isObject2 || !isClass) {
30042
30043
  return `export class ${name} extends ${source} {}`;
30043
30044
  }
@@ -30175,6 +30176,9 @@ var make63 = gen2(function* () {
30175
30176
  topLevel
30176
30177
  );
30177
30178
  } else if ("allOf" in schema) {
30179
+ if (store.has(currentIdentifier)) {
30180
+ return some2(currentIdentifier);
30181
+ }
30178
30182
  const sources = schema.allOf;
30179
30183
  if (sources.length === 0) {
30180
30184
  return none2();
@@ -30245,12 +30249,56 @@ function mergeSchemas(self, other) {
30245
30249
  },
30246
30250
  required: [...other.required || [], ...self.required || []]
30247
30251
  };
30252
+ } else if ("anyOf" in self && "anyOf" in other) {
30253
+ return {
30254
+ ...other,
30255
+ ...self,
30256
+ anyOf: [...self.anyOf, ...other.anyOf]
30257
+ };
30248
30258
  }
30249
30259
  return {
30250
30260
  ...self,
30251
30261
  ...other
30252
30262
  };
30253
30263
  }
30264
+ function resolveAllOf(schema, context7, resolveRefs = true) {
30265
+ if ("$ref" in schema) {
30266
+ const resolved = resolveRef(schema, context7, resolveRefs);
30267
+ if (!resolved) {
30268
+ return schema;
30269
+ }
30270
+ return resolved.schema;
30271
+ } else if ("allOf" in schema) {
30272
+ if (schema.allOf.length <= 1) {
30273
+ let out2 = { ...schema };
30274
+ delete out2.allOf;
30275
+ if (schema.allOf.length === 0) {
30276
+ return out2;
30277
+ }
30278
+ Object.assign(out2, schema.allOf[0]);
30279
+ return resolveAllOf(out2, context7, resolveRefs);
30280
+ }
30281
+ let out = {};
30282
+ for (const member of schema.allOf) {
30283
+ out = mergeSchemas(out, resolveAllOf(member, context7, resolveRefs));
30284
+ }
30285
+ return out;
30286
+ }
30287
+ return schema;
30288
+ }
30289
+ function resolveRef(schema, context7, recursive = false) {
30290
+ if (!schema.$ref.startsWith("#")) {
30291
+ return;
30292
+ }
30293
+ const path2 = schema.$ref.slice(2).split("/");
30294
+ const name = identifier2(path2[path2.length - 1]);
30295
+ let current = context7;
30296
+ for (const key of path2) {
30297
+ if (!current) return;
30298
+ current = current[key];
30299
+ }
30300
+ return { name, schema: resolveAllOf(current, context7, recursive) };
30301
+ }
30254
30302
 
30255
30303
  // src/OpenApi.ts
30256
30304
  var methodNames = [
@@ -30369,6 +30417,7 @@ var make64 = gen2(function* () {
30369
30417
  'import * as HttpClientError from "@effect/platform/HttpClientError"',
30370
30418
  'import * as HttpClientRequest from "@effect/platform/HttpClientRequest"',
30371
30419
  'import * as HttpClientResponse from "@effect/platform/HttpClientResponse"',
30420
+ 'import * as UrlParams from "@effect/platform/UrlParams"',
30372
30421
  'import * as Effect from "effect/Effect"',
30373
30422
  'import type { ParseError } from "effect/ParseResult"',
30374
30423
  'import * as S from "effect/Schema"'
@@ -30474,7 +30523,7 @@ var operationToImpl = (operation) => {
30474
30523
  const varName = operation.payload ? "options.params" : "options";
30475
30524
  if (operation.urlParams.length > 0) {
30476
30525
  const props = operation.urlParams.map(
30477
- (param) => `"${param}": ${varName}["${param}"]`
30526
+ (param) => `"${param}": ${varName}["${param}"] as UrlParams.Coercible`
30478
30527
  );
30479
30528
  pipeline.push(`HttpClientRequest.setUrlParams({ ${props.join(", ")} })`);
30480
30529
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-smart/openapi-gen",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "description": "Generate Effect http clients from OpenAPI specs",
5
5
  "bin": "main.js",
6
6
  "repository": {