use of io.swagger.v3.oas.models.headers.Header 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.models.headers.Header in project swagger-core by swagger-api.
the class ParameterDeSerializationTest method deserializeHeaderParameter.
@Test(description = "it should deserialize a HeaderParameter")
public void deserializeHeaderParameter() throws IOException {
final String json = "{\"in\":\"header\",\"required\":true,\"schema\":{\"type\":\"string\"}}";
final Parameter p = m.readValue(json, Parameter.class);
SerializationMatchers.assertEqualsToJson(p, json);
}
use of io.swagger.v3.oas.models.headers.Header in project swagger-core by swagger-api.
the class JsonDeserializationTest method testDeserializeSecurity.
@Test
public void testDeserializeSecurity() throws Exception {
final OpenAPI swagger = TestUtils.deserializeJsonFileFromClasspath("specFiles/securityDefinitions.json", OpenAPI.class);
final List<SecurityRequirement> security = swagger.getSecurity();
assertNotNull(security);
assertEquals(security.size(), 3);
final Map<String, SecurityScheme> securitySchemes = swagger.getComponents().getSecuritySchemes();
assertNotNull(securitySchemes);
assertEquals(securitySchemes.size(), 4);
{
final SecurityScheme scheme = securitySchemes.get("petstore_auth");
assertNotNull(scheme);
assertEquals(scheme.getType().toString(), "oauth2");
assertEquals(scheme.getFlows().getImplicit().getAuthorizationUrl(), "http://petstore.swagger.io/oauth/dialog");
assertEquals(scheme.getFlows().getImplicit().getScopes().get("write:pets"), "modify pets in your account");
assertEquals(scheme.getFlows().getImplicit().getScopes().get("read:pets"), "read your pets");
}
{
final SecurityScheme scheme = securitySchemes.get("api_key");
assertNotNull(scheme);
assertEquals(scheme.getType().toString(), "apiKey");
assertEquals(scheme.getIn().toString(), "header");
assertEquals(scheme.getName(), "api_key");
}
{
final SecurityScheme scheme = securitySchemes.get("http");
assertNotNull(scheme);
assertEquals(scheme.getType().toString(), "http");
assertEquals(scheme.getScheme(), "basic");
}
{
final SecurityScheme scheme = securitySchemes.get("open_id_connect");
assertNotNull(scheme);
assertEquals(scheme.getType().toString(), "openIdConnect");
assertEquals(scheme.getOpenIdConnectUrl(), "http://petstore.swagger.io/openid");
}
{
final SecurityRequirement securityRequirement = security.get(0);
final List<String> scopes = securityRequirement.get("petstore_auth");
assertNotNull(scopes);
assertEquals(scopes.size(), 2);
assertTrue(scopes.contains("write:pets"));
assertTrue(scopes.contains("read:pets"));
}
{
final SecurityRequirement securityRequirement = security.get(1);
final List<String> scopes = securityRequirement.get("api_key");
assertNotNull(scopes);
assertTrue(scopes.isEmpty());
}
{
final SecurityRequirement securityRequirement = security.get(2);
final List<String> scopes = securityRequirement.get("http");
assertNotNull(scopes);
assertTrue(scopes.isEmpty());
}
}
use of io.swagger.v3.oas.models.headers.Header in project swagger-core by swagger-api.
the class OpenAPI3_1DeserializationTest method testRefDeserializationOnOAS31.
@Test
public void testRefDeserializationOnOAS31() throws IOException {
final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/3.1.0/petstore-3.1_refs_siblings.yaml");
OpenAPI openAPI = Yaml31.mapper().readValue(jsonString, OpenAPI.class);
assertEquals(openAPI.getPaths().get("/ref_pet").get$ref(), "#/components/pathItems/pet");
assertEquals(openAPI.getPaths().get("/ref_pet").getDescription(), "ref pathItem description");
assertEquals(openAPI.getPaths().get("/ref_pet").getSummary(), "ref pathItem summary");
assertEquals(openAPI.getPaths().get("/pets").getPost().getParameters().get(0).get$ref(), "#/components/parameters/testParameter");
assertEquals(openAPI.getPaths().get("/pets").getPost().getParameters().get(0).getDescription(), "ref parameter description");
assertEquals(openAPI.getPaths().get("/pets").getPost().getParameters().get(1).getName(), "randomParam");
assertEquals(openAPI.getPaths().get("/pets").getPost().getParameters().get(1).getIn(), "query");
assertEquals(openAPI.getPaths().get("/pets").getPost().getParameters().get(1).getExamples().get("refExample").get$ref(), "#/components/examples/testExample");
assertEquals(openAPI.getPaths().get("/pets").getPost().getParameters().get(1).getExamples().get("refExample").getDescription(), "ref example description");
assertEquals(openAPI.getPaths().get("/pets").getPost().getParameters().get(1).getExamples().get("refExample").getSummary(), "ref example summary");
assertEquals(openAPI.getPaths().get("/pets").getPost().getCallbacks().get("callIt").get$ref(), "#/components/callbacks/TestCallback");
assertEquals(openAPI.getPaths().get("/pets").getPost().getRequestBody().get$ref(), "#/components/requestBodies/body");
assertEquals(openAPI.getPaths().get("/pets").getPost().getRequestBody().getDescription(), "ref request body description");
assertEquals(openAPI.getPaths().get("/pets").getPost().getResponses().get("201").get$ref(), "#/components/responses/okResponse");
assertEquals(openAPI.getPaths().get("/pets").getPost().getResponses().get("201").getDescription(), "ref response description");
assertEquals(openAPI.getPaths().get("/pets").getPost().getResponses().get("default").getHeaders().get("head").get$ref(), "#/components/headers/head");
assertEquals(openAPI.getPaths().get("/pets").getPost().getResponses().get("default").getHeaders().get("head").getDescription(), "ref header description");
}
use of io.swagger.v3.oas.models.headers.Header in project swagger-core by swagger-api.
the class ParameterSerializationTest method serializeHeaderParameter.
@Test(description = "it should it should serialize a HeaderParameter")
public void serializeHeaderParameter() {
final Parameter p = new HeaderParameter().schema(new StringSchema());
final String json = "{\"in\":\"header\",\"schema\":{\"type\":\"string\"}}";
SerializationMatchers.assertEqualsToJson(p, json);
final String yaml = "---\n" + "in: \"header\"\n" + "schema:\n" + " type: \"string\"";
SerializationMatchers.assertEqualsToYaml(p, yaml);
}
Aggregations