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

allow null values for extensions properties in openapi object #4468

Merged
merged 1 commit into from
Aug 26, 2023
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 @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.v3.core.jackson.PathsSerializer;
import io.swagger.v3.oas.models.PathItem;
Expand All @@ -12,6 +13,7 @@
public abstract class OpenAPIMixin {

@JsonAnyGetter
@JsonInclude
public abstract Map<String, Object> getExtensions();

@JsonAnySetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import org.testng.annotations.Test;
import org.yaml.snakeyaml.LoaderOptions;

import java.util.HashMap;
import java.util.Map;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;

Expand Down Expand Up @@ -55,6 +58,19 @@ public void testExtension() throws Exception {

}

@Test
public void testExtensionObjectWithProperties() throws Exception {
final Map<String, Object> extensionObjectProps = new HashMap<>();
extensionObjectProps.put("x-foo-bar", "foo bar");
extensionObjectProps.put("x-bar-foo", null);

OpenAPI swagger = new OpenAPI();
swagger.addExtension("x-extension-with-properties", extensionObjectProps);

String swaggerJson = Json.mapper().writeValueAsString(swagger);
assertEquals(swaggerJson, "{\"openapi\":\"3.0.1\",\"x-extension-with-properties\":{\"x-foo-bar\":\"foo bar\",\"x-bar-foo\":null}}");
}

@Test
public void testSerializeASpecWithResponseReferences() throws Exception {
OpenAPI swagger = new OpenAPI()
Expand Down
Loading