use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.
the class HeaderImpl method merge.
public static void merge(Header from, Header to, boolean override, ApiContext context) {
if (from == null) {
return;
}
if (from.getRef() != null && !from.getRef().isEmpty()) {
applyReference(to, from.getRef());
return;
}
to.setDescription(mergeProperty(to.getDescription(), from.getDescription(), override));
to.setRequired(mergeProperty(to.getRequired(), from.getRequired(), override));
to.setDeprecated(mergeProperty(to.getDeprecated(), from.getDeprecated(), override));
to.setAllowEmptyValue(mergeProperty(to.getAllowEmptyValue(), from.getAllowEmptyValue(), override));
to.setStyle(Style.SIMPLE);
to.setExplode(mergeProperty(to.getExplode(), from.getExplode(), override));
if (from.getSchema() != null) {
if (to.getSchema() == null) {
to.setSchema(new SchemaImpl());
}
SchemaImpl.merge(from.getSchema(), to.getSchema(), override, context);
}
to.setExample(mergeProperty(to.getExample(), from.getExample(), override));
if (from.getExamples() != null) {
for (String exampleName : from.getExamples().keySet()) {
if (exampleName != null) {
Example example = new ExampleImpl();
ExampleImpl.merge(from.getExamples().get(exampleName), example, override);
to.addExample(exampleName, example);
}
}
}
if (from.getContent() != null) {
if (to.getContent() == null) {
to.setContent(new ContentImpl());
}
ContentImpl.merge((ContentImpl) from.getContent(), to.getContent(), override, context);
}
}
use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.
the class ApplicationProcessor method visitRequestBodySchema.
@Override
public void visitRequestBodySchema(AnnotationModel requestBodySchema, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel || element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
final RequestBody currentRequestBody = context.getWorkingOperation().getRequestBody();
if (currentRequestBody != null) {
final String implementationClass = requestBodySchema.getValue("value", String.class);
final SchemaImpl schema = SchemaImpl.fromImplementation(implementationClass, context);
for (MediaType mediaType : currentRequestBody.getContent().getMediaTypes().values()) {
mediaType.setSchema(schema);
}
}
}
}
use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.
the class ApplicationProcessor method visitSchemaParameter.
private static void visitSchemaParameter(AnnotationModel schemaAnnotation, org.glassfish.hk2.classmodel.reflect.Parameter parameter, ApiContext context) {
// If this is being parsed at the start, ignore it as the path doesn't exist
if (context.getWorkingOperation() == null) {
return;
}
// Check if it's a request body
if (ModelUtils.isRequestBody(context, parameter)) {
if (context.getWorkingOperation().getRequestBody() == null) {
context.getWorkingOperation().setRequestBody(new RequestBodyImpl());
}
// Insert the schema to the request body media type
MediaType mediaType = context.getWorkingOperation().getRequestBody().getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD);
Schema schema = SchemaImpl.createInstance(schemaAnnotation, context);
SchemaImpl.merge(schema, mediaType.getSchema(), true, context);
if (schema.getRef() != null && !schema.getRef().isEmpty()) {
mediaType.setSchema(new SchemaImpl().ref(schema.getRef()));
}
} else if (ModelUtils.getParameterType(context, parameter) != null) {
for (Parameter param : context.getWorkingOperation().getParameters()) {
if (param.getName().equals(ModelUtils.getParameterName(context, parameter))) {
Schema schema = SchemaImpl.createInstance(schemaAnnotation, context);
SchemaImpl.merge(schema, param.getSchema(), true, context);
if (schema.getRef() != null && !schema.getRef().isEmpty()) {
param.setSchema(new SchemaImpl().ref(schema.getRef()));
}
}
}
}
}
use of fish.payara.microprofile.openapi.impl.model.media.SchemaImpl in project Payara by payara.
the class ConfigPropertyProcessor method process.
@Override
public OpenAPI process(OpenAPI api, OpenApiConfiguration config) {
// Add the schemas
for (Entry<String, SchemaImpl> schemaEntry : config.getSchemaMap().entrySet()) {
final SchemaImpl schema = schemaEntry.getValue();
// The Java class name represented by the schema
final String schemaClassName = schemaEntry.getKey();
schema.setImplementation(schemaClassName);
// Get the name to use as the key for the Schema
String schemaName = schema.getName();
if (schemaName == null || schemaName.isEmpty()) {
schemaName = ModelUtils.getSimpleName(schemaClassName);
}
api.getComponents().addSchema(schemaName, schema);
}
return api;
}
Aggregations