Skip to content

Add configuration flag for tryItOutEnabled #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2021
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 @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -206,6 +207,7 @@ public Map<String, Object> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {

}

}
Original file line number Diff line number Diff line change
@@ -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 {
}

}
7 changes: 7 additions & 0 deletions springdoc-openapi-ui/src/test/resources/results/app18-1.json
Original file line number Diff line number Diff line change
@@ -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"
}