Skip to content

Commit

Permalink
Revert "Merge pull request payara#5331 from aubi/FISH-1204"
Browse files Browse the repository at this point in the history
This reverts commit e0c842c

Signed-off-by: JamesHillyard <[email protected]>
  • Loading branch information
JamesHillyard committed Dec 22, 2021
1 parent af74670 commit f98db22
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 535 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2021] Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2018-2020] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -43,25 +43,30 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;

import fish.payara.microprofile.openapi.api.visitor.ApiContext;
import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl;
import fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl;
import fish.payara.microprofile.openapi.impl.model.util.ModelUtils;
import fish.payara.microprofile.openapi.impl.rest.app.provider.ObjectMapperFactory;

import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.applyReference;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.createList;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.createMap;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.extractAnnotations;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.mergeImmutableList;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.mergeProperty;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.readOnlyView;
import fish.payara.microprofile.openapi.impl.rest.app.provider.ObjectMapperFactory;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import static java.util.logging.Level.WARNING;

import java.util.logging.Logger;

import org.eclipse.microprofile.openapi.models.ExternalDocumentation;
import org.eclipse.microprofile.openapi.models.media.Discriminator;
import org.eclipse.microprofile.openapi.models.media.Schema;
Expand Down Expand Up @@ -128,25 +133,20 @@ public static SchemaImpl valueOf(String content) throws JsonMappingException, Js
.readValue(content, SchemaImpl.class);
}

@SuppressWarnings("unchecked")
public static SchemaImpl createInstance(AnnotationModel annotation, ApiContext context) {
SchemaImpl from = new SchemaImpl();

if (annotation == null) {
return from;
}

// Solve the required attribute before "ref" as it is the only one which doesn't conflict with it.
final Boolean isRequired = annotation.getValue("required", Boolean.class);
if (isRequired != null) {
from.isRequired = isRequired;
}

String ref = annotation.getValue("ref", String.class);
if (ref != null && !ref.isEmpty()) {
from.setRef(ref);
return from;
}

EnumModel typeEnum = annotation.getValue("type", EnumModel.class);
if (typeEnum != null) {
from.setType(SchemaType.valueOf(typeEnum.getValue()));
Expand Down Expand Up @@ -184,6 +184,11 @@ public static SchemaImpl createInstance(AnnotationModel annotation, ApiContext c
from.setMinProperties(annotation.getValue("minProperties", Integer.class));
from.setRequired(annotation.getValue("requiredProperties", List.class));

final Boolean isRequired = annotation.getValue("required", Boolean.class);
if (isRequired != null) {
from.isRequired = isRequired;
}

extractAnnotations(annotation, context, "properties", "name", SchemaImpl::createInstance, from::addProperty);
for (Entry<String, Schema> property : from.getProperties().entrySet()) {
final SchemaImpl propertySchema = (SchemaImpl) property.getValue();
Expand Down Expand Up @@ -920,7 +925,7 @@ private static void setImplementation(SchemaImpl schema, String implementationCl
} else {
schemaName = ModelUtils.getSimpleName(implementationClass);
}
// Get the schema reference, and copy it's values over to the new schema model if they are missing
// Get the schema reference, and copy it's values over to the new schema model
Schema copyFrom = context.getApi().getComponents().getSchemas().get(schemaName);
if (copyFrom == null) {
// If the class hasn't been parsed
Expand All @@ -929,9 +934,9 @@ private static void setImplementation(SchemaImpl schema, String implementationCl
}
if (schema.getType() == SchemaType.ARRAY) {
schema.setItems(new SchemaImpl());
ModelUtils.merge(copyFrom, schema.getItems(), false);
ModelUtils.merge(copyFrom, schema.getItems(), true);
} else {
ModelUtils.merge(copyFrom, schema, false);
ModelUtils.merge(copyFrom, schema, true);
}
schema.setRef(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
*/
package fish.payara.microprofile.openapi.impl.processor;

import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isVoid;

import fish.payara.microprofile.openapi.api.processor.OASProcessor;
import fish.payara.microprofile.openapi.api.visitor.ApiContext;
import fish.payara.microprofile.openapi.api.visitor.ApiVisitor;
Expand All @@ -61,20 +63,21 @@
import fish.payara.microprofile.openapi.impl.model.servers.ServerImpl;
import fish.payara.microprofile.openapi.impl.model.tags.TagImpl;
import fish.payara.microprofile.openapi.impl.model.util.ModelUtils;
import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isVoid;
import fish.payara.microprofile.openapi.impl.visitor.OpenApiWalker;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Level;
import java.util.Map.Entry;

import static java.util.logging.Level.FINE;
import static java.util.logging.Level.SEVERE;
import static java.util.logging.Level.WARNING;

import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import jakarta.ws.rs.DefaultValue;
Expand All @@ -85,16 +88,16 @@
import org.eclipse.microprofile.openapi.models.Components;
import org.eclipse.microprofile.openapi.models.ExternalDocumentation;
import org.eclipse.microprofile.openapi.models.OpenAPI;
import org.eclipse.microprofile.openapi.models.Operation;
import org.eclipse.microprofile.openapi.models.PathItem;
import org.eclipse.microprofile.openapi.models.Reference;
import org.eclipse.microprofile.openapi.models.callbacks.Callback;
import org.eclipse.microprofile.openapi.models.media.MediaType;
import org.eclipse.microprofile.openapi.models.media.Schema;
import org.eclipse.microprofile.openapi.models.media.Schema.SchemaType;
import org.eclipse.microprofile.openapi.models.parameters.Parameter;
import org.eclipse.microprofile.openapi.models.parameters.Parameter.In;
import org.eclipse.microprofile.openapi.models.parameters.RequestBody;
import org.eclipse.microprofile.openapi.models.Operation;
import org.eclipse.microprofile.openapi.models.media.Schema.SchemaType;
import org.eclipse.microprofile.openapi.models.responses.APIResponse;
import org.eclipse.microprofile.openapi.models.responses.APIResponses;
import org.eclipse.microprofile.openapi.models.security.SecurityRequirement;
Expand All @@ -109,9 +112,9 @@
import org.glassfish.hk2.classmodel.reflect.FieldModel;
import org.glassfish.hk2.classmodel.reflect.MethodModel;
import org.glassfish.hk2.classmodel.reflect.ParameterizedInterfaceModel;
import org.glassfish.hk2.classmodel.reflect.ParameterizedType;
import org.glassfish.hk2.classmodel.reflect.Type;
import org.glassfish.hk2.classmodel.reflect.Types;
import org.glassfish.hk2.classmodel.reflect.ParameterizedType;

/**
* A processor to parse the application for annotations, to add to the OpenAPI
Expand Down Expand Up @@ -630,7 +633,7 @@ private void visitSchemaField(AnnotationModel schemaAnnotation, FieldModel field
visitSchemaFieldOrMethod(schemaAnnotation, field, declaringType, typeName, context);
}

private void visitSchemaFieldOrMethod(AnnotationModel schemaAnnotation, AnnotatedElement fieldOrMethod,
public void visitSchemaFieldOrMethod(AnnotationModel schemaAnnotation, AnnotatedElement fieldOrMethod,
ExtensibleType<?> declaringType, String typeName, ApiContext context) {
assert (fieldOrMethod instanceof FieldModel) || (fieldOrMethod instanceof MethodModel);

Expand Down Expand Up @@ -1247,14 +1250,6 @@ private Schema createSchema(
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;
}
Expand Down

This file was deleted.

Loading

0 comments on commit f98db22

Please sign in to comment.