@tim-smart/openapi-gen 0.3.23 → 0.3.25

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 +75 -80
  2. package/package.json +1 -1
package/main.js CHANGED
@@ -35326,13 +35326,17 @@ var methodNames = [
35326
35326
  var make65 = gen2(function* () {
35327
35327
  const convert3 = fn("OpenApi.convert")(
35328
35328
  (v2Spec) => async2((resume2) => {
35329
- (0, import_swagger2openapi.convertObj)(v2Spec, {}, (err, result) => {
35330
- if (err) {
35331
- resume2(die5(err));
35332
- } else {
35333
- resume2(succeed8(result.openapi));
35329
+ (0, import_swagger2openapi.convertObj)(
35330
+ v2Spec,
35331
+ { laxDefaults: true, laxurls: true, patch: true, warnOnly: true },
35332
+ (err, result) => {
35333
+ if (err) {
35334
+ resume2(die5(err));
35335
+ } else {
35336
+ resume2(succeed8(result.openapi));
35337
+ }
35334
35338
  }
35335
- });
35339
+ );
35336
35340
  })
35337
35341
  );
35338
35342
  const generate = fnUntraced2(
@@ -35484,9 +35488,11 @@ var OpenApiTransformer = class extends Tag2("OpenApiTransformer")() {
35484
35488
  var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
35485
35489
  const operationsToInterface = (name2, operations) => `export interface ${name2} {
35486
35490
  readonly httpClient: HttpClient.HttpClient
35487
- ${operations.map(operationToMethod).join("\n ")}
35488
- }`;
35489
- const operationToMethod = (operation) => {
35491
+ ${operations.map((op) => operationToMethod(name2, op)).join("\n ")}
35492
+ }
35493
+
35494
+ ${clientErrorSource(name2)}`;
35495
+ const operationToMethod = (name2, operation) => {
35490
35496
  const args2 = [];
35491
35497
  if (operation.pathIds.length > 0) {
35492
35498
  args2.push(...operation.pathIds.map((id2) => `${id2}: string`));
@@ -35520,7 +35526,7 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
35520
35526
  if (operation.errorSchemas.size > 0) {
35521
35527
  errors.push(
35522
35528
  ...Array.from(operation.errorSchemas.values()).map(
35523
- (schema) => `typeof ${schema}.Type`
35529
+ (schema) => `${name2}Error<"${schema}", typeof ${schema}.Type>`
35524
35530
  )
35525
35531
  );
35526
35532
  }
@@ -35532,45 +35538,17 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
35532
35538
  readonly transformClient?: ((client: HttpClient.HttpClient) => Effect.Effect<HttpClient.HttpClient>) | undefined
35533
35539
  } = {}
35534
35540
  ): ${name2} => {
35535
- const unexpectedStatus = (response: HttpClientResponse.HttpClientResponse) =>
35536
- Effect.flatMap(
35537
- Effect.orElseSucceed(response.json, () => "Unexpected status code"),
35538
- (description) =>
35539
- Effect.fail(
35540
- new HttpClientError.ResponseError({
35541
- request: response.request,
35542
- response,
35543
- reason: "StatusCode",
35544
- description: typeof description === "string" ? description : JSON.stringify(description),
35545
- }),
35546
- ),
35547
- )
35548
- const withResponse: <A, E, R>(
35549
- f: (
35550
- response: HttpClientResponse.HttpClientResponse,
35551
- ) => Effect.Effect<A, E, R>,
35552
- ) => (
35553
- request: HttpClientRequest.HttpClientRequest,
35554
- ) => Effect.Effect<A, E | HttpClientError.HttpClientError, R> =
35555
- options.transformClient
35556
- ? (f) => (request) =>
35557
- Effect.flatMap(
35558
- Effect.flatMap(options.transformClient!(httpClient), (client) =>
35559
- client.execute(request),
35560
- ),
35561
- f,
35562
- )
35563
- : (f) => (request) => Effect.flatMap(httpClient.execute(request), f)
35541
+ ${commonSource}
35564
35542
  const decodeSuccess =
35565
35543
  <A, I, R>(schema: S.Schema<A, I, R>) =>
35566
35544
  (response: HttpClientResponse.HttpClientResponse) =>
35567
35545
  HttpClientResponse.schemaBodyJson(schema)(response)
35568
35546
  const decodeError =
35569
- <A, I, R>(schema: S.Schema<A, I, R>) =>
35547
+ <const Tag extends string, A, I, R>(tag: Tag, schema: S.Schema<A, I, R>) =>
35570
35548
  (response: HttpClientResponse.HttpClientResponse) =>
35571
35549
  Effect.flatMap(
35572
35550
  HttpClientResponse.schemaBodyJson(schema)(response),
35573
- Effect.fail,
35551
+ (cause) => Effect.fail(${name2}Error(tag, cause, response)),
35574
35552
  )
35575
35553
  return {
35576
35554
  httpClient,
@@ -35615,7 +35593,7 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
35615
35593
  decodes.push(`"${statusCode}": decodeSuccess(${schema})`);
35616
35594
  });
35617
35595
  operation.errorSchemas.forEach((schema, status2) => {
35618
- decodes.push(`"${status2}": decodeError(${schema})`);
35596
+ decodes.push(`"${status2}": decodeError("${schema}", ${schema})`);
35619
35597
  });
35620
35598
  decodes.push(`orElse: unexpectedStatus`);
35621
35599
  pipeline.push(`withResponse(HttpClientResponse.matchStatus({
@@ -35631,6 +35609,7 @@ var layerTransformerSchema2 = sync6(OpenApiTransformer, () => {
35631
35609
  'import * as HttpClientError from "@effect/platform/HttpClientError"',
35632
35610
  'import * as HttpClientRequest from "@effect/platform/HttpClientRequest"',
35633
35611
  'import * as HttpClientResponse from "@effect/platform/HttpClientResponse"',
35612
+ 'import * as Data from "effect/Data"',
35634
35613
  'import * as Effect from "effect/Effect"',
35635
35614
  'import type { ParseError } from "effect/ParseResult"',
35636
35615
  'import * as S from "effect/Schema"'
@@ -35645,17 +35624,7 @@ var layerTransformerTs2 = sync6(OpenApiTransformer, () => {
35645
35624
  ${operations.map((s) => operationToMethod(name2, s)).join("\n ")}
35646
35625
  }
35647
35626
 
35648
- export interface ${name2}Error<Tag extends string, E> {
35649
- readonly _tag: Tag
35650
- readonly cause: E
35651
- }
35652
-
35653
- class ${name2}ErrorImpl extends Data.Error<{ _tag: string; cause: any }> {}
35654
-
35655
- export const ${name2}Error = <Tag extends string, E>(
35656
- tag: Tag,
35657
- cause: E,
35658
- ): ${name2}Error<Tag, E> => new ${name2}ErrorImpl({ _tag: tag, cause }) as any`;
35627
+ ${clientErrorSource(name2)}`;
35659
35628
  const operationToMethod = (name2, operation) => {
35660
35629
  const args2 = [];
35661
35630
  if (operation.pathIds.length > 0) {
@@ -35700,32 +35669,7 @@ export const ${name2}Error = <Tag extends string, E>(
35700
35669
  readonly transformClient?: ((client: HttpClient.HttpClient) => Effect.Effect<HttpClient.HttpClient>) | undefined
35701
35670
  } = {}
35702
35671
  ): ${name2} => {
35703
- const unexpectedStatus = (response: HttpClientResponse.HttpClientResponse) =>
35704
- Effect.flatMap(
35705
- Effect.orElseSucceed(response.json, () => "Unexpected status code"),
35706
- (description) =>
35707
- Effect.fail(
35708
- new HttpClientError.ResponseError({
35709
- request: response.request,
35710
- response,
35711
- reason: "StatusCode",
35712
- description: typeof description === "string" ? description : JSON.stringify(description),
35713
- }),
35714
- ),
35715
- )
35716
- const withResponse: <A, E>(
35717
- f: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, E>,
35718
- ) => (
35719
- request: HttpClientRequest.HttpClientRequest,
35720
- ) => Effect.Effect<any, any> = options.transformClient
35721
- ? (f) => (request) =>
35722
- Effect.flatMap(
35723
- Effect.flatMap(options.transformClient!(httpClient), (client) =>
35724
- client.execute(request),
35725
- ),
35726
- f,
35727
- )
35728
- : (f) => (request) => Effect.flatMap(httpClient.execute(request), f)
35672
+ ${commonSource}
35729
35673
  const decodeSuccess = <A>(response: HttpClientResponse.HttpClientResponse) =>
35730
35674
  response.json as Effect.Effect<A, HttpClientError.ResponseError>
35731
35675
  const decodeVoid = (_response: HttpClientResponse.HttpClientResponse) =>
@@ -35740,7 +35684,7 @@ export const ${name2}Error = <Tag extends string, E>(
35740
35684
  > =>
35741
35685
  Effect.flatMap(
35742
35686
  response.json as Effect.Effect<E, HttpClientError.ResponseError>,
35743
- (cause) => Effect.fail(${name2}Error(tag, cause)),
35687
+ (cause) => Effect.fail(${name2}Error(tag, cause, response)),
35744
35688
  )
35745
35689
  const onRequest = (
35746
35690
  successCodes: ReadonlyArray<string>,
@@ -35829,6 +35773,57 @@ var processPath = (path2) => {
35829
35773
  });
35830
35774
  return { path: "`" + path2 + "`", ids: ids3 };
35831
35775
  };
35776
+ var commonSource = `const unexpectedStatus = (response: HttpClientResponse.HttpClientResponse) =>
35777
+ Effect.flatMap(
35778
+ Effect.orElseSucceed(response.json, () => "Unexpected status code"),
35779
+ (description) =>
35780
+ Effect.fail(
35781
+ new HttpClientError.ResponseError({
35782
+ request: response.request,
35783
+ response,
35784
+ reason: "StatusCode",
35785
+ description: typeof description === "string" ? description : JSON.stringify(description),
35786
+ }),
35787
+ ),
35788
+ )
35789
+ const withResponse: <A, E>(
35790
+ f: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, E>,
35791
+ ) => (
35792
+ request: HttpClientRequest.HttpClientRequest,
35793
+ ) => Effect.Effect<any, any> = options.transformClient
35794
+ ? (f) => (request) =>
35795
+ Effect.flatMap(
35796
+ Effect.flatMap(options.transformClient!(httpClient), (client) =>
35797
+ client.execute(request),
35798
+ ),
35799
+ f,
35800
+ )
35801
+ : (f) => (request) => Effect.flatMap(httpClient.execute(request), f)`;
35802
+ var clientErrorSource = (name2) => `export interface ${name2}Error<Tag extends string, E> {
35803
+ readonly _tag: Tag
35804
+ readonly request: HttpClientRequest.HttpClientRequest
35805
+ readonly response: HttpClientResponse.HttpClientResponse
35806
+ readonly cause: E
35807
+ }
35808
+
35809
+ class ${name2}ErrorImpl extends Data.Error<{
35810
+ _tag: string
35811
+ cause: any
35812
+ request: HttpClientRequest.HttpClientRequest
35813
+ response: HttpClientResponse.HttpClientResponse
35814
+ }> {}
35815
+
35816
+ export const ${name2}Error = <Tag extends string, E>(
35817
+ tag: Tag,
35818
+ cause: E,
35819
+ response: HttpClientResponse.HttpClientResponse,
35820
+ ): ${name2}Error<Tag, E> =>
35821
+ new ${name2}ErrorImpl({
35822
+ _tag: tag,
35823
+ cause,
35824
+ response,
35825
+ request: response.request,
35826
+ }) as any`;
35832
35827
 
35833
35828
  // src/main.ts
35834
35829
  var spec = fileParse2("spec").pipe(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-smart/openapi-gen",
3
- "version": "0.3.23",
3
+ "version": "0.3.25",
4
4
  "description": "Generate Effect http clients from OpenAPI specs",
5
5
  "bin": "main.js",
6
6
  "repository": {