@tim-smart/openapi-gen 0.3.7 → 0.3.9

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 +45 -13
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -30037,7 +30037,7 @@ var make63 = gen2(function* () {
30037
30037
  const isEnum = enums.has(name);
30038
30038
  return toSource(S, schema, name, isClass || isEnum).pipe(
30039
30039
  map2((source) => {
30040
- const isObject2 = "properties" in schema;
30040
+ const isObject2 = "properties" in schema || "allOf" in schema;
30041
30041
  if (!isObject2 || !isClass) {
30042
30042
  return `export class ${name} extends ${source} {}`;
30043
30043
  }
@@ -30045,6 +30045,26 @@ var make63 = gen2(function* () {
30045
30045
  })
30046
30046
  );
30047
30047
  };
30048
+ const getSchema = (raw) => {
30049
+ if ("$ref" in raw) {
30050
+ return refStore.get(raw.$ref) ?? raw;
30051
+ }
30052
+ return raw;
30053
+ };
30054
+ const flattenAllOf = (schema) => {
30055
+ if ("allOf" in schema) {
30056
+ let out = {};
30057
+ for (const member of schema.allOf) {
30058
+ let s = getSchema(member);
30059
+ if ("allOf" in s) {
30060
+ s = flattenAllOf(s);
30061
+ }
30062
+ out = mergeSchemas(out, s);
30063
+ }
30064
+ return out;
30065
+ }
30066
+ return getSchema(schema);
30067
+ };
30048
30068
  const toSource = (S, schema, currentIdentifier, topLevel = false) => {
30049
30069
  if ("properties" in schema) {
30050
30070
  const obj = schema;
@@ -30052,7 +30072,7 @@ var make63 = gen2(function* () {
30052
30072
  const properties = pipe(
30053
30073
  Object.entries(obj.properties ?? {}),
30054
30074
  filterMap2(([key, schema2]) => {
30055
- const fullSchema = "$ref" in schema2 ? refStore.get(schema2.$ref) : schema2;
30075
+ const fullSchema = getSchema(schema2);
30056
30076
  const isOptional = !required2.includes(key);
30057
30077
  return toSource(S, schema2, currentIdentifier + identifier2(key)).pipe(
30058
30078
  map2(
@@ -30155,21 +30175,14 @@ var make63 = gen2(function* () {
30155
30175
  topLevel
30156
30176
  );
30157
30177
  } else if ("allOf" in schema) {
30158
- const sources = pipe(
30159
- schema.allOf,
30160
- filterMap2((_) => toSource(S, _, currentIdentifier + "Enum"))
30161
- );
30178
+ const sources = schema.allOf;
30162
30179
  if (sources.length === 0) {
30163
30180
  return none2();
30164
30181
  } else if (sources.length === 1) {
30165
- return some2(sources[0]);
30166
- }
30167
- const first3 = sources[0];
30168
- const modifiers = [];
30169
- for (let i = 1; i < sources.length; i++) {
30170
- modifiers.push(sources[i]);
30182
+ return toSource(S, sources[0], currentIdentifier + "Enum", topLevel);
30171
30183
  }
30172
- return some2(`${first3}${pipeSource(modifiers)}`);
30184
+ const flattened2 = flattenAllOf(schema);
30185
+ return toSource(S, flattened2, currentIdentifier + "Enum", topLevel);
30173
30186
  } else if ("anyOf" in schema || "oneOf" in schema) {
30174
30187
  const sources = pipe(
30175
30188
  "anyOf" in schema ? schema.anyOf : schema.oneOf,
@@ -30178,6 +30191,8 @@ var make63 = gen2(function* () {
30178
30191
  if (sources.length === 0) return none2();
30179
30192
  else if (sources.length === 1) return some2(sources[0]);
30180
30193
  return some2(`${S}.Union(${sources.join(", ")})`);
30194
+ } else if ("const" in schema) {
30195
+ return some2(`${S}.Literal(${JSON.stringify(schema.const)})`);
30181
30196
  }
30182
30197
  return none2();
30183
30198
  };
@@ -30219,6 +30234,23 @@ var _JsonSchemaGen = class _JsonSchemaGen extends Tag2("JsonSchemaGen")() {
30219
30234
  };
30220
30235
  _JsonSchemaGen.with = provideServiceEffect2(_JsonSchemaGen, make63);
30221
30236
  var JsonSchemaGen = _JsonSchemaGen;
30237
+ function mergeSchemas(self, other) {
30238
+ if ("properties" in self && "properties" in other) {
30239
+ return {
30240
+ ...other,
30241
+ ...self,
30242
+ properties: {
30243
+ ...other.properties,
30244
+ ...self.properties
30245
+ },
30246
+ required: [...other.required || [], ...self.required || []]
30247
+ };
30248
+ }
30249
+ return {
30250
+ ...self,
30251
+ ...other
30252
+ };
30253
+ }
30222
30254
 
30223
30255
  // src/OpenApi.ts
30224
30256
  var methodNames = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-smart/openapi-gen",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "Generate Effect http clients from OpenAPI specs",
5
5
  "bin": "main.js",
6
6
  "repository": {