-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhanced support for additionalProperties
- Loading branch information
Showing
14 changed files
with
309 additions
and
6 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
modules/swagger-core/src/main/java/io/swagger/jackson/ModelSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.swagger.jackson; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.ResolvableSerializer; | ||
import io.swagger.models.Model; | ||
|
||
import java.io.IOException; | ||
|
||
public class ModelSerializer extends JsonSerializer<Model> implements ResolvableSerializer { | ||
|
||
private JsonSerializer<Object> defaultSerializer; | ||
|
||
public ModelSerializer(JsonSerializer<Object> serializer) { | ||
defaultSerializer = serializer; | ||
} | ||
|
||
@Override | ||
public void resolve(SerializerProvider serializerProvider) throws JsonMappingException { | ||
if (defaultSerializer instanceof ResolvableSerializer) { | ||
((ResolvableSerializer) defaultSerializer).resolve(serializerProvider); | ||
} | ||
} | ||
|
||
@Override | ||
public void serialize( | ||
Model value, JsonGenerator jgen, SerializerProvider provider) | ||
throws IOException { | ||
|
||
if (value.getBooleanValue() != null) { | ||
jgen.writeBoolean(value.getBooleanValue()); | ||
} else { | ||
defaultSerializer.serialize(value, jgen, provider); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
modules/swagger-core/src/main/java/io/swagger/jackson/PropertySerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.swagger.jackson; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.ResolvableSerializer; | ||
import io.swagger.models.properties.Property; | ||
|
||
import java.io.IOException; | ||
|
||
public class PropertySerializer extends JsonSerializer<Property> implements ResolvableSerializer { | ||
|
||
private JsonSerializer<Object> defaultSerializer; | ||
|
||
public PropertySerializer(JsonSerializer<Object> serializer) { | ||
defaultSerializer = serializer; | ||
} | ||
|
||
@Override | ||
public void resolve(SerializerProvider serializerProvider) throws JsonMappingException { | ||
if (defaultSerializer instanceof ResolvableSerializer) { | ||
((ResolvableSerializer) defaultSerializer).resolve(serializerProvider); | ||
} | ||
} | ||
|
||
@Override | ||
public void serialize( | ||
Property value, JsonGenerator jgen, SerializerProvider provider) | ||
throws IOException { | ||
|
||
if (value.getBooleanValue() != null) { | ||
jgen.writeBoolean(value.getBooleanValue()); | ||
} else { | ||
defaultSerializer.serialize(value, jgen, provider); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
modules/swagger-core/src/test/java/io/swagger/BooleanModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package io.swagger; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import io.swagger.matchers.SerializationMatchers; | ||
import io.swagger.models.ModelImpl; | ||
import io.swagger.models.Swagger; | ||
import io.swagger.util.Yaml; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
public class BooleanModelTest { | ||
@Test | ||
public void testBooleanProperty() throws JsonProcessingException { | ||
String yaml = "swagger: '2.0'\n" + | ||
"info:\n" + | ||
" title: Some API\n" + | ||
" description: >-\n" + | ||
" This is the Some Api\n" + | ||
" version: 2.0.0\n" + | ||
"basePath: /somepath\n" + | ||
"schemes:\n" + | ||
" - https\n" + | ||
"consumes:\n" + | ||
" - application/json\n" + | ||
"produces:\n" + | ||
" - application/json\n" + | ||
"paths:\n" + | ||
" /somepath:\n" + | ||
" get:\n" + | ||
" description: >\n" + | ||
" my description\n" + | ||
" operationId: MyGet\n" + | ||
" responses:\n" + | ||
" '200':\n" + | ||
" $ref: '#/responses/Response'\n" + | ||
"responses:\n" + | ||
" Response:\n" + | ||
" description: Response\n" + | ||
" schema:\n" + | ||
" type: object\n" + | ||
" required:\n" + | ||
" - Report\n" + | ||
" properties:\n" + | ||
" Report:\n" + | ||
" type: string\n" + | ||
" additionalProperties: false"; | ||
|
||
Swagger swagger = Yaml.mapper().readValue(yaml, Swagger.class); | ||
assertEquals(((ModelImpl)swagger.getResponses().get("Response").getResponseSchema()).getAdditionalProperties().getBooleanValue().booleanValue(), false); | ||
SerializationMatchers.assertEqualsToYaml(swagger, "swagger: \"2.0\"\n" + | ||
"info:\n" + | ||
" description: \"This is the Some Api\"\n" + | ||
" version: \"2.0.0\"\n" + | ||
" title: \"Some API\"\n" + | ||
"basePath: \"/somepath\"\n" + | ||
"schemes:\n" + | ||
"- \"https\"\n" + | ||
"consumes:\n" + | ||
"- \"application/json\"\n" + | ||
"produces:\n" + | ||
"- \"application/json\"\n" + | ||
"paths:\n" + | ||
" /somepath:\n" + | ||
" get:\n" + | ||
" description: \"my description\\n\"\n" + | ||
" operationId: \"MyGet\"\n" + | ||
" parameters: []\n" + | ||
" responses:\n" + | ||
" \"200\":\n" + | ||
" $ref: \"#/responses/Response\"\n" + | ||
"responses:\n" + | ||
" Response:\n" + | ||
" description: \"Response\"\n" + | ||
" schema:\n" + | ||
" type: \"object\"\n" + | ||
" required:\n" + | ||
" - \"Report\"\n" + | ||
" properties:\n" + | ||
" Report:\n" + | ||
" type: \"string\"\n" + | ||
" additionalProperties: false"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
modules/swagger-models/src/main/java/io/swagger/models/BooleanValueModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.swagger.models; | ||
|
||
public class BooleanValueModel extends AbstractModel { | ||
|
||
public BooleanValueModel() {} | ||
public BooleanValueModel(Boolean booleanValue) { | ||
this.setBooleanValue(booleanValue); | ||
} | ||
@Override | ||
public String getDescription() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void setDescription(String description) { | ||
|
||
} | ||
|
||
@Override | ||
public Object getExample() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void setExample(Object example) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.