openapi_generate_typescript_fetch 0.1.1 → 0.1.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.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fef98fafb2dd49b75ce82402cae6b4ee62ee057c7373df6fcddec049f2dfe68b
|
|
4
|
+
data.tar.gz: 3fb16c794e0e3d80782da49c9b3ee43125f78771a462d517bbc653f63e31c14c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14f13f53771fce068e664cfb01538fede08f8b6b100117cdca9d88b18118ec5e3a267cf3ca30c992dad5bc18cea4952a99f5073ca2f4b82cbd9fc1c8c3459dc3
|
|
7
|
+
data.tar.gz: b15055c459a498fcdd2da933f2d58a59d16cded49098f599575cf06419916e100b317b8ca2f3c8fb2e1a2e31946ed55e0898a141f9a012e0d9c5f7ba5a14941c
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright © 2025 Ismo Kärkkäinen
|
|
3
|
+
# Copyright © 2025-2026 Ismo Kärkkäinen
|
|
4
4
|
# Licensed under Universal Permissive License. See LICENSE.txt.
|
|
5
5
|
|
|
6
6
|
module OpenAPIGenerateTypeScriptFetch
|
|
7
7
|
NAME = 'openapi_generate_typescript_fetch'
|
|
8
|
-
VERSION = '0.1.
|
|
8
|
+
VERSION = '0.1.2'
|
|
9
9
|
end
|
|
@@ -236,7 +236,7 @@ EOB
|
|
|
236
236
|
end
|
|
237
237
|
query_params = ps.select { |p| p['in'] == 'query' }
|
|
238
238
|
query_func = query_params.map { |qp|
|
|
239
|
-
"if (cand.#{qp[:name]} !== undefined) q.push(`#{URI.encode_uri_component(qp['name'])}
|
|
239
|
+
"if (cand.#{qp[:name]} !== undefined) q.push(`#{URI.encode_uri_component(qp['name'])}=${encodeURIComponent(cand.#{qp[:name]})}`);"
|
|
240
240
|
}.join("\n")
|
|
241
241
|
header_params = ps.select { |p| p['in'] == 'header' }
|
|
242
242
|
header_func = header_params.map { |hp|
|
|
@@ -439,6 +439,8 @@ export class #{clsName} {
|
|
|
439
439
|
|
|
440
440
|
#{encode}
|
|
441
441
|
prepare({ ignoreMismatches = false, createAbortSignal = false }: PrepareArgs = {}): UrlRequestInit {
|
|
442
|
+
if (this.urlRequestInit !== undefined)
|
|
443
|
+
return this.urlRequestInit;
|
|
442
444
|
const cand = #{paramless ? '{}' : "{ ...#{operation_object[:shared]}(), ...#{clsName}.params, ...this.params! }"};
|
|
443
445
|
#{paramless ? '// cand is ok.' : "
|
|
444
446
|
if (!#{operation_object[:args_is]}(cand) && !ignoreMismatches) {
|
|
@@ -462,9 +464,11 @@ export class #{clsName} {
|
|
|
462
464
|
return out;
|
|
463
465
|
}
|
|
464
466
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
467
|
+
// args gets passed through to #{clsRespName}.obtain.
|
|
468
|
+
async call(args: Partial<#{clsRespName}Args> = {}): Promise<#{clsRespName}> {
|
|
469
|
+
if (this.urlRequestInit === undefined)
|
|
470
|
+
this.prepare();
|
|
471
|
+
return #{clsRespName}.obtain({ caller: this, ...args });
|
|
468
472
|
}
|
|
469
473
|
}
|
|
470
474
|
|
|
@@ -500,6 +504,7 @@ export class #{clsRespName} {
|
|
|
500
504
|
|
|
501
505
|
static async obtain(args: #{clsRespName}Args): Promise<#{clsRespName}> {
|
|
502
506
|
if (args.response === undefined) {
|
|
507
|
+
args.caller.prepare();
|
|
503
508
|
args.response = await fetch(args.caller.urlRequestInit!.url, args.caller.urlRequestInit!.ri);
|
|
504
509
|
}
|
|
505
510
|
args = { loaders: #{clsRespName}.loaders, ...#{clsRespName}.args, ...args };
|
data/template/src/schemas.ts.erb
CHANGED
|
@@ -77,7 +77,7 @@ export function baseArray(a: Array<any>): Array<any> {
|
|
|
77
77
|
else if (isObject(x))
|
|
78
78
|
out.push(baseObject(x as object));
|
|
79
79
|
else
|
|
80
|
-
out.push(x); //
|
|
80
|
+
out.push(x); // Scalar or undefined.
|
|
81
81
|
}
|
|
82
82
|
return out;
|
|
83
83
|
}
|
|
@@ -503,7 +503,15 @@ export function #{si.schema[:base]}(x: #{si.name}): #{si.name} {
|
|
|
503
503
|
EOB
|
|
504
504
|
out.push(s)
|
|
505
505
|
else
|
|
506
|
-
|
|
506
|
+
ref = si.schema['$ref']
|
|
507
|
+
raise StandardError, "Unhandled type: '#{si.schema['type']}' in #{si.name}" if ref.nil?
|
|
508
|
+
Gen.x.schemas.types.push(si.name)
|
|
509
|
+
r = Gen.h.dereference(ref)
|
|
510
|
+
si.schema[:is] = r[:is]
|
|
511
|
+
si.schema[:unknown] = r[:unknown]
|
|
512
|
+
si.schema[:base] = r[:base]
|
|
513
|
+
si.schema[:checkers] = r[:checkers]
|
|
514
|
+
out.push("export type #{si.name} = #{r[:name]};")
|
|
507
515
|
end
|
|
508
516
|
out.push('')
|
|
509
517
|
end
|
data/template/test/makers.ts.erb
CHANGED
|
@@ -751,7 +751,9 @@ Gen.doc['paths'].each do |path, path_item_object|
|
|
|
751
751
|
end
|
|
752
752
|
paraschemas = operation_object[:paraschemas]
|
|
753
753
|
commons = {}
|
|
754
|
-
[ :pass, :fail, :typefail
|
|
754
|
+
categories = [ :pass, :fail, :typefail ]
|
|
755
|
+
categories.push('missing') unless paraschemas.index { |ps| ps[:param]['required'] }.nil?
|
|
756
|
+
categories.each do |kind|
|
|
755
757
|
paraschemas.size.times do |chosen|
|
|
756
758
|
param_makers = []
|
|
757
759
|
category = kind
|
|
@@ -768,6 +770,8 @@ Gen.doc['paths'].each do |path, path_item_object|
|
|
|
768
770
|
needed = :fail unless schema[:fail].empty?
|
|
769
771
|
category = needed
|
|
770
772
|
else
|
|
773
|
+
needed = :pass # Optional missing is not a problem.
|
|
774
|
+
category = needed
|
|
771
775
|
param_makers.push(nil)
|
|
772
776
|
next
|
|
773
777
|
end
|