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
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,11 @@ public CodegenModel fromModel(String name, Schema model) {
codegenModel.imports.remove("ApiModel");
}

if (getAnnotationLibrary() != AnnotationLibrary.SWAGGER2) {
// remove swagger imports
codegenModel.imports.remove("Schema");
}

return codegenModel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import static org.openapitools.codegen.languages.features.DocumentationProviderFeatures.ANNOTATION_LIBRARY;
import static org.openapitools.codegen.languages.features.DocumentationProviderFeatures.DOCUMENTATION_PROVIDER;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail;

public class SpringCodegenTest {
Expand Down Expand Up @@ -5759,4 +5760,72 @@ public void testApiVersion() throws IOException {
.assertMethodAnnotations()
.containsWithNameAndDoesContainAttributes("RequestMapping", List.of("version"));
}

@Test
public void annotationLibraryDoesNotCauseImportConflictsInSpring() throws IOException {
Map<String, Object> properties = new HashMap<>();
properties.put("documentationProvider", "source");
properties.put("annotationLibrary", "none");

File output = Files.createTempDirectory("test").toFile();
output.deleteOnExit();

final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/java/native/issue21991.yaml");

SpringCodegen codegen = new SpringCodegen();
codegen.setLibrary(SPRING_BOOT);
codegen.setOpenAPI(openAPI);
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().putAll(properties);

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

DefaultGenerator generator = new DefaultGenerator();

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

File apiFile = files.get("Schema.java");
assertNotNull(apiFile);

JavaFileAssert.assertThat(apiFile).fileDoesNotContain(
"import io.swagger.v3.oas.annotations.media.Schema;"
);
}

@Test
public void annotationLibraryDoesNotCauseImportConflictsInSpringWithAnnotationLibrary() throws IOException {
Map<String, Object> properties = new HashMap<>();
properties.put("documentationProvider", "source");
properties.put("annotationLibrary", "swagger2");

File output = Files.createTempDirectory("test").toFile();
output.deleteOnExit();

final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/java/native/issue21991.yaml");

SpringCodegen codegen = new SpringCodegen();
codegen.setOpenAPI(openAPI);
codegen.setLibrary(SPRING_BOOT);
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().putAll(properties);

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

DefaultGenerator generator = new DefaultGenerator();

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

File apiFile = files.get("Schema.java");
assertNotNull(apiFile);

JavaFileAssert.assertThat(apiFile).fileContains(
"import io.swagger.v3.oas.annotations.media.Schema;"
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


# Category

A category for a pet

## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**id** | **Long** | | [optional] |
|**name** | **String** | | [optional] |



Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


# ModelApiResponse

Describes the result of uploading an image resource

## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**code** | **Integer** | | [optional] |
|**type** | **String** | | [optional] |
|**message** | **String** | | [optional] |



Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@


# Order

An order for a pets from the pet store

## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**id** | **Long** | | [optional] |
|**petId** | **Long** | | [optional] |
|**quantity** | **Integer** | | [optional] |
|**shipDate** | **OffsetDateTime** | | [optional] |
|**status** | [**StatusEnum**](#StatusEnum) | Order Status | [optional] |
|**complete** | **Boolean** | | [optional] |



## Enum: StatusEnum

| Name | Value |
|---- | -----|
| PLACED | &quot;placed&quot; |
| APPROVED | &quot;approved&quot; |
| DELIVERED | &quot;delivered&quot; |



Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@


# Pet

A pet for sale in the pet store

## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**id** | **Long** | | [optional] |
|**category** | [**Category**](Category.md) | | [optional] |
|**name** | **String** | | |
|**photoUrls** | **List&lt;String&gt;** | | |
|**tags** | [**List&lt;Tag&gt;**](Tag.md) | | [optional] |
|**status** | [**StatusEnum**](#StatusEnum) | pet status in the store | [optional] |



## Enum: StatusEnum

| Name | Value |
|---- | -----|
| AVAILABLE | &quot;available&quot; |
| PENDING | &quot;pending&quot; |
| SOLD | &quot;sold&quot; |



Loading
Loading