Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5349,9 +5349,6 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
if (parameter.getExtensions() != null && !parameter.getExtensions().isEmpty()) {
codegenParameter.vendorExtensions.putAll(parameter.getExtensions());
}
if (parameter.getSchema() != null && parameter.getSchema().getExtensions() != null && !parameter.getSchema().getExtensions().isEmpty()) {
codegenParameter.vendorExtensions.putAll(parameter.getSchema().getExtensions());
}

Schema parameterSchema;

Expand Down Expand Up @@ -5386,6 +5383,10 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
parameterSchema = null;
}

if (parameterSchema != null && parameterSchema.getExtensions() != null && !parameterSchema.getExtensions().isEmpty()) {
codegenParameter.vendorExtensions.putAll(parameterSchema.getExtensions());
}

if (parameter instanceof QueryParameter || "query".equalsIgnoreCase(parameter.getIn())) {
codegenParameter.isQueryParam = true;
codegenParameter.isAllowEmptyValue = parameter.getAllowEmptyValue() != null && parameter.getAllowEmptyValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6175,4 +6175,52 @@ public void annotationLibraryDoesNotCauseImportConflictsInSpringWithAnnotationLi
"import io.swagger.v3.oas.annotations.media.Schema;"
);
}

@Test
public void testExtensionsOnSchema_issue9183() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();

final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_9138_resolve_extensions_on_schema.yaml");
final SpringCodegen codegen = new SpringCodegen();
codegen.setOpenAPI(openAPI);
codegen.setOutputDir(output.getAbsolutePath());

codegen.additionalProperties().put(SpringCodegen.DATE_LIBRARY, "java8-localdatetime");
codegen.additionalProperties().put(INTERFACE_ONLY, "true");
codegen.additionalProperties().put(USE_RESPONSE_ENTITY, "false");
codegen.additionalProperties().put(DELEGATE_PATTERN, "true");
codegen.additionalProperties().put(USE_BEANVALIDATION, "true");
codegen.additionalProperties().put(PERFORM_BEANVALIDATION, "true");
codegen.additionalProperties().put(REQUEST_MAPPING_OPTION, "api_interface");

ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);

DefaultGenerator generator = new DefaultGenerator();
generator.setGenerateMetadata(false); // skip metadata generation

Map<String, File> files = generator.opts(input).generate().stream()
.collect(Collectors.toMap(File::getName, Function.identity()));

JavaFileAssert javaFileAssert = JavaFileAssert.assertThat(files.get("TestApi.java"));
javaFileAssert
.assertMethod("_postToTest")
.assertParameter("groupObj")
.assertParameterAnnotations()
.containsWithNameAndAttributes("Pattern", ImmutableMap.of(
"regexp", "\"[a-zA-Z]\"",
"message", "\"Only letters\""
))
.toParameter()
.toMethod()
.assertParameter("token")
.assertParameterAnnotations()
.containsWithNameAndAttributes("Pattern", ImmutableMap.of(
"regexp", "\"[0-9a-fA-F]\"",
"message", "\"Only numbers and letters a-f\""
));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
openapi: 3.0.3
info:
title: sample spec
version: 1.0.0
paths:
/test/{groupObj}:
post:
summary: Post to test
description: ''
operationId: postToTest
parameters:
- in: path
name: groupObj
required: true
schema:
$ref: '#/components/schemas/OnlyLetters'
- in: query
name: token
required: true
schema:
type: string
pattern: "[0-9a-fA-F]"
x-pattern-message: "Only numbers and letters a-f"
responses:
201:
description: success
components:
schemas:
OnlyLetters:
type: string
pattern: "[a-zA-Z]"
x-pattern-message: "Only letters"
Loading