use of io.swagger.v3.oas.models.info.Info in project flow by vaadin.
the class SchemaGenerator method getFieldsAndOptionalMap.
/**
* Because it's not possible to check the `transient` modifier and
* annotation of a field using JavaParser API. We need this method to
* reflect the type and get those information from the reflected object.
*
* @param type
* type of the class to get fields information
* @return set of fields' name that we should generate.
*/
private Map<String, Boolean> getFieldsAndOptionalMap(GeneratorType type) {
ResolvedReferenceType resolvedReferenceType = type.asResolvedType().asReferenceType();
Optional<ResolvedReferenceTypeDeclaration> typeDeclaration = resolvedReferenceType.getTypeDeclaration();
if (!typeDeclaration.filter(td -> td.isClass() && !td.isAnonymousClass()).isPresent()) {
return Collections.emptyMap();
}
HashMap<String, Boolean> validFields = new HashMap<>();
try {
Class<?> aClass = openApiObjectGenerator.getClassFromReflection(type);
Arrays.stream(aClass.getDeclaredFields()).filter(field -> {
int modifiers = field.getModifiers();
return !Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers) && !field.isAnnotationPresent(JsonIgnore.class);
}).forEach(field -> validFields.put(field.getName(), !ExplicitNullableTypeChecker.isRequired(field)));
} catch (ClassNotFoundException e) {
String message = String.format("Can't get list of fields from class '%s'." + "Please make sure that class '%s' is in your project's compile classpath. " + "As the result, the generated TypeScript file will be empty.", resolvedReferenceType.getQualifiedName(), resolvedReferenceType.getQualifiedName());
getLogger().info(message);
getLogger().debug(message, e);
}
return validFields;
}
use of io.swagger.v3.oas.models.info.Info in project cxf by apache.
the class OpenApiFeature method initialize.
@Override
public void initialize(Server server, Bus bus) {
final JAXRSServiceFactoryBean sfb = (JAXRSServiceFactoryBean) server.getEndpoint().get(JAXRSServiceFactoryBean.class.getName());
final ServerProviderFactory factory = (ServerProviderFactory) server.getEndpoint().get(ServerProviderFactory.class.getName());
final Set<String> packages = new HashSet<>();
if (resourcePackages != null) {
packages.addAll(resourcePackages);
}
Properties swaggerProps = null;
GenericOpenApiContextBuilder<?> openApiConfiguration;
final Application application = getApplicationOrDefault(server, factory, sfb, bus);
if (StringUtils.isEmpty(getConfigLocation())) {
swaggerProps = getSwaggerProperties(propertiesLocation, bus);
if (isScan()) {
packages.addAll(scanResourcePackages(sfb));
}
final OpenAPI oas = new OpenAPI().info(getInfo(swaggerProps));
registerComponents(securityDefinitions).ifPresent(oas::setComponents);
final SwaggerConfiguration config = new SwaggerConfiguration().openAPI(oas).prettyPrint(getOrFallback(isPrettyPrint(), swaggerProps, PRETTY_PRINT_PROPERTY)).readAllResources(isReadAllResources()).ignoredRoutes(getIgnoredRoutes()).filterClass(getOrFallback(getFilterClass(), swaggerProps, FILTER_CLASS_PROPERTY)).resourceClasses(getResourceClasses()).resourcePackages(getOrFallback(packages, swaggerProps, RESOURCE_PACKAGE_PROPERTY));
openApiConfiguration = new JaxrsOpenApiContextBuilder<>().application(application).openApiConfiguration(config);
} else {
openApiConfiguration = new JaxrsOpenApiContextBuilder<>().application(application).configLocation(getConfigLocation());
}
try {
final OpenApiContext context = openApiConfiguration.buildContext(true);
final Properties userProperties = getUserProperties(context.getOpenApiConfiguration().getUserDefinedOptions());
registerOpenApiResources(sfb, packages, context.getOpenApiConfiguration());
registerSwaggerUiResources(sfb, combine(swaggerProps, userProperties), factory, bus);
if (customizer != null) {
customizer.setApplicationInfo(factory.getApplicationProvider());
}
} catch (OpenApiConfigurationException ex) {
throw new RuntimeException("Unable to initialize OpenAPI context", ex);
}
}
use of io.swagger.v3.oas.models.info.Info in project hippo by NHS-digital-website.
the class ApiSpecificationStaticHtml2Codegen method sanitiseDefaultDate.
private Optional<String> sanitiseDefaultDate(final String defaultValue, final String dataFormat, final String parameter) {
if ("date".equals(dataFormat) && StringUtils.isNotBlank(defaultValue)) {
// Sun Jan 01 00:00:00 GMT 1984
final String pattern = "E MMM dd HH:mm:ss VV uuuu";
final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
try {
return Optional.of(LocalDate.parse(defaultValue.trim(), dateTimeFormatter).toString());
} catch (final Exception e) {
final String apiTitle = Optional.ofNullable(openAPI.getInfo()).map(Info::getTitle).orElse("n/a");
log.warn("Unable to fix default value of '{}' as ISO-8601 format uuuu-MM-dd despite format being 'date' for parameter '{}' in API specification '{}'.", defaultValue, parameter, apiTitle);
}
}
return Optional.empty();
}
use of io.swagger.v3.oas.models.info.Info in project carbon-apimgt by wso2.
the class OAS3Parser method updateOperationManagedInfo.
/**
* Updates managed info of a provided operation such as auth type and throttling
*
* @param resource API resource data
* @param operation swagger operation
*/
private void updateOperationManagedInfo(SwaggerData.Resource resource, Operation operation) {
String authType = resource.getAuthType();
if (APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN.equals(authType)) {
authType = "Application & Application User";
}
if (APIConstants.AUTH_APPLICATION_USER_LEVEL_TOKEN.equals(authType)) {
authType = "Application User";
}
if (APIConstants.AUTH_APPLICATION_LEVEL_TOKEN.equals(authType)) {
authType = "Application";
}
operation.addExtension(APIConstants.SWAGGER_X_AUTH_TYPE, authType);
if (resource.getPolicy() != null) {
operation.addExtension(APIConstants.SWAGGER_X_THROTTLING_TIER, resource.getPolicy());
} else {
operation.addExtension(APIConstants.SWAGGER_X_THROTTLING_TIER, APIConstants.DEFAULT_API_POLICY_UNLIMITED);
}
// AWS Lambda: set arn & timeout to swagger
if (resource.getAmznResourceName() != null) {
operation.addExtension(APIConstants.SWAGGER_X_AMZN_RESOURCE_NAME, resource.getAmznResourceName());
}
if (resource.getAmznResourceTimeout() != 0) {
operation.addExtension(APIConstants.SWAGGER_X_AMZN_RESOURCE_TIMEOUT, resource.getAmznResourceTimeout());
}
updateLegacyScopesFromOperation(resource, operation);
List<SecurityRequirement> security = operation.getSecurity();
if (security == null) {
security = new ArrayList<>();
operation.setSecurity(security);
}
for (Map<String, List<String>> requirement : security) {
if (requirement.get(OPENAPI_SECURITY_SCHEMA_KEY) != null) {
if (resource.getScopes().isEmpty()) {
requirement.put(OPENAPI_SECURITY_SCHEMA_KEY, Collections.EMPTY_LIST);
} else {
requirement.put(OPENAPI_SECURITY_SCHEMA_KEY, resource.getScopes().stream().map(Scope::getKey).collect(Collectors.toList()));
}
return;
}
}
// if oauth2SchemeKey not present, add a new
SecurityRequirement defaultRequirement = new SecurityRequirement();
if (resource.getScopes().isEmpty()) {
defaultRequirement.put(OPENAPI_SECURITY_SCHEMA_KEY, Collections.EMPTY_LIST);
} else {
defaultRequirement.put(OPENAPI_SECURITY_SCHEMA_KEY, resource.getScopes().stream().map(Scope::getKey).collect(Collectors.toList()));
}
security.add(defaultRequirement);
}
use of io.swagger.v3.oas.models.info.Info in project carbon-apimgt by wso2.
the class OAS3Parser method generateAPIDefinition.
/**
* This method generates API definition to the given api
*
* @param swaggerData api
* @return API definition in string format
* @throws APIManagementException
*/
@Override
public String generateAPIDefinition(SwaggerData swaggerData) throws APIManagementException {
OpenAPI openAPI = new OpenAPI();
// create path if null
if (openAPI.getPaths() == null) {
openAPI.setPaths(new Paths());
}
// Create info object
Info info = new Info();
info.setTitle(swaggerData.getTitle());
if (swaggerData.getDescription() != null) {
info.setDescription(swaggerData.getDescription());
}
Contact contact = new Contact();
// Create contact object and map business owner info
if (swaggerData.getContactName() != null) {
contact.setName(swaggerData.getContactName());
}
if (swaggerData.getContactEmail() != null) {
contact.setEmail(swaggerData.getContactEmail());
}
if (swaggerData.getContactName() != null || swaggerData.getContactEmail() != null) {
// put contact object to info object
info.setContact(contact);
}
info.setVersion(swaggerData.getVersion());
openAPI.setInfo(info);
updateSwaggerSecurityDefinition(openAPI, swaggerData, OPENAPI_DEFAULT_AUTHORIZATION_URL);
updateLegacyScopesFromSwagger(openAPI, swaggerData);
if (APIConstants.GRAPHQL_API.equals(swaggerData.getTransportType())) {
modifyGraphQLSwagger(openAPI);
} else {
for (SwaggerData.Resource resource : swaggerData.getResources()) {
addOrUpdatePathToSwagger(openAPI, resource);
}
}
return Json.pretty(openAPI);
}
Aggregations