|
1 | | -using System.Data.Common; |
2 | 1 | using System.Text; |
3 | 2 | using System.Text.RegularExpressions; |
4 | 3 |
|
@@ -175,14 +174,6 @@ private string ParameterPrototype(Parameter param) { |
175 | 174 | return $"{param.Name}{optional}: {tsType}"; |
176 | 175 | } |
177 | 176 |
|
178 | | - private static string ParameterQuery(Parameter param, int index) { |
179 | | - if (param.Schema.Default is null) { |
180 | | - return $"${{{param.Name} ? `&{param.Name}=${{encodeURIComponent({param.Name})}}` : ''}}"; |
181 | | - } else { |
182 | | - return $"&{param.Name}=${{encodeURIComponent({param.Name} ?? {param.Schema.Default})}}"; |
183 | | - } |
184 | | - } |
185 | | - |
186 | 177 | private static string ParameterQueryInitializer(Parameter param) { |
187 | 178 | return $"if ({param.Name} !== undefined) __query__.push(`{param.Name}=${{encodeURIComponent({param.Name})}}`);"; |
188 | 179 | } |
@@ -266,16 +257,23 @@ private string RawGenerateType(int indent, Schema schema, string[] composedRequi |
266 | 257 | sb.Append('}'); |
267 | 258 | return sb.ToString(); |
268 | 259 | } else if (schema is EnumSchema enumSchema) { |
269 | | - return string.Join(" | ", enumSchema.Enum.Select(e => $"\"{e}\"")); |
| 260 | + return string.Join(" | ", enumSchema.Enum.Where(e => e is not null).Select(e => $"\"{e}\"")); |
270 | 261 | } else if (schema is PrimitiveSchema primSchema) { |
271 | | - return (primSchema.Type, primSchema.Format) switch { |
| 262 | + var types = |
| 263 | + (primSchema.Types, primSchema.Type) switch { |
| 264 | + (string[], _) => primSchema.Types, |
| 265 | + (null, string) => [primSchema.Type], |
| 266 | + _ => ["void"] |
| 267 | + }; |
| 268 | + return string.Join(" | ", types.Select(type => (type, primSchema.Format) switch { |
272 | 269 | ("string", "binary") => "File", |
273 | 270 | ("string", _) => "string", |
274 | 271 | ("integer", _) => "number", |
275 | 272 | ("number", _) => "number", |
276 | 273 | ("boolean", _) => "boolean", |
| 274 | + ("null", _) => "null", |
277 | 275 | _ => "void" |
278 | | - }; |
| 276 | + })); |
279 | 277 | } else { |
280 | 278 | throw new ApplicationException("Unknown schema type."); |
281 | 279 | } |
|
0 commit comments