forked from loafle/openapi-generator-original
Fix attributes in allOf and $ref (#17836)
* fix allOf and ref properties * add tests
This commit is contained in:
parent
3f344ac6b4
commit
dd3ab0a1fa
@ -3979,6 +3979,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
} else {
|
||||
LOGGER.error("Unknown type in allOf schema. Please report the issue via openapi-generator's Github issue tracker.");
|
||||
}
|
||||
} else if (p.get$ref() != null) { // it's a ref
|
||||
original = p;
|
||||
}
|
||||
|
||||
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
|
||||
@ -4214,6 +4216,24 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
if (original.getDescription() != null) {
|
||||
property.description = p.getDescription();
|
||||
}
|
||||
if (original.getMaxLength() != null) {
|
||||
property.setMaxLength(original.getMaxLength());
|
||||
}
|
||||
if (original.getMinLength() != null) {
|
||||
property.setMinLength(original.getMinLength());
|
||||
}
|
||||
if (original.getMaxItems() != null) {
|
||||
property.setMaxItems(original.getMaxItems());
|
||||
}
|
||||
if (original.getMinItems() != null) {
|
||||
property.setMinItems(original.getMinItems());
|
||||
}
|
||||
if (original.getMaximum() != null) {
|
||||
property.setMaximum(String.valueOf(original.getMaximum().doubleValue()));
|
||||
}
|
||||
if (original.getMinimum() != null) {
|
||||
property.setMinimum(String.valueOf(original.getMinimum().doubleValue()));
|
||||
}
|
||||
}
|
||||
|
||||
// set the default value
|
||||
|
@ -5,6 +5,7 @@ import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.languages.KotlinServerCodegen;
|
||||
import org.openapitools.codegen.languages.KotlinSpringServerCodegen;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -164,4 +165,26 @@ public class KotlinServerCodegenTest {
|
||||
"import javax.validation.Valid"
|
||||
);
|
||||
}
|
||||
|
||||
// to test attributes in the $ref (OpenAPI 3.1 spec)
|
||||
@Test
|
||||
public void attributesInRef() throws IOException {
|
||||
File output = Files.createTempDirectory("test_attributes").toFile().getCanonicalFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||
codegen.setOutputDir(output.getAbsolutePath());
|
||||
|
||||
new DefaultGenerator().opts(new ClientOptInput()
|
||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_1/issue_17726.yaml"))
|
||||
.config(codegen))
|
||||
.generate();
|
||||
|
||||
String outputPath = output.getAbsolutePath() + "src/main/kotlin/org/openapitools";
|
||||
Path order = Paths.get(outputPath + "/model/Order.kt");
|
||||
assertFileContains(
|
||||
order,
|
||||
"@get:Size(max=50)"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
openapi: 3.1.0
|
||||
info:
|
||||
title: dummy
|
||||
version: "1.0"
|
||||
paths:
|
||||
/users/{id}:
|
||||
summary: Represents a user
|
||||
components:
|
||||
schemas:
|
||||
Order:
|
||||
type: object
|
||||
required:
|
||||
- name
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
address:
|
||||
$ref: '#/components/schemas/Address'
|
||||
maxLength: 50
|
||||
Address:
|
||||
type: object
|
||||
properties:
|
||||
firstName:
|
||||
type: string
|
Loading…
x
Reference in New Issue
Block a user