@tim-smart/openapi-gen 0.4.1 → 0.4.2

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 +49 -11
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -34907,9 +34907,10 @@ var make64 = gen2(function* () {
34907
34907
  filterMap2(([key, schema2]) => {
34908
34908
  const fullSchema = getSchema(schema2);
34909
34909
  const isOptional = !required2.includes(key);
34910
+ const [enumNullable, filteredSchema] = filterNullable(fullSchema);
34910
34911
  return toSource(
34911
34912
  importName,
34912
- schema2,
34913
+ enumNullable ? filteredSchema : schema2,
34913
34914
  currentIdentifier + identifier2(key)
34914
34915
  ).pipe(
34915
34916
  map2(
@@ -34919,7 +34920,7 @@ var make64 = gen2(function* () {
34919
34920
  key,
34920
34921
  source,
34921
34922
  isOptional,
34922
- isNullable: "nullable" in fullSchema && fullSchema.nullable === true || "default" in fullSchema && fullSchema.default === null,
34923
+ isNullable: enumNullable || "nullable" in fullSchema && fullSchema.nullable === true || "default" in fullSchema && fullSchema.default === null,
34923
34924
  default: fullSchema.default
34924
34925
  })
34925
34926
  )
@@ -34985,8 +34986,21 @@ var make64 = gen2(function* () {
34985
34986
  topLevel
34986
34987
  );
34987
34988
  } else if ("anyOf" in schema || "oneOf" in schema) {
34989
+ let itemSchemas = "anyOf" in schema ? schema.anyOf : schema.oneOf;
34990
+ let typePrimitives = 0;
34991
+ const constItems = empty2();
34992
+ for (const item of itemSchemas) {
34993
+ if ("type" in item && item.type !== "null") {
34994
+ typePrimitives++;
34995
+ } else if ("const" in item) {
34996
+ constItems.push(item);
34997
+ }
34998
+ }
34999
+ if (typePrimitives <= 1 && constItems.length > 0 && constItems.length + typePrimitives === itemSchemas.length) {
35000
+ itemSchemas = constItems;
35001
+ }
34988
35002
  const items = pipe(
34989
- "anyOf" in schema ? schema.anyOf : schema.oneOf,
35003
+ itemSchemas,
34990
35004
  filterMap2(
34991
35005
  (_) => toSource(importName, _, currentIdentifier + "Enum").pipe(
34992
35006
  map2(
@@ -35099,12 +35113,12 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
35099
35113
  supportsTopLevel({ isClass, isEnum }) {
35100
35114
  return isClass || isEnum;
35101
35115
  },
35102
- onTopLevel({ importName, schema, name: name2, source, isClass }) {
35116
+ onTopLevel({ importName, schema, name: name2, source, isClass, description }) {
35103
35117
  const isObject2 = "properties" in schema;
35104
35118
  if (!isObject2 || !isClass) {
35105
- return `export class ${name2} extends ${source} {}`;
35119
+ return `${toComment(description)}export class ${name2} extends ${source} {}`;
35106
35120
  }
35107
- return `export class ${name2} extends ${importName}.Class<${name2}>("${name2}")(${source}) {}`;
35121
+ return `${toComment(description)}export class ${name2} extends ${importName}.Class<${name2}>("${name2}")(${source}) {}`;
35108
35122
  },
35109
35123
  propertySeparator: ",\n ",
35110
35124
  onProperty: (options3) => {
@@ -35112,7 +35126,7 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
35112
35126
  options3.importName,
35113
35127
  options3
35114
35128
  )(options3.source);
35115
- return `"${options3.key}": ${source}`;
35129
+ return `${toComment(options3.description)}"${options3.key}": ${source}`;
35116
35130
  },
35117
35131
  onRef({ name: name2 }) {
35118
35132
  return name2;
@@ -35163,12 +35177,12 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
35163
35177
  const modifiers = [];
35164
35178
  if (minimum !== void 0) {
35165
35179
  modifiers.push(
35166
- `${importName}.greaterThan${exclusiveMinimum ? "" : "OrEqualTo"}(${schema.minimum})`
35180
+ `${importName}.greaterThan${exclusiveMinimum ? "" : "OrEqualTo"}(${minimum})`
35167
35181
  );
35168
35182
  }
35169
35183
  if (maximum !== void 0) {
35170
35184
  modifiers.push(
35171
- `${importName}.lessThan${exclusiveMaximum ? "" : "OrEqualTo"}(${schema.maximum})`
35185
+ `${importName}.lessThan${exclusiveMaximum ? "" : "OrEqualTo"}(${maximum})`
35172
35186
  );
35173
35187
  }
35174
35188
  return `${importName}.${schema.type === "integer" ? "Int" : "Number"}${pipeSource(modifiers)}`;
@@ -35184,7 +35198,7 @@ var layerTransformerSchema = sync6(JsonSchemaTransformer, () => {
35184
35198
  return `${importName}.${nonEmpty ? "NonEmpty" : ""}Array(${item})${pipeSource(modifiers)}`;
35185
35199
  },
35186
35200
  onUnion({ importName, items }) {
35187
- return `${importName}.Union(${items.map((_) => _.source).join(", ")})`;
35201
+ return `${importName}.Union(${items.map((_) => `${toComment(_.description)}${_.source}`).join(",\n")})`;
35188
35202
  }
35189
35203
  });
35190
35204
  });
@@ -35247,7 +35261,9 @@ export type ${name2} = (typeof ${name2})[keyof typeof ${name2}];` : `${toComment
35247
35261
  );
35248
35262
  var toComment = match2({
35249
35263
  onNone: () => "",
35250
- onSome: (description) => `/** ${description} */
35264
+ onSome: (description) => `/**
35265
+ * ${description.split("\n").join("\n* ")}
35266
+ */
35251
35267
  `
35252
35268
  });
35253
35269
  function mergeSchemas(self, other) {
@@ -35311,6 +35327,28 @@ function resolveRef(schema, context7, recursive = false) {
35311
35327
  }
35312
35328
  return { name: name2, schema: resolveAllOf(current, context7, recursive) };
35313
35329
  }
35330
+ function filterNullable(schema) {
35331
+ if ("oneOf" in schema || "anyOf" in schema) {
35332
+ const items = schema.oneOf ?? schema.anyOf;
35333
+ const prop = "oneOf" in schema ? "oneOf" : "anyOf";
35334
+ let isNullable2 = false;
35335
+ let otherItems = empty2();
35336
+ for (const item of items) {
35337
+ if ("type" in item && item.type === "null") {
35338
+ isNullable2 = true;
35339
+ } else if ("const" in item && item.const === null) {
35340
+ isNullable2 = true;
35341
+ } else {
35342
+ otherItems.push(item);
35343
+ }
35344
+ }
35345
+ return [
35346
+ isNullable2,
35347
+ { ...schema, [prop]: otherItems }
35348
+ ];
35349
+ }
35350
+ return [false, schema];
35351
+ }
35314
35352
 
35315
35353
  // src/OpenApi.ts
35316
35354
  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.2",
4
4
  "description": "Generate Effect http clients from OpenAPI specs",
5
5
  "bin": "main.js",
6
6
  "repository": {