use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.
the class ApplicationProcessor method createSchema.
private Schema createSchema(Schema schema, ApiContext context, ParameterizedType type) {
String typeName = type.getTypeName();
List<ParameterizedType> genericTypes = type.getParameterizedTypes();
SchemaType schemaType = ModelUtils.getSchemaType(type, context);
if (schema == null) {
schema = new SchemaImpl();
schema.setType(schemaType);
}
// Set the subtype if it's an array (for example an array of ints)
if (schemaType == SchemaType.ARRAY) {
if (type.isArray()) {
schemaType = ModelUtils.getSchemaType(type.getTypeName(), context);
schema.setType(schemaType);
} else if (!genericTypes.isEmpty()) {
// should be something Iterable
schema.setItems(createSchema(context, genericTypes.get(0)));
}
}
// If the schema is an object, insert the reference
if (schemaType == SchemaType.OBJECT) {
if (insertObjectReference(context, schema, type.getType(), typeName)) {
schema.setType(null);
schema.setItems(null);
}
}
if (type instanceof AnnotatedElement) {
AnnotatedElement element = (AnnotatedElement) type;
final AnnotationModel schemaAnnotation = element.getAnnotation(org.eclipse.microprofile.openapi.annotations.media.Schema.class.getName());
if (schemaAnnotation != null) {
SchemaImpl.merge(SchemaImpl.createInstance(schemaAnnotation, context), schema, false, context);
}
}
return schema;
}
use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.
the class ApplicationProcessor method visitFormParam.
@Override
public void visitFormParam(AnnotationModel param, AnnotatedElement element, ApiContext context) {
// Find the aggregate schema type of all the parameters
SchemaType formSchemaType = null;
if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
List<org.glassfish.hk2.classmodel.reflect.Parameter> parameters = ((org.glassfish.hk2.classmodel.reflect.Parameter) element).getMethod().getParameters();
for (org.glassfish.hk2.classmodel.reflect.Parameter methodParam : parameters) {
if (methodParam.getAnnotation(FormParam.class.getName()) != null) {
formSchemaType = ModelUtils.getParentSchemaType(formSchemaType, ModelUtils.getSchemaType(methodParam, context));
}
}
}
final Operation workingOperation = context.getWorkingOperation();
if (workingOperation != null) {
// If there's no request body, fill out a new one right down to the schema
if (workingOperation.getRequestBody() == null) {
workingOperation.setRequestBody(new RequestBodyImpl().content(new ContentImpl().addMediaType(javax.ws.rs.core.MediaType.WILDCARD, new MediaTypeImpl().schema(new SchemaImpl()))));
}
for (MediaType mediaType : workingOperation.getRequestBody().getContent().getMediaTypes().values()) {
final Schema schema = mediaType.getSchema();
if (schema != null) {
schema.setType(formSchemaType);
}
}
}
}
use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.
the class ApplicationProcessor method visitParameter.
@Override
public void visitParameter(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
Parameter matchedParam = null;
Boolean hidden = annotation.getValue("hidden", Boolean.class);
if (hidden != null && hidden) {
return;
}
Parameter parameter = ParameterImpl.createInstance(annotation, context);
if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
matchedParam = findOperationParameterFor((org.glassfish.hk2.classmodel.reflect.Parameter) element, context);
}
if (element instanceof MethodModel) {
matchedParam = findOperationParameterFor(parameter, (MethodModel) element, context);
}
if (matchedParam != null) {
ParameterImpl.merge(parameter, matchedParam, true, context);
// If a content was added, and a schema type exists, reconfigure the schema type
if (matchedParam.getContent() != null && !matchedParam.getContent().getMediaTypes().isEmpty() && matchedParam.getSchema() != null && matchedParam.getSchema().getType() != null) {
SchemaType type = matchedParam.getSchema().getType();
matchedParam.setSchema(null);
for (MediaType mediaType : matchedParam.getContent().getMediaTypes().values()) {
if (mediaType.getSchema() == null) {
mediaType.setSchema(new SchemaImpl());
}
mediaType.getSchema().setType(ModelUtils.mergeProperty(mediaType.getSchema().getType(), type, false));
}
}
}
}
use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.
the class OpenApiWalker method addSchemasToPaths.
private void addSchemasToPaths() {
OpenAPI api = context.getApi();
api.getPaths().getPathItems().forEach((String s, PathItem t) -> {
t.getOperations().forEach((PathItem.HttpMethod u, org.eclipse.microprofile.openapi.models.Operation v) -> {
v.getResponses().getAPIResponses().forEach((String w, org.eclipse.microprofile.openapi.models.responses.APIResponse x) -> {
if (x.getContent() != null) {
x.getContent().getMediaTypes().forEach((y, z) -> {
SchemaImpl.merge(z.getSchema(), z.getSchema(), true, context);
if (z.getSchema() instanceof SchemaImpl) {
SchemaImpl schema = (SchemaImpl) z.getSchema();
schema.setImplementation(null);
}
});
}
});
});
});
}
use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.
the class ComponentsImpl method merge.
public static void merge(Components from, Components to, boolean override, ApiContext context) {
if (from == null) {
return;
}
// Handle @Schema
if (from.getSchemas() != null) {
for (Entry<String, Schema> fromEntry : from.getSchemas().entrySet()) {
final String schemaName = fromEntry.getKey();
if (schemaName != null) {
final Schema fromSchema = fromEntry.getValue();
final Schema toSchema = to.getSchemas().getOrDefault(schemaName, new SchemaImpl());
SchemaImpl.merge(fromSchema, toSchema, override, context);
to.addSchema(schemaName, toSchema);
}
}
}
// Handle @Callback
if (from.getCallbacks() != null) {
for (String callbackName : from.getCallbacks().keySet()) {
if (callbackName != null) {
Callback newCallback = new CallbackImpl();
CallbackImpl.merge(from.getCallbacks().get(callbackName), newCallback, override, context);
to.addCallback(callbackName, newCallback);
}
}
}
// Handle @ExampleObject
if (from.getExamples() != null) {
for (String exampleName : from.getExamples().keySet()) {
if (exampleName != null) {
Example newExample = new ExampleImpl();
ExampleImpl.merge(from.getExamples().get(exampleName), newExample, override);
to.addExample(exampleName, newExample);
}
}
}
// Handle @Header
if (from.getHeaders() != null) {
for (String headerName : from.getHeaders().keySet()) {
if (headerName != null) {
Header newHeader = new HeaderImpl();
HeaderImpl.merge(from.getHeaders().get(headerName), newHeader, override, context);
to.addHeader(headerName, newHeader);
}
}
}
// Handle @Link
if (from.getLinks() != null) {
for (String linkName : from.getLinks().keySet()) {
if (linkName != null) {
Link newLink = new LinkImpl();
LinkImpl.merge(from.getLinks().get(linkName), newLink, override);
to.addLink(linkName, newLink);
}
}
}
// Handle @Parameter
if (from.getParameters() != null) {
for (String parameterName : from.getParameters().keySet()) {
if (parameterName != null) {
Parameter newParameter = new ParameterImpl();
ParameterImpl.merge(from.getParameters().get(parameterName), newParameter, override, context);
to.addParameter(parameterName, newParameter);
}
}
}
// Handle @RequestBody
if (from.getRequestBodies() != null) {
for (String requestBodyName : from.getRequestBodies().keySet()) {
if (requestBodyName != null) {
RequestBody newRequestBody = new RequestBodyImpl();
RequestBodyImpl.merge(from.getRequestBodies().get(requestBodyName), newRequestBody, override, context);
to.addRequestBody(requestBodyName, newRequestBody);
}
}
}
// Handle @APIResponse
if (from.getResponses() != null) {
for (String responseName : from.getResponses().keySet()) {
if (responseName != null) {
APIResponse newResponse = new APIResponseImpl();
APIResponseImpl.merge(from.getResponses().get(responseName), newResponse, override, context);
to.addResponse(responseName, newResponse);
}
}
}
// Handle @SecurityScheme
if (from.getSecuritySchemes() != null) {
for (String securitySchemeName : from.getSecuritySchemes().keySet()) {
if (securitySchemeName != null) {
SecurityScheme newSecurity = new SecuritySchemeImpl();
SecuritySchemeImpl.merge(from.getSecuritySchemes().get(securitySchemeName), newSecurity, override);
to.addSecurityScheme(securitySchemeName, newSecurity);
}
}
}
}
Aggregations