use of io.swagger.v3.oas.annotations.media.Schema in project activityinfo by bedatadriven.
the class FormResource method getXlsForm.
@GET
@NoCache
@Path("form.xls")
@Operation(summary = "Get a form's schema as an XLSForm")
public Response getXlsForm() {
assertVisible(formId);
final XlsFormBuilder xlsForm = new XlsFormBuilder(backend.getStorage());
xlsForm.build(formId);
StreamingOutput output = xlsForm::write;
return Response.ok(output, "application/vnd.ms-excel").build();
}
use of io.swagger.v3.oas.annotations.media.Schema 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.media.Schema in project syncope by apache.
the class SyncopeOpenApiCustomizer method addParameters.
@Override
protected void addParameters(final List<Parameter> parameters) {
if (domains == null) {
domains = new ArrayList<>(ApplicationContextProvider.getApplicationContext().getBean(DomainsHolder.class).getDomains().keySet());
}
Optional<Parameter> domainHeaderParameter = parameters.stream().filter(parameter -> parameter instanceof HeaderParameter && RESTHeaders.DOMAIN.equals(parameter.getName())).findFirst();
if (!domainHeaderParameter.isPresent()) {
HeaderParameter parameter = new HeaderParameter();
parameter.setName(RESTHeaders.DOMAIN);
parameter.setRequired(true);
Schema<String> schema = new Schema<>();
schema.setType("string");
schema.setEnum(domains);
schema.setDefault(SyncopeConstants.MASTER_DOMAIN);
parameter.setSchema(schema);
parameters.add(parameter);
}
}
use of io.swagger.v3.oas.annotations.media.Schema in project flink by apache.
the class OpenApiSpecGenerator method createDocumentationFile.
@VisibleForTesting
static void createDocumentationFile(DocumentingRestEndpoint restEndpoint, RestAPIVersion apiVersion, Path outputFile) throws IOException {
final OpenAPI openApi = new OpenAPI();
// eagerly initialize some data-structures to simplify operations later on
openApi.setPaths(new io.swagger.v3.oas.models.Paths());
openApi.setComponents(new Components());
setInfo(openApi, apiVersion);
List<MessageHeaders> specs = restEndpoint.getSpecs().stream().filter(spec -> spec.getSupportedAPIVersions().contains(apiVersion)).filter(OpenApiSpecGenerator::shouldBeDocumented).collect(Collectors.toList());
specs.forEach(spec -> add(spec, openApi));
final List<Schema> asyncOperationSchemas = collectAsyncOperationResultVariants(specs);
// this adds the schema for every JSON object
openApi.components(new Components().schemas(new HashMap<>(modelConverterContext.getDefinedModels())));
injectAsyncOperationResultSchema(openApi, asyncOperationSchemas);
overrideIdSchemas(openApi);
overrideSerializeThrowableSchema(openApi);
Files.deleteIfExists(outputFile);
Files.write(outputFile, Yaml.pretty(openApi).getBytes(StandardCharsets.UTF_8));
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-core by swagger-api.
the class ParameterProcessor method applyAnnotations.
public static Parameter applyAnnotations(Parameter parameter, Type type, List<Annotation> annotations, Components components, String[] classTypes, String[] methodTypes, JsonView jsonViewAnnotation) {
final AnnotationsHelper helper = new AnnotationsHelper(annotations, type);
if (helper.isContext()) {
return null;
}
if (parameter == null) {
// consider it to be body param
parameter = new Parameter();
}
// first handle schema
List<Annotation> reworkedAnnotations = new ArrayList<>(annotations);
Annotation paramSchemaOrArrayAnnotation = getParamSchemaAnnotation(annotations);
if (paramSchemaOrArrayAnnotation != null) {
reworkedAnnotations.add(paramSchemaOrArrayAnnotation);
}
AnnotatedType annotatedType = new AnnotatedType().type(type).resolveAsRef(true).skipOverride(true).jsonViewAnnotation(jsonViewAnnotation).ctxAnnotations(reworkedAnnotations.toArray(new Annotation[reworkedAnnotations.size()]));
ResolvedSchema resolvedSchema = ModelConverters.getInstance().resolveAsResolvedSchema(annotatedType);
if (resolvedSchema.schema != null) {
parameter.setSchema(resolvedSchema.schema);
}
resolvedSchema.referencedSchemas.forEach(components::addSchemas);
// handle first FormParam as it affects Explode resolving
for (Annotation annotation : annotations) {
if (annotation.annotationType().getName().equals("javax.ws.rs.FormParam")) {
try {
String name = (String) annotation.annotationType().getMethod("value").invoke(annotation);
if (StringUtils.isNotBlank(name)) {
parameter.setName(name);
}
} catch (Exception e) {
}
// set temporarily to "form" to inform caller that we need to further process along other form parameters
parameter.setIn("form");
} else if (annotation.annotationType().getName().endsWith("FormDataParam")) {
try {
String name = (String) annotation.annotationType().getMethod("value").invoke(annotation);
if (StringUtils.isNotBlank(name)) {
parameter.setName(name);
}
} catch (Exception e) {
}
// set temporarily to "form" to inform caller that we need to further process along other form parameters
parameter.setIn("form");
}
}
for (Annotation annotation : annotations) {
if (annotation instanceof io.swagger.v3.oas.annotations.Parameter) {
io.swagger.v3.oas.annotations.Parameter p = (io.swagger.v3.oas.annotations.Parameter) annotation;
if (p.hidden()) {
return null;
}
if (StringUtils.isNotBlank(p.ref())) {
parameter = new Parameter().$ref(p.ref());
return parameter;
}
if (StringUtils.isNotBlank(p.description())) {
parameter.setDescription(p.description());
}
if (StringUtils.isNotBlank(p.name())) {
parameter.setName(p.name());
}
if (StringUtils.isNotBlank(p.in().toString())) {
parameter.setIn(p.in().toString());
}
if (StringUtils.isNotBlank(p.example())) {
try {
parameter.setExample(Json.mapper().readTree(p.example()));
} catch (IOException e) {
parameter.setExample(p.example());
}
}
if (p.deprecated()) {
parameter.setDeprecated(p.deprecated());
}
if (p.required()) {
parameter.setRequired(p.required());
}
if (p.allowEmptyValue()) {
parameter.setAllowEmptyValue(p.allowEmptyValue());
}
if (p.allowReserved()) {
parameter.setAllowReserved(p.allowReserved());
}
Map<String, Example> exampleMap = new LinkedHashMap<>();
if (p.examples().length == 1 && StringUtils.isBlank(p.examples()[0].name())) {
Optional<Example> exampleOptional = AnnotationsUtils.getExample(p.examples()[0], true);
if (exampleOptional.isPresent()) {
parameter.setExample(exampleOptional.get());
}
} else {
for (ExampleObject exampleObject : p.examples()) {
AnnotationsUtils.getExample(exampleObject).ifPresent(example -> exampleMap.put(exampleObject.name(), example));
}
}
if (exampleMap.size() > 0) {
parameter.setExamples(exampleMap);
}
if (p.extensions().length > 0) {
Map<String, Object> extensionMap = AnnotationsUtils.getExtensions(p.extensions());
if (extensionMap != null && !extensionMap.isEmpty()) {
extensionMap.forEach(parameter::addExtension);
}
}
Optional<Content> content = AnnotationsUtils.getContent(p.content(), classTypes, methodTypes, parameter.getSchema(), null, jsonViewAnnotation);
if (content.isPresent()) {
parameter.setContent(content.get());
parameter.setSchema(null);
}
setParameterStyle(parameter, p);
setParameterExplode(parameter, p);
} else if (annotation.annotationType().getName().equals("javax.ws.rs.PathParam")) {
try {
String name = (String) annotation.annotationType().getMethod("value").invoke(annotation);
if (StringUtils.isNotBlank(name)) {
parameter.setName(name);
}
} catch (Exception e) {
}
} else if (annotation.annotationType().getName().equals("javax.validation.constraints.Size")) {
try {
if (parameter.getSchema() == null) {
parameter.setSchema(new ArraySchema());
}
if (parameter.getSchema() instanceof ArraySchema) {
ArraySchema as = (ArraySchema) parameter.getSchema();
Integer min = (Integer) annotation.annotationType().getMethod("min").invoke(annotation);
if (min != null) {
as.setMinItems(min);
}
Integer max = (Integer) annotation.annotationType().getMethod("max").invoke(annotation);
if (max != null) {
as.setMaxItems(max);
}
}
} catch (Exception e) {
LOGGER.error("failed on " + annotation.annotationType().getName(), e);
}
} else if (ModelResolver.NOT_NULL_ANNOTATIONS.contains(annotation.annotationType().getSimpleName())) {
parameter.setRequired(true);
}
}
final String defaultValue = helper.getDefaultValue();
Schema paramSchema = parameter.getSchema();
if (paramSchema == null) {
if (parameter.getContent() != null && !parameter.getContent().values().isEmpty()) {
paramSchema = parameter.getContent().values().iterator().next().getSchema();
}
}
if (paramSchema != null) {
if (paramSchema instanceof ArraySchema) {
ArraySchema as = (ArraySchema) paramSchema;
if (defaultValue != null) {
as.getItems().setDefault(defaultValue);
}
} else {
if (defaultValue != null) {
paramSchema.setDefault(defaultValue);
}
}
}
return parameter;
}
Aggregations