Search in sources :

Example 6 with Example

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);
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) Schema(io.swagger.v3.oas.models.media.Schema) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 7 with Example

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);
}
Also used : ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 8 with Example

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\"}");
}
Also used : DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 9 with Example

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" + "}");
}
Also used : Components(io.swagger.v3.oas.models.Components) Example(io.swagger.v3.oas.models.examples.Example) Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 10 with Example

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);
}
Also used : Components(io.swagger.v3.oas.models.Components) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)28 OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Schema (io.swagger.v3.oas.models.media.Schema)12 Components (io.swagger.v3.oas.models.Components)9 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)9 Info (io.swagger.v3.oas.models.info.Info)8 StringSchema (io.swagger.v3.oas.models.media.StringSchema)7 Example (io.swagger.v3.oas.models.examples.Example)6 Content (io.swagger.v3.oas.models.media.Content)6 MediaType (io.swagger.v3.oas.models.media.MediaType)6 Parameter (io.swagger.v3.oas.models.parameters.Parameter)6 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)6 Operation (io.swagger.v3.oas.models.Operation)5 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)5 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)4 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)3 ExampleObject (io.swagger.v3.oas.annotations.media.ExampleObject)3 PathItem (io.swagger.v3.oas.models.PathItem)3 Link (io.swagger.v3.oas.models.links.Link)3 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)3