use of io.swagger.v3.oas.models.examples.Example in project swagger-core by swagger-api.
the class Ticket3063Test method testTicket3063.
@Test
public void testTicket3063() throws Exception {
final Schema model = context.resolve(new AnnotatedType(BaseClass.class));
assertNotNull(model);
String yaml = "BaseClass:\n" + " required:\n" + " - type\n" + " type: object\n" + " properties:\n" + " type:\n" + " type: string\n" + " description: Type\n" + " example: AndroidDeviceRequirements\n" + " description: test\n" + " discriminator:\n" + " propertyName: type\n" + "SubClass:\n" + " required:\n" + " - type\n" + " type: object\n" + " description: SubClass\n" + " allOf:\n" + " - $ref: '#/components/schemas/BaseClass'\n" + " - type: object\n" + " properties:\n" + " additionalPropertyWhichShouldBeThere:\n" + " type: integer\n" + " description: Test\n" + " format: int32";
SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), yaml);
}
use of io.swagger.v3.oas.models.examples.Example in project swagger-core by swagger-api.
the class ModelExampleTest method createModel.
@Test(description = "it should create a model")
public void createModel() {
ObjectSchema model = new ObjectSchema();
model.addProperties("name", new StringSchema().example("Tony"));
model.addProperties("id", new IntegerSchema().example(123));
assertNotNull(model);
}
use of io.swagger.v3.oas.models.examples.Example in project swagger-core by swagger-api.
the class ModelSerializerTest method deserializeModelWithObjectExample.
@Test(description = "it should deserialize a model with object example")
public void deserializeModelWithObjectExample() throws IOException {
final String json = "{\n" + " \"title\":\"Error\",\n" + " \"type\":\"object\",\n" + " \"properties\":{\n" + " \"code\":{\n" + " \"type\":\"integer\",\n" + " \"format\":\"int32\"\n" + " },\n" + " \"message\":{\n" + " \"type\":\"string\"\n" + " },\n" + " \"fields\":{\n" + " \"type\":\"string\"\n" + " }\n" + " },\n" + " \"example\":{\n" + " \"code\":1,\n" + " \"message\":\"hello\",\n" + " \"fields\":\"abc\"\n" + " }\n" + "}";
final Schema model = Json.mapper().readValue(json, Schema.class);
assertEquals(Json.mapper().writeValueAsString(model.getExample()), "{\"code\":1,\"message\":\"hello\",\"fields\":\"abc\"}");
}
use of io.swagger.v3.oas.models.examples.Example in project swagger-core by swagger-api.
the class OpenAPI3_1SerializationTest method testExampleRefSerialization.
@Test
public void testExampleRefSerialization() {
OpenAPI openAPI = new OpenAPI().openapi("3.1.0").components(new Components().addExamples("testExample", new Example().value("Example on test").description("this is a example desc").summary("this is a summary test")).addSchemas("schema", new Schema().example(new Example().$ref("#/components/examples/testExample").description("ref description").summary("ref summary"))));
SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "components:\n" + " schemas:\n" + " schema:\n" + " example:\n" + " summary: ref summary\n" + " description: ref description\n" + " $ref: '#/components/examples/testExample'\n" + " examples:\n" + " testExample:\n" + " summary: this is a summary test\n" + " description: this is a example desc\n" + " value: Example on test");
SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + " \"openapi\" : \"3.1.0\",\n" + " \"components\" : {\n" + " \"schemas\" : {\n" + " \"schema\" : {\n" + " \"example\" : {\n" + " \"summary\" : \"ref summary\",\n" + " \"description\" : \"ref description\",\n" + " \"$ref\" : \"#/components/examples/testExample\"\n" + " }\n" + " }\n" + " },\n" + " \"examples\" : {\n" + " \"testExample\" : {\n" + " \"summary\" : \"this is a summary test\",\n" + " \"description\" : \"this is a example desc\",\n" + " \"value\" : \"Example on test\"\n" + " }\n" + " }\n" + " }\n" + "}");
}
use of io.swagger.v3.oas.models.examples.Example in project swagger-core by swagger-api.
the class ReaderTest method testParameterWithRef.
@Test(description = "Parameter with ref")
public void testParameterWithRef() {
Components components = new Components();
components.addParameters("id", new Parameter().description("Id Description").schema(new IntegerSchema()).in(ParameterIn.QUERY.toString()).example(1).required(true));
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(RefParameterResource.class);
String yaml = "openapi: 3.0.1\n" + "info:\n" + " description: info\n" + "paths:\n" + " /:\n" + " get:\n" + " summary: Simple get operation\n" + " description: Defines a simple get operation with a payload complex input object\n" + " operationId: sendPayload\n" + " parameters:\n" + " - $ref: '#/components/parameters/id'\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + " deprecated: true\n" + "components:\n" + " parameters: \n" + " id:\n" + " in: query\n" + " description: Id Description\n" + " required: true\n" + " schema:\n" + " type: integer\n" + " format: int32\n" + " example: 1\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Aggregations