From 264ec0060cb9cac8b07027e2cf31229254e0d685 Mon Sep 17 00:00:00 2001 From: Harry Collard Date: Tue, 16 Mar 2021 14:32:36 +0000 Subject: [PATCH 1/2] Add configuration flag for tryItOutEnabled --- .../AbstractSwaggerUiConfigProperties.java | 21 +++++++++++++++++++ .../core/SwaggerUiConfigParameters.java | 2 ++ 2 files changed, 23 insertions(+) diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractSwaggerUiConfigProperties.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractSwaggerUiConfigProperties.java index e40f63976..4bc468932 100644 --- a/springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractSwaggerUiConfigProperties.java +++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractSwaggerUiConfigProperties.java @@ -159,11 +159,32 @@ public abstract class AbstractSwaggerUiConfigProperties { */ protected SyntaxHighlight syntaxHighlight; + /** + * Try it out enabled + */ + protected Boolean tryItOutEnabled; + /** * The Persist authorization. */ protected Boolean persistAuthorization; + /** + * Gets try it out enabled + * @return try it out enabled + */ + public Boolean getTryItOutEnabled() { + return tryItOutEnabled; + } + + /** + * Sets try it out enabled + * @param tryItOutEnabled try it out enabled + */ + public void setTryItOutEnabled(Boolean tryItOutEnabled) { + this.tryItOutEnabled = tryItOutEnabled; + } + /** * Gets persist authorization. * diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/SwaggerUiConfigParameters.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/SwaggerUiConfigParameters.java index 3c2c53bbb..1681b3ba4 100644 --- a/springdoc-openapi-common/src/main/java/org/springdoc/core/SwaggerUiConfigParameters.java +++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/SwaggerUiConfigParameters.java @@ -117,6 +117,7 @@ public SwaggerUiConfigParameters(SwaggerUiConfigProperties swaggerUiConfig) { this.urlsPrimaryName = swaggerUiConfig.getUrlsPrimaryName(); this.groupsOrder = swaggerUiConfig.getGroupsOrder(); this.syntaxHighlight = swaggerUiConfig.getSyntaxHighlight(); + this.tryItOutEnabled = swaggerUiConfig.getTryItOutEnabled(); this.persistAuthorization = swaggerUiConfig.getPersistAuthorization(); } @@ -206,6 +207,7 @@ public Map getConfigParameters() { SpringDocPropertiesUtils.put("url", url, params); put(URLS_PROPERTY, urls, params); SpringDocPropertiesUtils.put("urls.primaryName", urlsPrimaryName, params); + SpringDocPropertiesUtils.put("tryItOutEnabled", tryItOutEnabled, params); SpringDocPropertiesUtils.put("persistAuthorization", persistAuthorization, params); return params; } From 277b1140e3b390a557e85b66c7d62f8e47787cdc Mon Sep 17 00:00:00 2001 From: Harry Collard Date: Tue, 16 Mar 2021 15:56:55 +0000 Subject: [PATCH 2/2] Add tests --- .../springdoc/ui/app18/HelloController.java | 36 ++++++++++++++ .../ui/app18/SpringDocApp18Test.java | 48 +++++++++++++++++++ .../src/test/resources/results/app18-1.json | 7 +++ 3 files changed, 91 insertions(+) create mode 100644 springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app18/HelloController.java create mode 100644 springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app18/SpringDocApp18Test.java create mode 100644 springdoc-openapi-ui/src/test/resources/results/app18-1.json diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app18/HelloController.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app18/HelloController.java new file mode 100644 index 000000000..580ef8a48 --- /dev/null +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app18/HelloController.java @@ -0,0 +1,36 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * https://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package test.org.springdoc.ui.app18; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.Valid; +import javax.validation.constraints.Size; + +@RestController +public class HelloController { + + @GetMapping(value = "/persons") + public void persons(@Valid @RequestParam @Size(min = 4, max = 6) String name) { + + } + +} diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app18/SpringDocApp18Test.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app18/SpringDocApp18Test.java new file mode 100644 index 000000000..909e9e6ea --- /dev/null +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app18/SpringDocApp18Test.java @@ -0,0 +1,48 @@ +/* + * + * * Copyright 2019-2020 the original author or authors. + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * https://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package test.org.springdoc.ui.app18; + +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import test.org.springdoc.ui.AbstractSpringDocActuatorTest; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = {"management.endpoints.web.exposure.include:*", + "springdoc.use-management-port=true", + "springdoc.swagger-ui.try-it-out-enabled=true", + "management.server.port=9095", + "management.server.base-path=/test", + "management.endpoints.web.base-path=/application" + }) +class SpringDocApp18Test extends AbstractSpringDocActuatorTest { + + @Test + public void testIndexSwaggerConfigTryItOutEnabledExists() throws Exception { + String contentAsString = actuatorRestTemplate.getForObject("/test/application/swaggerui/swagger-config", String.class); + String expected = getContent("results/app18-1.json"); + JSONAssert.assertEquals(expected, contentAsString, true); + } + + @SpringBootApplication + static class SpringDocTestApp { + } + +} \ No newline at end of file diff --git a/springdoc-openapi-ui/src/test/resources/results/app18-1.json b/springdoc-openapi-ui/src/test/resources/results/app18-1.json new file mode 100644 index 000000000..b18be76b3 --- /dev/null +++ b/springdoc-openapi-ui/src/test/resources/results/app18-1.json @@ -0,0 +1,7 @@ +{ + "configUrl": "/test/application/swaggerui/swagger-config", + "oauth2RedirectUrl": "http://localhost:9095/test/application/swagger-ui/oauth2-redirect.html", + "validatorUrl": "", + "url": "/test/application/openapi", + "tryItOutEnabled": "true" +} \ No newline at end of file