Skip to content

Commit

Permalink
Merge pull request #4468 from swagger-api/issue-4132
Browse files Browse the repository at this point in the history
allow null values for extensions properties in openapi object
  • Loading branch information
HugoMario committed Aug 26, 2023
2 parents d0d584d + 05f9129 commit cbb955b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit cbb955b

Please sign in to comment.