Search in sources :

Example 26 with Header

use of io.swagger.v3.oas.annotations.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);
}
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 27 with Header

use of io.swagger.v3.oas.annotations.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);
}
Also used : Parameter(io.swagger.v3.oas.models.parameters.Parameter) Test(org.testng.annotations.Test)

Example 28 with Header

use of io.swagger.v3.oas.annotations.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());
    }
}
Also used : List(java.util.List) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme) SecurityRequirement(io.swagger.v3.oas.models.security.SecurityRequirement) Test(org.testng.annotations.Test)

Example 29 with Header

use of io.swagger.v3.oas.annotations.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");
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 30 with Header

use of io.swagger.v3.oas.annotations.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);
}
Also used : Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) StringSchema(io.swagger.v3.oas.models.media.StringSchema) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)32 OpenAPI (io.swagger.v3.oas.models.OpenAPI)26 Header (io.swagger.v3.oas.models.headers.Header)25 Parameter (io.swagger.v3.oas.models.parameters.Parameter)16 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)13 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)11 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)11 Schema (io.swagger.v3.oas.models.media.Schema)10 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)10 MediaType (io.swagger.v3.oas.models.media.MediaType)8 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)8 Components (io.swagger.v3.oas.models.Components)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 StringSchema (io.swagger.v3.oas.models.media.StringSchema)6 AuthorizationValue (io.swagger.v3.parser.core.models.AuthorizationValue)6 PathItem (io.swagger.v3.oas.models.PathItem)5 Example (io.swagger.v3.oas.models.examples.Example)5 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)5 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)5 RefFormat (io.swagger.v3.parser.models.RefFormat)5