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 @@ -449,7 +449,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("homeController.mustache",
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator),
"HomeController.java"));
if (!reactive && !apiFirst) {
if (!reactive && !apiFirst && this.openapiDocketConfig) {
supportingFiles.add(new SupportingFile("openapiDocumentationConfig.mustache",
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator),
"OpenAPIDocumentationConfig.java"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static org.openapitools.codegen.TestUtils.assertFileNotContains;
import static org.openapitools.codegen.languages.SpringCodegen.RESPONSE_WRAPPER;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;

public class SpringCodegenTest {

Expand Down Expand Up @@ -722,5 +723,45 @@ public void shouldGenerateDefaultValueForEnumRequestParameter() throws IOExcepti
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/api/GetApi.java"),
"@RequestParam(value = \"testParameter1\", required = false, defaultValue = \"BAR\")",
"@RequestParam(value = \"TestParameter2\", required = false, defaultValue = \"BAR\")");

}

/**define the destinationFilename*/
private final static String DESTINATIONFILE = "OpenAPIDocumentationConfig.java";
/**define the templateFile*/
private final static String TEMPLATEFILE = "openapiDocumentationConfig.mustache";

/**
* test whether OpenAPIDocumentationConfig.java is generated
* fix issue #10287
*/
@Test
public void testConfigFileGeneration() {

final SpringCodegen codegen = new SpringCodegen();

codegen.additionalProperties().put(SpringCodegen.INTERFACE_ONLY, false);
codegen.additionalProperties().put(SpringCodegen.SPRING_CLOUD_LIBRARY, "spring-cloud");
codegen.additionalProperties().put(SpringCodegen.OPENAPI_DOCKET_CONFIG, true);
codegen.additionalProperties().put(SpringCodegen.REACTIVE, false);
codegen.additionalProperties().put(SpringCodegen.API_FIRST, false);

codegen.processOpts();
final List<SupportingFile> supList = codegen.supportingFiles();
String tmpFile;
String desFile;
boolean flag = false;
for (final SupportingFile s : supList) {
tmpFile = s.getTemplateFile();
desFile = s.getDestinationFilename();

if (TEMPLATEFILE.equals(tmpFile)) {
flag = true;
assertEquals(desFile, DESTINATIONFILE);
}
}
if(!flag){
fail("OpenAPIDocumentationConfig.java not generated");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ src/main/java/org/openapitools/api/TestHeadersApiController.java
src/main/java/org/openapitools/api/TestQueryParamsApi.java
src/main/java/org/openapitools/api/TestQueryParamsApiController.java
src/main/java/org/openapitools/configuration/HomeController.java
src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java
src/main/java/org/openapitools/model/TestResponse.java
src/main/resources/application.properties
src/main/resources/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
openapi: 3.0.1
info:
description: desc
title: toto
version: 1.0.0
servers:
- description: /
url: /
tags:
- description: verify-default-value
name: verify-default-value
paths:
/test-headers:
get:
description: desc
operationId: headersTest
parameters:
- explode: false
in: header
name: headerNumber
required: false
schema:
default: 11.2
type: number
style: simple
- explode: false
in: header
name: headerString
required: false
schema:
default: qwerty
type: string
style: simple
- explode: false
in: header
name: headerStringWrapped
required: false
schema:
default: qwerty
type: string
style: simple
- explode: false
in: header
name: headerStringQuotes
required: false
schema:
default: qwerty"with quotes" test
type: string
style: simple
- explode: false
in: header
name: headerStringQuotesWrapped
required: false
schema:
default: qwerty"with quotes" test
type: string
style: simple
- explode: false
in: header
name: headerBoolean
required: false
schema:
default: true
type: boolean
style: simple
responses:
default:
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
description: default response
summary: test headers
tags:
- verify-default-value
x-accepts: application/json
x-tags:
- tag: verify-default-value
/test-query-params:
get:
description: desc
operationId: queryParamsTest
parameters:
- explode: true
in: query
name: queryNumber
required: false
schema:
default: 11.2
type: number
style: form
- explode: true
in: query
name: queryString
required: false
schema:
default: qwerty
type: string
style: form
- explode: true
in: query
name: queryStringWrapped
required: false
schema:
default: qwerty
type: string
style: form
- explode: true
in: query
name: queryStringQuotes
required: false
schema:
default: qwerty"with quotes" test
type: string
style: form
- explode: true
in: query
name: queryStringQuotesWrapped
required: false
schema:
default: qwerty"with quotes" test
type: string
style: form
- explode: true
in: query
name: queryBoolean
required: false
schema:
default: true
type: boolean
style: form
responses:
default:
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
description: default response
summary: test query params
tags:
- verify-default-value
x-accepts: application/json
x-tags:
- tag: verify-default-value
components:
schemas:
TestResponse:
example:
numberField: 6.027456183070403
booleanField: true
id: 0
stringField: asd
properties:
id:
type: integer
stringField:
default: asd
type: string
numberField:
default: 11
type: number
booleanField:
default: true
type: boolean
required:
- booleanField
- id
- numberField
- stringField
type: object
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ src/main/java/org/openapitools/api/StoreApiController.java
src/main/java/org/openapitools/api/UserApi.java
src/main/java/org/openapitools/api/UserApiController.java
src/main/java/org/openapitools/configuration/HomeController.java
src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java
src/main/java/org/openapitools/configuration/OpenAPIUiConfiguration.java
src/main/java/org/openapitools/configuration/RFC3339DateFormat.java
src/main/java/org/openapitools/configuration/WebApplication.java
Expand Down Expand Up @@ -66,3 +65,4 @@ src/main/java/org/openapitools/model/TypeHolderExample.java
src/main/java/org/openapitools/model/User.java
src/main/java/org/openapitools/model/XmlItem.java
src/main/resources/application.properties
src/main/resources/openapi.yaml
Loading