Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
},
"ghcr.io/devcontainers/features/rust:1": {},
"ghcr.io/snebjorn/devcontainer-feature/chromium:latest": {},
"docker-in-docker": {
"version": "latest",
"moby": true,
"dockerDashComposeVersion": "v1"
}
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
// Configure tool-specific properties.
"customizations": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,11 @@ public String toModelFilename(String name) {
public String getTypeDeclaration(Schema p) {
if (ModelUtils.isArraySchema(p)) {
Schema<?> items = ModelUtils.getSchemaItems(p);
return getSchemaType(p) + "<" + getTypeDeclaration(unaliasSchema(items)) + ">";
String postfix = "";
if (Boolean.TRUE.equals(items.getNullable())) {
postfix = " | null";
}
return getSchemaType(p) + "<" + getTypeDeclaration(unaliasSchema(items)) + postfix + ">";
} else if (ModelUtils.isMapSchema(p)) {
Schema<?> inner = getSchemaAdditionalProperties(p);
String nullSafeSuffix = getNullSafeAdditionalProps() ? " | undefined" : "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,8 @@ private String getHttpLibForFramework(String object) {

@Override
public String getTypeDeclaration(Schema p) {
Schema inner;
if (ModelUtils.isArraySchema(p)) {
inner = ModelUtils.getSchemaItems(p);
return this.getSchemaType(p) + "<" + this.getTypeDeclaration(unaliasSchema(inner)) + ">";
} else if (ModelUtils.isMapSchema(p)) {
inner = getSchemaAdditionalProperties(p);
if (ModelUtils.isMapSchema(p)) {
Schema<?> inner = getSchemaAdditionalProperties(p);
String postfix = "";
if (Boolean.TRUE.equals(inner.getNullable())) {
postfix = " | null";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,15 @@ public void testCompilePattern() {
Assert.fail("Exception was thrown.");
}
}

@Test
public void arrayItemsCanBeNullable() throws Exception {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/array-nullable-items.yaml");
final DefaultCodegen codegen = new TypeScriptClientCodegen();
codegen.setOpenAPI(openAPI);
final ArraySchema schema = (ArraySchema) openAPI.getComponents().getSchemas().get("ArrayWithNullableItemsModel")
.getProperties()
.get("foo");
Assert.assertEquals(codegen.getTypeDeclaration(schema), "Array<string | null>");
}
}
Loading