@tim-smart/openapi-gen 0.3.3 → 0.3.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 +20 -11
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -29405,7 +29405,7 @@ var make65 = gen2(function* () {
29405
29405
  current = current[key];
29406
29406
  }
29407
29407
  refStore.set(schema.$ref, current);
29408
- addRefs(current, "properties" in current ? name2 : void 0);
29408
+ addRefs(current, name2);
29409
29409
  store.set(name2, current);
29410
29410
  if (!asStruct2) {
29411
29411
  classes.add(name2);
@@ -29416,16 +29416,22 @@ var make65 = gen2(function* () {
29416
29416
  );
29417
29417
  } else if ("type" in schema && schema.type === "array") {
29418
29418
  if (Array.isArray(schema.items)) {
29419
- schema.items.forEach((s) => addRefs(s, childName));
29419
+ schema.items.forEach((s) => addRefs(s, void 0));
29420
29420
  } else if (schema.items) {
29421
- addRefs(schema.items, childName);
29421
+ addRefs(schema.items, void 0);
29422
29422
  }
29423
29423
  } else if ("allOf" in schema) {
29424
- schema.allOf.forEach((s) => addRefs(s, childName));
29424
+ schema.allOf.forEach(
29425
+ (s) => addRefs(s, childName ? childName + "Enum" : void 0)
29426
+ );
29425
29427
  } else if ("anyOf" in schema) {
29426
- schema.anyOf.forEach((s) => addRefs(s, childName));
29428
+ schema.anyOf.forEach(
29429
+ (s) => addRefs(s, childName ? childName + "Enum" : void 0)
29430
+ );
29427
29431
  } else if ("oneOf" in schema) {
29428
- schema.oneOf.forEach((s) => addRefs(s, childName));
29432
+ schema.oneOf.forEach(
29433
+ (s) => addRefs(s, childName ? childName + "Enum" : void 0)
29434
+ );
29429
29435
  } else if ("enum" in schema) {
29430
29436
  if (childName !== void 0) {
29431
29437
  store.set(childName, schema);
@@ -29471,7 +29477,7 @@ var make65 = gen2(function* () {
29471
29477
  map(
29472
29478
  applyAnnotations(S, {
29473
29479
  isOptional,
29474
- isNullable: "nullable" in fullSchema && fullSchema.nullable === true,
29480
+ isNullable: "nullable" in fullSchema && fullSchema.nullable === true || "default" in fullSchema && fullSchema.default === null,
29475
29481
  default: fullSchema.default
29476
29482
  })
29477
29483
  ),
@@ -29497,7 +29503,7 @@ var make65 = gen2(function* () {
29497
29503
  }
29498
29504
  const items = schema.enum.map((_) => JSON.stringify(_)).join(", ");
29499
29505
  return some2(`${S}.Literal(${items})`);
29500
- } else if ("type" in schema) {
29506
+ } else if ("type" in schema && schema.type) {
29501
29507
  switch (schema.type) {
29502
29508
  case "string": {
29503
29509
  const modifiers = [];
@@ -29570,7 +29576,7 @@ var make65 = gen2(function* () {
29570
29576
  } else if ("allOf" in schema) {
29571
29577
  const sources = pipe(
29572
29578
  schema.allOf,
29573
- filterMap2((_) => toSource(S, _, currentIdentifier))
29579
+ filterMap2((_) => toSource(S, _, currentIdentifier + "Enum"))
29574
29580
  );
29575
29581
  if (sources.length === 0) {
29576
29582
  return none2();
@@ -29586,7 +29592,7 @@ var make65 = gen2(function* () {
29586
29592
  } else if ("anyOf" in schema || "oneOf" in schema) {
29587
29593
  const sources = pipe(
29588
29594
  "anyOf" in schema ? schema.anyOf : schema.oneOf,
29589
- filterMap2((_) => toSource(S, _, currentIdentifier))
29595
+ filterMap2((_) => toSource(S, _, currentIdentifier + "Enum"))
29590
29596
  );
29591
29597
  if (sources.length === 0) return none2();
29592
29598
  else if (sources.length === 1) return some2(sources[0]);
@@ -29595,6 +29601,9 @@ var make65 = gen2(function* () {
29595
29601
  return none2();
29596
29602
  };
29597
29603
  const applyAnnotations = (S, options3) => (source) => {
29604
+ if (options3.isNullable && options3.default === null) {
29605
+ return `${S}.optionalWith(${source}, { nullable: true, default: () => null })`;
29606
+ }
29598
29607
  const defaultSource = options3.default !== void 0 && options3.default !== null ? `() => ${JSON.stringify(options3.default)} as const` : void 0;
29599
29608
  if (options3.isOptional) {
29600
29609
  return defaultSource ? `${S}.optionalWith(${source}, { nullable: true, default: ${defaultSource} })` : `${S}.optionalWith(${source}, { nullable: true })`;
@@ -29857,7 +29866,7 @@ var operationToImpl = (operation) => {
29857
29866
  }
29858
29867
  if (operation.headers.length > 0) {
29859
29868
  const props = operation.headers.map(
29860
- (param) => `"${param}": ${varName}["${param}"]`
29869
+ (param) => `"${param}": ${varName}["${param}"] ?? undefined`
29861
29870
  );
29862
29871
  pipeline.push(`HttpClientRequest.setHeaders({ ${props.join(", ")} })`);
29863
29872
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-smart/openapi-gen",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Generate Effect http clients from OpenAPI specs",
5
5
  "bin": "main.js",
6
6
  "repository": {