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"));
}
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);
}
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());
}
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");
}
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" + "}");
}
Aggregations