openapi_generate_typescript_fetch 0.1.0 → 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 +4 -4
- data/lib/openapi_generate_typescript_fetch/version.rb +2 -2
- data/template/src/callclasses.ts.erb +9 -4
- data/template/src/schemas.ts.erb +11 -4
- data/template/test/makers.ts.erb +14 -10
- metadata +16 -4
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
|
}
|
|
@@ -195,8 +195,7 @@ EOB
|
|
|
195
195
|
kreq = []
|
|
196
196
|
os.props.select { |p| !p.pattern && !p.additional }.each do |p|
|
|
197
197
|
ps = Gen.h.dereference(p.spec)
|
|
198
|
-
#
|
|
199
|
-
warn("Property '#{p.name}' type '#{p.type}' has nil schema, fully proicessed source?") if ps.nil?
|
|
198
|
+
warn("Property '#{p.name}' type '#{p.type}' has nil schema, fully processed source?") if ps.nil?
|
|
200
199
|
o.push("#{p.name}#{p.req ? '' : '?'}: #{p.type};")
|
|
201
200
|
(p.req ? preq : popt).push({
|
|
202
201
|
name: p.name,
|
|
@@ -504,7 +503,15 @@ export function #{si.schema[:base]}(x: #{si.name}): #{si.name} {
|
|
|
504
503
|
EOB
|
|
505
504
|
out.push(s)
|
|
506
505
|
else
|
|
507
|
-
|
|
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]};")
|
|
508
515
|
end
|
|
509
516
|
out.push('')
|
|
510
517
|
end
|
data/template/test/makers.ts.erb
CHANGED
|
@@ -70,16 +70,16 @@ sis.each do |si|
|
|
|
70
70
|
end
|
|
71
71
|
if props.empty? && pat_props.empty? && (add_props.nil? || add_props == false)
|
|
72
72
|
make_name(si.schema, :pass, si.name)
|
|
73
|
-
out.push("export function #{si.schema[:pass].last}(): #{si.name} { return {} as #{si.name}; }")
|
|
73
|
+
out.push("export function #{si.schema[:pass].last}(): #{si.name} { return {} as unknown as #{si.name}; }")
|
|
74
74
|
if add_props == false
|
|
75
75
|
make_name(si.schema, :fail, si.name)
|
|
76
|
-
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return { prop: 'invalid' } as #{si.name}; }")
|
|
76
|
+
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return { prop: 'invalid' } as unknown as #{si.name}; }")
|
|
77
77
|
end
|
|
78
78
|
next
|
|
79
79
|
end
|
|
80
80
|
unless si.schema.fetch('required', []).empty?
|
|
81
81
|
make_name(si.schema, :fail, si.name)
|
|
82
|
-
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return {} as #{si.name}; }")
|
|
82
|
+
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return {} as unknown as #{si.name}; }")
|
|
83
83
|
end
|
|
84
84
|
todo.push(si)
|
|
85
85
|
when 'array'
|
|
@@ -122,7 +122,7 @@ sis.each do |si|
|
|
|
122
122
|
# Handle size-based fails. Any type is ok as length is not within limits.
|
|
123
123
|
if min_items > 1
|
|
124
124
|
make_name(si.schema, :fail, si.name)
|
|
125
|
-
out.push("export function #{si.schema[:fail].last}(): #{si.name} { const a = []; a[#{min_items - 2}] = 1; return a as #{si.name}; }")
|
|
125
|
+
out.push("export function #{si.schema[:fail].last}(): #{si.name} { const a = []; a[#{min_items - 2}] = 1; return a as unknown as #{si.name}; }")
|
|
126
126
|
elsif min_items == 1
|
|
127
127
|
make_name(si.schema, :fail, si.name)
|
|
128
128
|
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return [] as #{si.name}; }")
|
|
@@ -132,7 +132,7 @@ sis.each do |si|
|
|
|
132
132
|
end
|
|
133
133
|
unless max_items.nil?
|
|
134
134
|
make_name(si.schema, :fail, si.name)
|
|
135
|
-
out.push("export function #{si.schema[:fail].last}(): #{si.name} { const a = []; a[#{max_items}] = 0; return a as #{si.name}; }")
|
|
135
|
+
out.push("export function #{si.schema[:fail].last}(): #{si.name} { const a = []; a[#{max_items}] = 0; return a as unknown as #{si.name}; }")
|
|
136
136
|
end
|
|
137
137
|
todo.push(si)
|
|
138
138
|
when 'string'
|
|
@@ -670,11 +670,11 @@ EOB
|
|
|
670
670
|
if idx < pp.size
|
|
671
671
|
m = other_type([ alts[:prefix][idx], alts[:contains] ].compact)
|
|
672
672
|
make_name(si.schema, :fail, si.name)
|
|
673
|
-
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return replace(#{ma}, #{idx}, #{m}) as #{si.name}; }")
|
|
673
|
+
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return replace(#{ma}, #{idx}, #{m}) as unknown as #{si.name}; }")
|
|
674
674
|
else
|
|
675
675
|
m = other_type([ alts[:items], alts[:contains] ].compact)
|
|
676
676
|
make_name(si.schema, :fail, si.name)
|
|
677
|
-
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return replace(#{ma}, #{idx}, #{m}) as #{si.name}; }")
|
|
677
|
+
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return replace(#{ma}, #{idx}, #{m}) as unknown as #{si.name}; }")
|
|
678
678
|
end
|
|
679
679
|
end
|
|
680
680
|
end
|
|
@@ -685,7 +685,7 @@ EOB
|
|
|
685
685
|
len = max_contains + 1
|
|
686
686
|
ma = "makeContainingArray(#{min_items}, #{pp}, null, #{alts[:contains][:pass].first}, #{alts[:contains][:is]}, #{len}, #{len})"
|
|
687
687
|
make_name(si.schema, :fail, si.name)
|
|
688
|
-
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return #{ma} as #{si.name}; }")
|
|
688
|
+
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return #{ma} as unknown as #{si.name}; }")
|
|
689
689
|
# Exactly max_contains pass, minContains == maxContains == max_contains
|
|
690
690
|
len = max_contains
|
|
691
691
|
ma = "makeContainingArray(#{min_items}, #{pp}, null, #{alts[:contains][:pass].first}, #{alts[:contains][:is]}, #{len}, #{len})"
|
|
@@ -700,7 +700,7 @@ EOB
|
|
|
700
700
|
len = min_contains - 1
|
|
701
701
|
ma = "makeContainingArray(#{min_items}, #{pp}, #{ip}, #{alts[:contains][:pass].first}, #{alts[:contains][:is]}, #{len}, #{len})"
|
|
702
702
|
make_name(si.schema, :fail, si.name)
|
|
703
|
-
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return #{ma} as #{si.name}; }")
|
|
703
|
+
out.push("export function #{si.schema[:fail].last}(): #{si.name} { return #{ma} as unknown as #{si.name}; }")
|
|
704
704
|
end
|
|
705
705
|
if min_items <= min_contains + certain_mismatch
|
|
706
706
|
# Min contains pass, minContains == maxContains == min_contains
|
|
@@ -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
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: openapi_generate_typescript_fetch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ismo Kärkkäinen
|
|
@@ -34,6 +34,9 @@ dependencies:
|
|
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
|
35
35
|
requirements:
|
|
36
36
|
- - "~>"
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
- - ">="
|
|
37
40
|
- !ruby/object:Gem::Version
|
|
38
41
|
version: 0.1.0
|
|
39
42
|
type: :runtime
|
|
@@ -41,6 +44,9 @@ dependencies:
|
|
|
41
44
|
version_requirements: !ruby/object:Gem::Requirement
|
|
42
45
|
requirements:
|
|
43
46
|
- - "~>"
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
- - ">="
|
|
44
50
|
- !ruby/object:Gem::Version
|
|
45
51
|
version: 0.1.0
|
|
46
52
|
- !ruby/object:Gem::Dependency
|
|
@@ -49,14 +55,20 @@ dependencies:
|
|
|
49
55
|
requirements:
|
|
50
56
|
- - "~>"
|
|
51
57
|
- !ruby/object:Gem::Version
|
|
52
|
-
version: 0
|
|
58
|
+
version: '0'
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.12.1
|
|
53
62
|
type: :runtime
|
|
54
63
|
prerelease: false
|
|
55
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
56
65
|
requirements:
|
|
57
66
|
- - "~>"
|
|
58
67
|
- !ruby/object:Gem::Version
|
|
59
|
-
version: 0
|
|
68
|
+
version: '0'
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: 0.12.1
|
|
60
72
|
description: |-
|
|
61
73
|
This is a processor gem for use with openapi-generate from gem
|
|
62
74
|
openapi-sourcetools.
|
|
@@ -106,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
106
118
|
- !ruby/object:Gem::Version
|
|
107
119
|
version: '0'
|
|
108
120
|
requirements: []
|
|
109
|
-
rubygems_version:
|
|
121
|
+
rubygems_version: 4.0.21
|
|
110
122
|
specification_version: 4
|
|
111
123
|
summary: Generate Typescript Fetch API client package using OpenAPI format API specification.
|
|
112
124
|
test_files: []
|