Skip to content

Commit b07f5f9

Browse files
authored
fix(javascript): handle parent in models (#339)
1 parent f2ea49c commit b07f5f9

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed
Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
package com.algolia.codegen;
22

3-
import java.util.List;
4-
5-
import org.openapitools.codegen.CodegenOperation;
6-
import org.openapitools.codegen.languages.TypeScriptNodeClientCodegen;
3+
import io.swagger.v3.oas.models.Operation;
74
import io.swagger.v3.oas.models.media.Schema;
85
import io.swagger.v3.oas.models.parameters.Parameter;
9-
import io.swagger.v3.oas.models.Operation;
106
import io.swagger.v3.oas.models.servers.Server;
7+
import java.util.List;
8+
import org.openapitools.codegen.CodegenOperation;
9+
import org.openapitools.codegen.languages.TypeScriptNodeClientCodegen;
1110

1211
public class AlgoliaJavascriptGenerator extends TypeScriptNodeClientCodegen {
12+
1313
@Override
1414
public String getName() {
1515
return "algolia-javascript";
1616
}
1717

1818
@Override
19-
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
20-
return Utils.specifyCustomRequest(super.fromOperation(path, httpMethod, operation, servers));
19+
public CodegenOperation fromOperation(
20+
String path,
21+
String httpMethod,
22+
Operation operation,
23+
List<Server> servers
24+
) {
25+
return Utils.specifyCustomRequest(
26+
super.fromOperation(path, httpMethod, operation, servers)
27+
);
2128
}
2229

2330
@Override
@@ -27,4 +34,13 @@ protected String getParameterDataType(Parameter parameter, Schema p) {
2734
// we use replace because there might be more to this type, like '| undefined'
2835
return type.replace("{ [key: string]: object; }", "Record<string, any>");
2936
}
37+
38+
@Override
39+
public String toInstantiationType(Schema schema) {
40+
String type = super.toInstantiationType(schema);
41+
42+
// Same as the `getParameterDataType` but for the models, the generator
43+
// consider `object` as a fit all which is wrong in TypeScript
44+
return type.replace("null<String, object>", "Record<string, any>");
45+
}
3046
}

templates/javascript/model.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type {{classname}} = {{#oneOf}}{{.}} {{^-last}}|{{/-last}} {{/oneOf}}{{#a
1616
*/
1717
{{/description}}
1818
{{^isEnum}}
19-
export type {{classname}} = {
19+
export type {{classname}} = {{#parent}} {{{.}}} & {{/parent}} {
2020
{{#vars}}
2121
{{#description}}
2222
/**

0 commit comments

Comments
 (0)