Skip to content
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

fix #3071 - fixes empty enum in server variable #3110

Merged
merged 1 commit into from
Feb 5, 2019
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 @@ -635,7 +635,9 @@ public static Optional<Server> getServer(io.swagger.v3.oas.annotations.servers.S
serverVariableObject.setDefault(serverVariable.defaultValue());
}
if (serverVariable.allowableValues() != null && serverVariable.allowableValues().length > 0) {
serverVariableObject.setEnum(Arrays.asList(serverVariable.allowableValues()));
if (StringUtils.isNotBlank(serverVariable.allowableValues()[0])) {
serverVariableObject.setEnum(Arrays.asList(serverVariable.allowableValues()));
}
}
if (serverVariable.extensions() != null && serverVariable.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(serverVariable.extensions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;

public class OpenApiDefinitionTest extends AbstractAnnotationTest {

@Test
public void testSimpleInfoGet() throws IOException {

Expand Down Expand Up @@ -104,4 +105,44 @@ public void foo() {

}

@Test
public void testServerVariableWithoutEnum() throws IOException {

String expectedYAML = "openapi: 3.0.1\n" +
"info:\n" +
" title: My Rest API\n" +
" description: My RESTful API implementation\n" +
" version: 1.0.0\n" +
"servers:\n" +
"- url: /{context-path}/{rest-api}\n" +
" description: My REST API\n" +
" variables:\n" +
" context-path:\n" +
" default: my-war\n" +
" rest-api:\n" +
" enum:\n" +
" - api\n" +
" - rest\n" +
" - batchapi\n" +
" default: api\n";

compareAsYaml(OpenApiDefinitionTest.ServerVariableWithoutEnum.class, expectedYAML);
}

@OpenAPIDefinition(
info = @Info( title = "My Rest API", version = "1.0.0", description = "My RESTful API implementation" ),
servers = {
@Server( description = "My REST API",
url = "/{context-path}/{rest-api}",
variables = {
@ServerVariable(name = "context-path", defaultValue = "my-war"),
@ServerVariable(name = "rest-api", defaultValue = "api",
allowableValues = {"api", "rest", "batchapi"}) } ) } )
static class ServerVariableWithoutEnum {

public void foo() {
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,6 @@ public ExtensionUser setUser(
"servers:\n" +
"- variables:\n" +
" aa:\n" +
" enum:\n" +
" - \"\"\n" +
" default: aa\n" +
" x-servervar:\n" +
" name: Josh\n" +
Expand Down