Search in sources :

Example 26 with ApiResponse

use of io.swagger.v3.oas.annotations.responses.ApiResponse in project swagger-parser by swagger-api.

the class OpenAPIV3ParserTest method testResolveFullyExample.

@Test
public void testResolveFullyExample() throws Exception {
    String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
    pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));
    ParseOptions options = new ParseOptions();
    options.setResolveFully(true);
    SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, new ArrayList<>(), options);
    Assert.assertNotNull(result);
    Assert.assertNotNull(result.getOpenAPI());
    Components components = result.getOpenAPI().getComponents();
    ApiResponse response = result.getOpenAPI().getPaths().get("/mockResponses/objectMultipleExamples").getGet().getResponses().get("200");
    assertEquals(response.getContent().get("application/json").getExamples().get("ArthurDent"), components.getExamples().get("Arthur"));
    assertEquals(response.getContent().get("application/xml").getExamples().get("Trillian"), components.getExamples().get("Trillian"));
}
Also used : Components(io.swagger.v3.oas.models.Components) ParseOptions(io.swagger.v3.parser.core.models.ParseOptions) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) File(java.io.File) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 27 with ApiResponse

use of io.swagger.v3.oas.annotations.responses.ApiResponse in project syncope by apache.

the class SyncopeOpenApiCustomizer method customize.

@Override
public OpenAPIConfiguration customize(final OpenAPIConfiguration configuration) {
    Map<String, Header> headers = new LinkedHashMap<>();
    headers.put(RESTHeaders.ERROR_CODE, new Header().schema(new Schema<>().type("string")).description("Error code"));
    headers.put(RESTHeaders.ERROR_INFO, new Header().schema(new Schema<>().type("string")).description("Error message"));
    Content content = new Content();
    content.addMediaType(javax.ws.rs.core.MediaType.APPLICATION_JSON, new MediaType().schema(new Schema<ErrorTO>()));
    content.addMediaType(javax.ws.rs.core.MediaType.APPLICATION_XML, new MediaType().schema(new Schema<ErrorTO>()));
    configuration.getOpenAPI().getComponents().addResponses("400", new ApiResponse().description("An error occurred; HTTP status code can vary depending on the actual error: " + "400, 403, 404, 409, 412").headers(headers).content(content));
    return super.customize(configuration);
}
Also used : Header(io.swagger.v3.oas.models.headers.Header) Content(io.swagger.v3.oas.models.media.Content) Schema(io.swagger.v3.oas.models.media.Schema) MediaType(io.swagger.v3.oas.models.media.MediaType) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) LinkedHashMap(java.util.LinkedHashMap)

Example 28 with ApiResponse

use of io.swagger.v3.oas.annotations.responses.ApiResponse in project swagger-core by swagger-api.

the class MapPropertyDeserializerTest method testBooleanAdditionalPropertiesDeserialization.

@Test(description = "it should deserialize a boolean additionalProperties")
public void testBooleanAdditionalPropertiesDeserialization() throws Exception {
    Operation operation = Json.mapper().readValue(jsonAdditionalPropertiesBoolean, Operation.class);
    ApiResponse response = operation.getResponses().get("200");
    assertNotNull(response);
    Schema responseSchema = response.getContent().get("*/*").getSchema();
    assertNotNull(responseSchema);
    assertTrue(responseSchema instanceof ObjectSchema);
    assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean);
    Assert.assertFalse((Boolean) responseSchema.getAdditionalProperties());
    operation = Json.mapper().readValue(jsonAdditionalPropertiesBooleanTrue, Operation.class);
    response = operation.getResponses().get("200");
    assertNotNull(response);
    responseSchema = response.getContent().get("*/*").getSchema();
    assertNotNull(responseSchema);
    assertTrue(responseSchema instanceof MapSchema);
    assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean);
    Assert.assertTrue((Boolean) responseSchema.getAdditionalProperties());
}
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) 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 29 with ApiResponse

use of io.swagger.v3.oas.annotations.responses.ApiResponse in project swagger-core by swagger-api.

the class MapPropertyDeserializerTest method testMapDeserializationVendorExtensions.

@Test(description = "vendor extensions should be included with object type")
public void testMapDeserializationVendorExtensions() 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);
    MapSchema mp = (MapSchema) responseSchema;
    assertTrue(mp.getExtensions().size() > 0);
    assertNotNull(mp.getExtensions().get("x-foo"));
    assertEquals(mp.getExtensions().get("x-foo"), "vendor x");
}
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) 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 30 with ApiResponse

use of io.swagger.v3.oas.annotations.responses.ApiResponse 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)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)113 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)84 Test (org.testng.annotations.Test)53 Operation (io.swagger.v3.oas.models.Operation)50 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)48 OpenAPI (io.swagger.v3.oas.models.OpenAPI)47 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)43 PathItem (io.swagger.v3.oas.models.PathItem)39 Schema (io.swagger.v3.oas.models.media.Schema)38 MediaType (io.swagger.v3.oas.models.media.MediaType)31 Path (javax.ws.rs.Path)30 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)29 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)27 StringSchema (io.swagger.v3.oas.models.media.StringSchema)27 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)25 Content (io.swagger.v3.oas.models.media.Content)25 ArrayList (java.util.ArrayList)24 Components (io.swagger.v3.oas.models.Components)19 Parameter (io.swagger.v3.oas.models.parameters.Parameter)18