@tim-smart/openapi-gen 0.4.1 → 0.4.3

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 +107 -23
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -7344,15 +7344,15 @@ var require_swagger2openapi = __commonJS({
7344
7344
  scheme.scheme = "basic";
7345
7345
  }
7346
7346
  if (scheme.type === "oauth2") {
7347
- let flow = {};
7347
+ let flow2 = {};
7348
7348
  let flowName = scheme.flow;
7349
7349
  if (scheme.flow === "application") flowName = "clientCredentials";
7350
7350
  if (scheme.flow === "accessCode") flowName = "authorizationCode";
7351
- if (typeof scheme.authorizationUrl !== "undefined") flow.authorizationUrl = scheme.authorizationUrl.split("?")[0].trim() || "/";
7352
- if (typeof scheme.tokenUrl === "string") flow.tokenUrl = scheme.tokenUrl.split("?")[0].trim() || "/";
7353
- flow.scopes = scheme.scopes || {};
7351
+ if (typeof scheme.authorizationUrl !== "undefined") flow2.authorizationUrl = scheme.authorizationUrl.split("?")[0].trim() || "/";
7352
+ if (typeof scheme.tokenUrl === "string") flow2.tokenUrl = scheme.tokenUrl.split("?")[0].trim() || "/";
7353
+ flow2.scopes = scheme.scopes || {};
7354
7354
  scheme.flows = {};
7355
- scheme.flows[flowName] = flow;
7355
+ scheme.flows[flowName] = flow2;
7356
7356
  delete scheme.flow;
7357
7357
  delete scheme.authorizationUrl;
7358
7358
  delete scheme.tokenUrl;
@@ -8556,6 +8556,45 @@ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
8556
8556
  }
8557
8557
  }
8558
8558
  }
8559
+ function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
8560
+ switch (arguments.length) {
8561
+ case 1:
8562
+ return ab;
8563
+ case 2:
8564
+ return function() {
8565
+ return bc(ab.apply(this, arguments));
8566
+ };
8567
+ case 3:
8568
+ return function() {
8569
+ return cd(bc(ab.apply(this, arguments)));
8570
+ };
8571
+ case 4:
8572
+ return function() {
8573
+ return de(cd(bc(ab.apply(this, arguments))));
8574
+ };
8575
+ case 5:
8576
+ return function() {
8577
+ return ef(de(cd(bc(ab.apply(this, arguments)))));
8578
+ };
8579
+ case 6:
8580
+ return function() {
8581
+ return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
8582
+ };
8583
+ case 7:
8584
+ return function() {
8585
+ return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
8586
+ };
8587
+ case 8:
8588
+ return function() {
8589
+ return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
8590
+ };
8591
+ case 9:
8592
+ return function() {
8593
+ return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
8594
+ };
8595
+ }
8596
+ return;
8597
+ }
8559
8598
 
8560
8599
  // node_modules/.pnpm/effect@3.15.2/node_modules/effect/dist/esm/Equivalence.js
8561
8600
  var make = (isEquivalent) => (self, that) => self === that || isEquivalent(self, that);
@@ -19317,6 +19356,8 @@ var capitalize = (self) => {
19317
19356
  if (self.length === 0) return self;
19318
19357
  return toUpperCase(self[0]) + self.slice(1);
19319
19358
  };
19359
+ var trim = (self) => self.trim();
19360
+ var isNonEmpty5 = (self) => self.length > 0;
19320
19361
 
19321
19362
  // node_modules/.pnpm/effect@3.15.2/node_modules/effect/dist/esm/internal/schedule.js
19322
19363
  var ScheduleSymbolKey = "effect/Schedule";
@@ -20624,10 +20665,10 @@ var formatUnknown = (u, checkCircular = true) => {
20624
20665
  }
20625
20666
  };
20626
20667
  var formatPropertyKey = (name2) => typeof name2 === "string" ? JSON.stringify(name2) : String(name2);
20627
- var isNonEmpty5 = (x) => Array.isArray(x);
20668
+ var isNonEmpty6 = (x) => Array.isArray(x);
20628
20669
  var isSingle = (x) => !Array.isArray(x);
20629
20670
  var formatPathKey = (key) => `[${formatPropertyKey(key)}]`;
20630
- var formatPath = (path2) => isNonEmpty5(path2) ? path2.map(formatPathKey).join("") : formatPathKey(path2);
20671
+ var formatPath = (path2) => isNonEmpty6(path2) ? path2.map(formatPathKey).join("") : formatPathKey(path2);
20631
20672
 
20632
20673
  // node_modules/.pnpm/effect@3.15.2/node_modules/effect/dist/esm/internal/schema/errors.js
20633
20674
  var getErrorMessage = (reason, details, path2, ast) => {
@@ -22895,7 +22936,7 @@ var formatTree = (issue) => {
22895
22936
  return right2(makeTree(message));
22896
22937
  }
22897
22938
  const parseIssueTitle = getParseIssueTitle(issue);
22898
- return isNonEmpty5(issue.issues) ? map18(forEach8(issue.issues, formatTree), (forest) => makeTree(parseIssueTitle, forest)) : map18(formatTree(issue.issues), (tree) => makeTree(parseIssueTitle, [tree]));
22939
+ return isNonEmpty6(issue.issues) ? map18(forEach8(issue.issues, formatTree), (forest) => makeTree(parseIssueTitle, forest)) : map18(formatTree(issue.issues), (tree) => makeTree(parseIssueTitle, [tree]));
22899
22940
  });
22900
22941
  }
22901
22942
  };
@@ -34868,7 +34909,7 @@ var make64 = gen2(function* () {
34868
34909
  (source) => transformer.onTopLevel({
34869
34910
  importName,
34870
34911
  schema,
34871
- description: fromNullable(schema.description),
34912
+ description: nonEmptyString3(schema.description),
34872
34913
  name: name2,
34873
34914
  source,
34874
34915
  isClass,
@@ -34907,19 +34948,20 @@ var make64 = gen2(function* () {
34907
34948
  filterMap2(([key, schema2]) => {
34908
34949
  const fullSchema = getSchema(schema2);
34909
34950
  const isOptional = !required2.includes(key);
34951
+ const [enumNullable, filteredSchema] = filterNullable(fullSchema);
34910
34952
  return toSource(
34911
34953
  importName,
34912
- schema2,
34954
+ enumNullable ? filteredSchema : schema2,
34913
34955
  currentIdentifier + identifier2(key)
34914
34956
  ).pipe(
34915
34957
  map2(
34916
34958
  (source) => transformer.onProperty({
34917
34959
  importName,
34918
- description: fromNullable(schema2.description),
34960
+ description: nonEmptyString3(schema2.description),
34919
34961
  key,
34920
34962
  source,
34921
34963
  isOptional,
34922
- isNullable: "nullable" in fullSchema && fullSchema.nullable === true || "default" in fullSchema && fullSchema.default === null,
34964
+ isNullable: enumNullable || "nullable" in fullSchema && fullSchema.nullable === true || "default" in fullSchema && fullSchema.default === null,
34923
34965
  default: fullSchema.default
34924
34966
  })
34925
34967
  )
@@ -34985,14 +35027,27 @@ var make64 = gen2(function* () {
34985
35027
  topLevel
34986
35028
  );
34987
35029
  } else if ("anyOf" in schema || "oneOf" in schema) {
35030
+ let itemSchemas = "anyOf" in schema ? schema.anyOf : schema.oneOf;
35031
+ let typePrimitives = 0;
35032
+ const constItems = empty2();
35033
+ for (const item of itemSchemas) {
35034
+ if ("type" in item && item.type !== "null") {
35035
+ typePrimitives++;
35036
+ } else if ("const" in item) {
35037
+ constItems.push(item);
35038
+ }
35039
+ }
35040
+ if (typePrimitives <= 1 && constItems.length > 0 && constItems.length + typePrimitives === itemSchemas.length) {
35041
+ itemSchemas = constItems;
35042
+ }
34988
35043
  const items = pipe(
34989
- "anyOf" in schema ? schema.anyOf : schema.oneOf,
35044
+ itemSchemas,
34990
35045
  filterMap2(
34991
35046
  (_) => toSource(importName, _, currentIdentifier + "Enum").pipe(
34992
35047
  map2(
34993
35048
  (source) => ({
34994
- description: fromNullable(_.description),
34995
- title: fromNullable(_.title),
35049
+ description: nonEmptyString3(_.description),
35050
+ title: nonEmptyString3(_.title),
34996
35051
  source
34997
35052
  })
34998
35053
  )
@@ -35099,12 +35154,12 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
35099
35154
  supportsTopLevel({ isClass, isEnum }) {
35100
35155
  return isClass || isEnum;
35101
35156
  },
35102
- onTopLevel({ importName, schema, name: name2, source, isClass }) {
35157
+ onTopLevel({ importName, schema, name: name2, source, isClass, description }) {
35103
35158
  const isObject2 = "properties" in schema;
35104
35159
  if (!isObject2 || !isClass) {
35105
- return `export class ${name2} extends ${source} {}`;
35160
+ return `${toComment(description)}export class ${name2} extends ${source} {}`;
35106
35161
  }
35107
- return `export class ${name2} extends ${importName}.Class<${name2}>("${name2}")(${source}) {}`;
35162
+ return `${toComment(description)}export class ${name2} extends ${importName}.Class<${name2}>("${name2}")(${source}) {}`;
35108
35163
  },
35109
35164
  propertySeparator: ",\n ",
35110
35165
  onProperty: (options3) => {
@@ -35112,7 +35167,7 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
35112
35167
  options3.importName,
35113
35168
  options3
35114
35169
  )(options3.source);
35115
- return `"${options3.key}": ${source}`;
35170
+ return `${toComment(options3.description)}"${options3.key}": ${source}`;
35116
35171
  },
35117
35172
  onRef({ name: name2 }) {
35118
35173
  return name2;
@@ -35163,12 +35218,12 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
35163
35218
  const modifiers = [];
35164
35219
  if (minimum !== void 0) {
35165
35220
  modifiers.push(
35166
- `${importName}.greaterThan${exclusiveMinimum ? "" : "OrEqualTo"}(${schema.minimum})`
35221
+ `${importName}.greaterThan${exclusiveMinimum ? "" : "OrEqualTo"}(${minimum})`
35167
35222
  );
35168
35223
  }
35169
35224
  if (maximum !== void 0) {
35170
35225
  modifiers.push(
35171
- `${importName}.lessThan${exclusiveMaximum ? "" : "OrEqualTo"}(${schema.maximum})`
35226
+ `${importName}.lessThan${exclusiveMaximum ? "" : "OrEqualTo"}(${maximum})`
35172
35227
  );
35173
35228
  }
35174
35229
  return `${importName}.${schema.type === "integer" ? "Int" : "Number"}${pipeSource(modifiers)}`;
@@ -35184,7 +35239,7 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
35184
35239
  return `${importName}.${nonEmpty ? "NonEmpty" : ""}Array(${item})${pipeSource(modifiers)}`;
35185
35240
  },
35186
35241
  onUnion({ importName, items }) {
35187
- return `${importName}.Union(${items.map((_) => _.source).join(", ")})`;
35242
+ return `${importName}.Union(${items.map((_) => `${toComment(_.description)}${_.source}`).join(",\n")})`;
35188
35243
  }
35189
35244
  });
35190
35245
  });
@@ -35245,9 +35300,16 @@ export type ${name2} = (typeof ${name2})[keyof typeof ${name2}];` : `${toComment
35245
35300
  }
35246
35301
  })
35247
35302
  );
35303
+ var nonEmptyString3 = flow(
35304
+ fromNullable,
35305
+ map2(trim),
35306
+ filter(isNonEmpty5)
35307
+ );
35248
35308
  var toComment = match2({
35249
35309
  onNone: () => "",
35250
- onSome: (description) => `/** ${description} */
35310
+ onSome: (description) => `/**
35311
+ * ${description.split("\n").join("\n* ")}
35312
+ */
35251
35313
  `
35252
35314
  });
35253
35315
  function mergeSchemas(self, other) {
@@ -35311,6 +35373,28 @@ function resolveRef(schema, context7, recursive = false) {
35311
35373
  }
35312
35374
  return { name: name2, schema: resolveAllOf(current, context7, recursive) };
35313
35375
  }
35376
+ function filterNullable(schema) {
35377
+ if ("oneOf" in schema || "anyOf" in schema) {
35378
+ const items = schema.oneOf ?? schema.anyOf;
35379
+ const prop = "oneOf" in schema ? "oneOf" : "anyOf";
35380
+ let isNullable2 = false;
35381
+ let otherItems = empty2();
35382
+ for (const item of items) {
35383
+ if ("type" in item && item.type === "null") {
35384
+ isNullable2 = true;
35385
+ } else if ("const" in item && item.const === null) {
35386
+ isNullable2 = true;
35387
+ } else {
35388
+ otherItems.push(item);
35389
+ }
35390
+ }
35391
+ return [
35392
+ isNullable2,
35393
+ { ...schema, [prop]: otherItems }
35394
+ ];
35395
+ }
35396
+ return [false, schema];
35397
+ }
35314
35398
 
35315
35399
  // src/OpenApi.ts
35316
35400
  var import_swagger2openapi = __toESM(require_swagger2openapi());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-smart/openapi-gen",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Generate Effect http clients from OpenAPI specs",
5
5
  "bin": "main.js",
6
6
  "repository": {