Search in sources :

Example 91 with Operation

use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.

the class MapPropertyDeserializerTest method testBooleanAdditionalPropertiesSerialization.

@Test(description = "it should serialize a boolean additionalProperties")
public void testBooleanAdditionalPropertiesSerialization() throws Exception {
    Operation operation = Json.mapper().readValue(json, Operation.class);
    ApiResponse response = operation.getResponses().get("200");
    assertNotNull(response);
    Schema responseSchema = response.getContent().get("*/*").getSchema();
    Schema schema = new ObjectSchema().additionalProperties(true);
    assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" + "  \"type\" : \"object\",\n" + "  \"additionalProperties\" : true\n" + "}");
    schema = new ObjectSchema().additionalProperties(responseSchema);
    assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" + "  \"type\" : \"object\",\n" + "  \"additionalProperties\" : {\n" + "    \"type\" : \"object\",\n" + "    \"additionalProperties\" : {\n" + "      \"type\" : \"integer\",\n" + "      \"format\" : \"int32\"\n" + "    },\n" + "    \"x-foo\" : \"vendor x\"\n" + "  }\n" + "}");
}
Also used : ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 92 with Operation

use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.

the class MapPropertyDeserializerTest method testIssue1261InlineSchemaExample.

@Test(description = "it should read an example within an inlined schema")
public void testIssue1261InlineSchemaExample() throws Exception {
    Operation operation = Yaml.mapper().readValue("      responses:\n" + "        \"200\":\n" + "          content:\n" + "            '*/*':\n" + "              description: OK\n" + "              schema:\n" + "                type: object\n" + "                properties:\n" + "                  id:\n" + "                    type: integer\n" + "                    format: int32\n" + "                  name:\n" + "                    type: string\n" + "                required: [id, name]\n" + "                example: ok", Operation.class);
    ApiResponse response = operation.getResponses().get("200");
    assertNotNull(response);
    Schema schema = response.getContent().get("*/*").getSchema();
    Object example = schema.getExample();
    assertNotNull(example);
    assertTrue(example instanceof String);
    assertEquals(example, "ok");
}
Also used : MapSchema(io.swagger.v3.oas.models.media.MapSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 93 with Operation

use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.

the class MapPropertyDeserializerTest method testMapDeserialization.

@Test(description = "it should deserialize a response per #1349")
public void testMapDeserialization() throws Exception {
    Operation operation = Json.mapper().readValue(json, Operation.class);
    ApiResponse response = operation.getResponses().get("200");
    assertNotNull(response);
    Schema responseSchema = response.getContent().get("*/*").getSchema();
    assertNotNull(responseSchema);
    assertTrue(responseSchema instanceof MapSchema);
    MapSchema mp = (MapSchema) responseSchema;
    assertTrue(mp.getAdditionalProperties() instanceof IntegerSchema);
}
Also used : MapSchema(io.swagger.v3.oas.models.media.MapSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 94 with Operation

use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.

the class JsonDeserializationTest method testNullExampleDeserialization.

@Test
public void testNullExampleDeserialization() throws Exception {
    String yamlNull = "openapi: 3.0.1\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      description: Operation Description\n" + "      operationId: operationId\n" + "components:\n" + "  schemas:\n" + "    UserStatus:\n" + "      type: string\n" + "      example: null\n";
    String yamlMissing = "openapi: 3.0.1\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      description: Operation Description\n" + "      operationId: operationId\n" + "components:\n" + "  schemas:\n" + "    UserStatus:\n" + "      type: string\n";
    OpenAPI oas = Yaml.mapper().readValue(yamlNull, OpenAPI.class);
    Yaml.prettyPrint(oas);
    assertNull(oas.getComponents().getSchemas().get("UserStatus").getExample());
    assertTrue(oas.getComponents().getSchemas().get("UserStatus").getExampleSetFlag());
    oas = Yaml.mapper().readValue(yamlMissing, OpenAPI.class);
    Yaml.prettyPrint(oas);
    assertNull(oas.getComponents().getSchemas().get("UserStatus").getExample());
    assertFalse(oas.getComponents().getSchemas().get("UserStatus").getExampleSetFlag());
    Yaml.prettyPrint(oas);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 95 with Operation

use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.

the class JsonDeserializationTest method testNullEnumItem.

@Test(description = "Deserialize null enum item")
public void testNullEnumItem() throws Exception {
    String yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      tags:\n" + "      - MyTag\n" + "      summary: Operation Summary\n" + "      description: Operation Description\n" + "      operationId: operationId\n" + "      parameters:\n" + "      - name: subscriptionId\n" + "        in: query\n" + "        schema:\n" + "          type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "components:\n" + "  schemas:\n" + "    UserStatus:\n" + "      type: integer\n" + "      description: some int values with null\n" + "      format: int32\n" + "      enum:\n" + "      - 1\n" + "      - 2\n" + "      - null\n";
    OpenAPI oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
    assertEquals(oas.getComponents().getSchemas().get("UserStatus").getEnum(), Arrays.asList(1, 2, null));
    yaml = "openapi: 3.0.1\n" + "paths:\n" + "  /:\n" + "    get:\n" + "      tags:\n" + "      - MyTag\n" + "      summary: Operation Summary\n" + "      description: Operation Description\n" + "      operationId: operationId\n" + "      parameters:\n" + "      - name: subscriptionId\n" + "        in: query\n" + "        schema:\n" + "          type: string\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "components:\n" + "  schemas:\n" + "    UserStatus:\n" + "      type: string\n" + "      description: some int values with null\n" + "      enum:\n" + "      - 1\n" + "      - 2\n" + "      - null\n";
    oas = Yaml.mapper().readValue(yaml, OpenAPI.class);
    assertEquals(oas.getComponents().getSchemas().get("UserStatus").getEnum(), Arrays.asList("1", "2", null));
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)177 Operation (io.swagger.v3.oas.models.Operation)174 OpenAPI (io.swagger.v3.oas.models.OpenAPI)141 Test (org.testng.annotations.Test)129 PathItem (io.swagger.v3.oas.models.PathItem)108 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 Schema (io.swagger.v3.oas.models.media.Schema)68 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)62 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)59 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)55 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)51 ArrayList (java.util.ArrayList)51 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)50 StringSchema (io.swagger.v3.oas.models.media.StringSchema)48 MediaType (io.swagger.v3.oas.models.media.MediaType)44 Path (javax.ws.rs.Path)44 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)43 Content (io.swagger.v3.oas.models.media.Content)42 lombok.val (lombok.val)42 Parameter (io.swagger.v3.oas.models.parameters.Parameter)39