@tim-smart/openapi-gen 0.3.2 → 0.3.4
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.
- package/main.js +32 -13
- 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,
|
|
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,
|
|
29419
|
+
schema.items.forEach((s) => addRefs(s, void 0));
|
|
29420
29420
|
} else if (schema.items) {
|
|
29421
|
-
addRefs(schema.items,
|
|
29421
|
+
addRefs(schema.items, void 0);
|
|
29422
29422
|
}
|
|
29423
29423
|
} else if ("allOf" in schema) {
|
|
29424
|
-
schema.allOf.forEach(
|
|
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(
|
|
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(
|
|
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);
|
|
@@ -29450,6 +29456,12 @@ var make65 = gen2(function* () {
|
|
|
29450
29456
|
const isEnum = enums.has(name);
|
|
29451
29457
|
return toSource(S, schema, name, isClass || isEnum).pipe(
|
|
29452
29458
|
map((source) => {
|
|
29459
|
+
if (name === "Model") {
|
|
29460
|
+
console.error({
|
|
29461
|
+
name,
|
|
29462
|
+
source
|
|
29463
|
+
});
|
|
29464
|
+
}
|
|
29453
29465
|
const isObject2 = "properties" in schema;
|
|
29454
29466
|
if (!isObject2 || !isClass) {
|
|
29455
29467
|
return `export class ${name} extends ${source} {}`;
|
|
@@ -29497,7 +29509,7 @@ var make65 = gen2(function* () {
|
|
|
29497
29509
|
}
|
|
29498
29510
|
const items = schema.enum.map((_) => JSON.stringify(_)).join(", ");
|
|
29499
29511
|
return some2(`${S}.Literal(${items})`);
|
|
29500
|
-
} else if ("type" in schema) {
|
|
29512
|
+
} else if ("type" in schema && schema.type) {
|
|
29501
29513
|
switch (schema.type) {
|
|
29502
29514
|
case "string": {
|
|
29503
29515
|
const modifiers = [];
|
|
@@ -29570,7 +29582,7 @@ var make65 = gen2(function* () {
|
|
|
29570
29582
|
} else if ("allOf" in schema) {
|
|
29571
29583
|
const sources = pipe(
|
|
29572
29584
|
schema.allOf,
|
|
29573
|
-
filterMap2((_) => toSource(S, _, currentIdentifier))
|
|
29585
|
+
filterMap2((_) => toSource(S, _, currentIdentifier + "Enum"))
|
|
29574
29586
|
);
|
|
29575
29587
|
if (sources.length === 0) {
|
|
29576
29588
|
return none2();
|
|
@@ -29586,7 +29598,7 @@ var make65 = gen2(function* () {
|
|
|
29586
29598
|
} else if ("anyOf" in schema || "oneOf" in schema) {
|
|
29587
29599
|
const sources = pipe(
|
|
29588
29600
|
"anyOf" in schema ? schema.anyOf : schema.oneOf,
|
|
29589
|
-
filterMap2((_) => toSource(S, _, currentIdentifier))
|
|
29601
|
+
filterMap2((_) => toSource(S, _, currentIdentifier + "Enum"))
|
|
29590
29602
|
);
|
|
29591
29603
|
if (sources.length === 0) return none2();
|
|
29592
29604
|
else if (sources.length === 1) return some2(sources[0]);
|
|
@@ -29815,7 +29827,12 @@ var operationToMethod = (operation) => {
|
|
|
29815
29827
|
}
|
|
29816
29828
|
return `readonly "${operation.id}": (${args.join(", ")}) => Effect.Effect<${success}, ${errors.join(" | ")}>`;
|
|
29817
29829
|
};
|
|
29818
|
-
var operationsToImpl = (name, operations) => `export const make = (
|
|
29830
|
+
var operationsToImpl = (name, operations) => `export const make = (
|
|
29831
|
+
httpClient: HttpClient.HttpClient,
|
|
29832
|
+
options: {
|
|
29833
|
+
readonly transformClient?: ((client: HttpClient.HttpClient) => Effect.Effect<HttpClient.HttpClient>) | undefined
|
|
29834
|
+
} = {}
|
|
29835
|
+
): ${name} => {
|
|
29819
29836
|
const unexpectedStatus = (request: HttpClientRequest.HttpClientRequest, response: HttpClientResponse.HttpClientResponse) =>
|
|
29820
29837
|
Effect.flatMap(
|
|
29821
29838
|
Effect.orElseSucceed(response.text, () => "Unexpected status code"),
|
|
@@ -29827,6 +29844,8 @@ var operationsToImpl = (name, operations) => `export const make = (httpClient: H
|
|
|
29827
29844
|
description
|
|
29828
29845
|
}))
|
|
29829
29846
|
)
|
|
29847
|
+
const applyClientTransform = (client: HttpClient.HttpClient): Effect.Effect<HttpClient.HttpClient> =>
|
|
29848
|
+
options.transformClient ? options.transformClient(client) : Effect.succeed(client)
|
|
29830
29849
|
const decodeError = <A, I, R>(response: HttpClientResponse.HttpClientResponse, schema: S.Schema<A, I, R>) => Effect.flatMap(HttpClientResponse.schemaBodyJson(schema)(response), Effect.fail)
|
|
29831
29850
|
return {
|
|
29832
29851
|
${operations.map(operationToImpl).join(",\n ")}
|
|
@@ -29850,7 +29869,7 @@ var operationToImpl = (operation) => {
|
|
|
29850
29869
|
}
|
|
29851
29870
|
if (operation.headers.length > 0) {
|
|
29852
29871
|
const props = operation.headers.map(
|
|
29853
|
-
(param) => `"${param}": ${varName}["${param}"]`
|
|
29872
|
+
(param) => `"${param}": ${varName}["${param}"] ?? undefined`
|
|
29854
29873
|
);
|
|
29855
29874
|
pipeline.push(`HttpClientRequest.setHeaders({ ${props.join(", ")} })`);
|
|
29856
29875
|
}
|
|
@@ -29878,9 +29897,9 @@ var operationToImpl = (operation) => {
|
|
|
29878
29897
|
decodes.push(`"${status2}": r => decodeError(r, ${schema})`);
|
|
29879
29898
|
});
|
|
29880
29899
|
decodes.push(`orElse: (response) => unexpectedStatus(request, response)`);
|
|
29881
|
-
pipeline.push(`Effect.flatMap(request => Effect.flatMap(httpClient.execute(request), HttpClientResponse.matchStatus({
|
|
29900
|
+
pipeline.push(`Effect.flatMap(request => Effect.flatMap(applyClientTransform(httpClient), (httpClient) => Effect.flatMap(httpClient.execute(request), HttpClientResponse.matchStatus({
|
|
29882
29901
|
${decodes.join(",\n ")}
|
|
29883
|
-
})))`);
|
|
29902
|
+
}))))`);
|
|
29884
29903
|
pipeline.push(`Effect.scoped`);
|
|
29885
29904
|
return `"${operation.id}": (${params}) => HttpClientRequest.make("${operation.method.toUpperCase()}")(${operation.pathTemplate}).pipe(
|
|
29886
29905
|
${pipeline.join(",\n ")}
|