use of io.swagger.v3.oas.annotations.headers.Header in project swagger-core by swagger-api.
the class ParameterSerializationTest method serializeStringArrayHeaderParameter.
@Test(description = "it should serialize a string array HeaderParameter")
public void serializeStringArrayHeaderParameter() {
final Parameter p = new HeaderParameter().schema(new ArraySchema().items(new StringSchema()));
final String json = "{\"in\":\"header\",\"schema\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}";
SerializationMatchers.assertEqualsToJson(p, json);
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-core by swagger-api.
the class ReaderTest method testSecuritySchemeWithRef.
@Test(description = "SecurityScheme with REf")
public void testSecuritySchemeWithRef() {
Components components = new Components();
components.addSecuritySchemes("Security", new SecurityScheme().description("Security Example").name("Security").type(SecurityScheme.Type.OAUTH2).$ref("myOauth2Security").in(SecurityScheme.In.HEADER));
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(RefSecurityResource.class);
String yaml = "openapi: 3.0.1\n" + "info:\n" + " description: info\n" + "paths:\n" + " /:\n" + " get:\n" + " description: description\n" + " operationId: Operation Id\n" + " responses:\n" + " default:\n" + " description: default response\n" + " content:\n" + " '*/*': {}\n" + " security:\n" + " - security_key:\n" + " - write:pets\n" + " - read:pets\n" + "components:\n" + " securitySchemes:\n" + " Security:\n" + " type: oauth2\n" + " description: Security Example\n" + " myOauth2Security:\n" + " type: oauth2\n" + " description: myOauthSecurity Description\n" + " $ref: '#/components/securitySchemes/Security'\n" + " in: header\n" + " flows:\n" + " implicit:\n" + " authorizationUrl: http://x.com\n" + " scopes:\n" + " write:pets: modify pets in your account\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.oas.annotations.headers.Header in project swagger-core by swagger-api.
the class ReaderTest method testHeaderWithRef.
@Test(description = "Header with Ref")
public void testHeaderWithRef() {
Components components = new Components();
components.addHeaders("Header", new Header().description("Header Description"));
OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
Reader reader = new Reader(oas);
OpenAPI openAPI = reader.read(RefHeaderResource.class);
String yaml = "openapi: 3.0.1\n" + "info:\n" + " description: info\n" + "paths:\n" + " /path:\n" + " get:\n" + " summary: Simple get operation\n" + " description: Defines a simple get operation with no inputs and a complex output\n" + " operationId: getWithPayloadResponse\n" + " responses:\n" + " \"200\":\n" + " description: voila!\n" + " headers:\n" + " Rate-Limit-Limit:\n" + " description: The number of allowed requests in the current period\n" + " $ref: '#/components/headers/Header'\n" + " style: simple\n" + " schema:\n" + " type: integer\n" + " deprecated: true\n" + "components:\n" + " headers:\n" + " Header:\n" + " description: Header Description\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.oas.annotations.headers.Header in project carbon-apimgt by wso2.
the class OAS3Parser method setExtensionsToAPI.
/**
* This method returns api that is attached with api extensions related to micro-gw
*
* @param apiDefinition String
* @param api API
* @return API
*/
@Override
public API setExtensionsToAPI(String apiDefinition, API api) throws APIManagementException {
OpenAPI openAPI = getOpenAPI(apiDefinition);
Map<String, Object> extensions = openAPI.getExtensions();
if (extensions == null) {
return api;
}
// Setup Custom auth header for API
String authHeader = OASParserUtil.getAuthorizationHeaderFromSwagger(extensions);
if (StringUtils.isNotBlank(authHeader)) {
api.setAuthorizationHeader(authHeader);
}
// Setup application Security
List<String> applicationSecurity = OASParserUtil.getApplicationSecurityTypes(extensions);
Boolean isOptional = OASParserUtil.getAppSecurityStateFromSwagger(extensions);
if (!applicationSecurity.isEmpty()) {
String securityList = api.getApiSecurity();
securityList = securityList == null ? "" : securityList;
for (String securityType : applicationSecurity) {
if (APIConstants.DEFAULT_API_SECURITY_OAUTH2.equals(securityType) && !securityList.contains(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) {
securityList = securityList + "," + APIConstants.DEFAULT_API_SECURITY_OAUTH2;
}
if (APIConstants.API_SECURITY_BASIC_AUTH.equals(securityType) && !securityList.contains(APIConstants.API_SECURITY_BASIC_AUTH)) {
securityList = securityList + "," + APIConstants.API_SECURITY_BASIC_AUTH;
}
if (APIConstants.API_SECURITY_API_KEY.equals(securityType) && !securityList.contains(APIConstants.API_SECURITY_API_KEY)) {
securityList = securityList + "," + APIConstants.API_SECURITY_API_KEY;
}
}
if (!(isOptional || securityList.contains(APIConstants.MANDATORY))) {
securityList = securityList + "," + APIConstants.MANDATORY;
}
api.setApiSecurity(securityList);
}
// Setup mutualSSL configuration
String mutualSSL = OASParserUtil.getMutualSSLEnabledFromSwagger(extensions);
if (StringUtils.isNotBlank(mutualSSL)) {
String securityList = api.getApiSecurity();
if (StringUtils.isBlank(securityList)) {
securityList = APIConstants.DEFAULT_API_SECURITY_OAUTH2;
}
if (APIConstants.OPTIONAL.equals(mutualSSL) && !securityList.contains(APIConstants.API_SECURITY_MUTUAL_SSL)) {
securityList = securityList + "," + APIConstants.API_SECURITY_MUTUAL_SSL;
} else if (APIConstants.MANDATORY.equals(mutualSSL) && !securityList.contains(APIConstants.API_SECURITY_MUTUAL_SSL_MANDATORY)) {
securityList = securityList + "," + APIConstants.API_SECURITY_MUTUAL_SSL + "," + APIConstants.API_SECURITY_MUTUAL_SSL_MANDATORY;
}
api.setApiSecurity(securityList);
}
// Setup CORSConfigurations
CORSConfiguration corsConfiguration = OASParserUtil.getCorsConfigFromSwagger(extensions);
if (corsConfiguration != null) {
api.setCorsConfiguration(corsConfiguration);
}
// Setup Response cache enabling
boolean responseCacheEnable = OASParserUtil.getResponseCacheFromSwagger(extensions);
if (responseCacheEnable) {
api.setResponseCache(APIConstants.ENABLED);
}
// Setup cache timeOut
int cacheTimeOut = OASParserUtil.getCacheTimeOutFromSwagger(extensions);
if (cacheTimeOut != 0) {
api.setCacheTimeout(cacheTimeOut);
}
// Setup Transports
String transports = OASParserUtil.getTransportsFromSwagger(extensions);
if (StringUtils.isNotBlank(transports)) {
api.setTransports(transports);
}
// Setup Throttlingtiers
String throttleTier = OASParserUtil.getThrottleTierFromSwagger(extensions);
if (StringUtils.isNotBlank(throttleTier)) {
api.setApiLevelPolicy(throttleTier);
}
return api;
}
use of io.swagger.v3.oas.annotations.headers.Header in project carbon-apimgt by wso2.
the class OASParserUtil method setRefOfApiResponseHeaders.
private static void setRefOfApiResponseHeaders(ApiResponses responses, SwaggerUpdateContext context) {
if (responses != null) {
for (ApiResponse response : responses.values()) {
Map<String, Header> headers = response.getHeaders();
if (headers != null) {
for (Header header : headers.values()) {
Content content = header.getContent();
extractReferenceFromContent(content, context);
}
}
}
}
}
Aggregations