@FFDCIgnore(IOException.class)
    public static Parameter applyAnnotations(Parameter parameter, Type type, List<Annotation> annotations, Components components, String[] classTypes, String[] methodTypes) {

        final AnnotationsHelper helper = new AnnotationsHelper(annotations, type);
        if (helper.isContext()) {
            return null;
        }
        if (parameter == null) {
            // consider it to be body param
            parameter = new ParameterImpl();
        }

        // first handle schema
        List<Annotation> reworkedAnnotations = new ArrayList<>(annotations);
        Annotation paramSchemaOrArrayAnnotation = getParamSchemaAnnotation(annotations);
        Schema schemaFromAnn = null;
        if (paramSchemaOrArrayAnnotation != null) {
            reworkedAnnotations.add(paramSchemaOrArrayAnnotation);
            if (paramSchemaOrArrayAnnotation instanceof org.eclipse.microprofile.openapi.annotations.media.Schema) {
                org.eclipse.microprofile.openapi.annotations.media.Schema schemaAnn = (org.eclipse.microprofile.openapi.annotations.media.Schema) paramSchemaOrArrayAnnotation;
                schemaFromAnn = AnnotationsUtils.getSchema(schemaAnn, components).orElse(null);
            }
        }

        ResolvedSchema resolvedSchema = ModelConverters.getInstance().resolveAnnotatedType(type, reworkedAnnotations, "");

        if (resolvedSchema.schema != null) {
            if (schemaFromAnn != null) {
                if (schemaFromAnn.getAllOf() != null) {
                    resolvedSchema.schema.setAllOf(schemaFromAnn.getAllOf());
                    resolvedSchema.schema.setType(null);
                }
                if (schemaFromAnn.getAnyOf() != null) {
                    resolvedSchema.schema.setAnyOf(schemaFromAnn.getAnyOf());
                    resolvedSchema.schema.setType(null);
                }
                if (schemaFromAnn.getOneOf() != null) {
                    resolvedSchema.schema.setOneOf(schemaFromAnn.getOneOf());
                    resolvedSchema.schema.setType(null);
                }
                if (schemaFromAnn.getNot() != null) {
                    resolvedSchema.schema.setNot(schemaFromAnn.getNot());
                    resolvedSchema.schema.setType(null);
                }
            }
            parameter.setSchema(resolvedSchema.schema);
        }
        resolvedSchema.referencedSchemas.forEach((key, schema) -> components.addSchema(key, schema));

        for (Annotation annotation : annotations) {
            if (annotation instanceof org.eclipse.microprofile.openapi.annotations.parameters.Parameter) {
                org.eclipse.microprofile.openapi.annotations.parameters.Parameter p = (org.eclipse.microprofile.openapi.annotations.parameters.Parameter) annotation;
                if (p.hidden()) {
                    return null;
                }
                if (StringUtils.isNotBlank(p.ref())) {
                    parameter.setRef(p.ref());
                }
                if (StringUtils.isNotBlank(p.description())) {
                    parameter.setDescription(p.description());
                }
                if (StringUtils.isNotBlank(p.name())) {
                    parameter.setName(p.name());
                }
                if (StringUtils.isNotBlank(p.in().toString())) {
                    ((ParameterImpl) parameter).setIn(Parameter.In.valueOf(p.in().toString().toUpperCase()));
                }
                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 HashMap<>();
                for (ExampleObject exampleObject : p.examples()) {
                    AnnotationsUtils.getExample(exampleObject).ifPresent(example -> exampleMap.put(AnnotationsUtils.getNameOfReferenceableItem(exampleObject), example));
                }
                if (exampleMap.size() > 0) {
                    parameter.setExamples(exampleMap);
                }

                Optional<Content> content = AnnotationsUtils.getContent(p.content(), classTypes, methodTypes, parameter.getSchema());
                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 SchemaImpl().type(SchemaType.ARRAY));
                    }
                    if (parameter.getSchema().getType() == SchemaType.ARRAY) {
                        Integer min = (Integer) annotation.annotationType().getMethod("min").invoke(annotation);
                        if (min != null) {
                            parameter.getSchema().setMinItems(min);
                        }
                        Integer max = (Integer) annotation.annotationType().getMethod("max").invoke(annotation);
                        if (max != null) {
                            parameter.getSchema().setMaxItems(max);
                        }
                    }

                } catch (Exception e) {
                    //LOGGER.error("failed on " + annotation.annotationType().getName(), e);
                }
            }
        }
        final String defaultValue = helper.getDefaultValue();

        Schema paramSchema = parameter.getSchema();
        if (paramSchema == null) {
            if (parameter.getContent() != null && parameter.getContent().values().size() > 0) {
                paramSchema = parameter.getContent().values().iterator().next().getSchema();
            }
        }
        if (paramSchema != null) {
            if (paramSchema.getType() == SchemaType.ARRAY) {
                if (defaultValue != null) {
                    paramSchema.getItems().setDefaultValue(defaultValue);
                }
            } else {
                if (defaultValue != null) {
                    paramSchema.setDefaultValue(defaultValue);
                }
            }
        }
        return parameter;
    }
@ FFDCIgnore ( IOException . class ) public static Parameter applyAnnotations ( Parameter parameter , Type type , List < Annotation > annotations , Components components , String [ ] classTypes , String [ ] methodTypes ) { final AnnotationsHelper helper = new AnnotationsHelper ( annotations , type ) ; if ( helper . isContext ( ) ) { return null ; } if ( parameter == null ) { parameter = new ParameterImpl ( ) ; } List < Annotation > reworkedAnnotations = new ArrayList < > ( annotations ) ; Annotation paramSchemaOrArrayAnnotation = getParamSchemaAnnotation ( annotations ) ; Schema schemaFromAnn = null ; if ( paramSchemaOrArrayAnnotation != null ) { reworkedAnnotations . add ( paramSchemaOrArrayAnnotation ) ; if ( paramSchemaOrArrayAnnotation instanceof org . eclipse . microprofile . openapi . annotations . media . Schema ) { org . eclipse . microprofile . openapi . annotations . media . Schema schemaAnn = ( org . eclipse . microprofile . openapi . annotations . media . Schema ) paramSchemaOrArrayAnnotation ; schemaFromAnn = AnnotationsUtils . getSchema ( schemaAnn , components ) . orElse ( null ) ; } } ResolvedSchema resolvedSchema = ModelConverters . getInstance ( ) . resolveAnnotatedType ( type , reworkedAnnotations , "" ) ; if ( resolvedSchema . schema != null ) { if ( schemaFromAnn != null ) { if ( schemaFromAnn . getAllOf ( ) != null ) { resolvedSchema . schema . setAllOf ( schemaFromAnn . getAllOf ( ) ) ; resolvedSchema . schema . setType ( null ) ; } if ( schemaFromAnn . getAnyOf ( ) != null ) { resolvedSchema . schema . setAnyOf ( schemaFromAnn . getAnyOf ( ) ) ; resolvedSchema . schema . setType ( null ) ; } if ( schemaFromAnn . getOneOf ( ) != null ) { resolvedSchema . schema . setOneOf ( schemaFromAnn . getOneOf ( ) ) ; resolvedSchema . schema . setType ( null ) ; } if ( schemaFromAnn . getNot ( ) != null ) { resolvedSchema . schema . setNot ( schemaFromAnn . getNot ( ) ) ; resolvedSchema . schema . setType ( null ) ; } } parameter . setSchema ( resolvedSchema . schema ) ; } resolvedSchema . referencedSchemas . forEach ( ( key , schema ) -> components . addSchema ( key , schema ) ) ; for ( Annotation annotation : annotations ) { if ( annotation instanceof org . eclipse . microprofile . openapi . annotations . parameters . Parameter ) { org . eclipse . microprofile . openapi . annotations . parameters . Parameter p = ( org . eclipse . microprofile . openapi . annotations . parameters . Parameter ) annotation ; if ( p . hidden ( ) ) { return null ; } if ( StringUtils . isNotBlank ( p . ref ( ) ) ) { parameter . setRef ( p . ref ( ) ) ; } if ( StringUtils . isNotBlank ( p . description ( ) ) ) { parameter . setDescription ( p . description ( ) ) ; } if ( StringUtils . isNotBlank ( p . name ( ) ) ) { parameter . setName ( p . name ( ) ) ; } if ( StringUtils . isNotBlank ( p . in ( ) . toString ( ) ) ) { ( ( ParameterImpl ) parameter ) . setIn ( Parameter . In . valueOf ( p . in ( ) . toString ( ) . toUpperCase ( ) ) ) ; } 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 HashMap < > ( ) ; for ( ExampleObject exampleObject : p . examples ( ) ) { AnnotationsUtils . getExample ( exampleObject ) . ifPresent ( example -> exampleMap . put ( AnnotationsUtils . getNameOfReferenceableItem ( exampleObject ) , example ) ) ; } if ( exampleMap . size ( ) > 0 ) { parameter . setExamples ( exampleMap ) ; } Optional < Content > content = AnnotationsUtils . getContent ( p . content ( ) , classTypes , methodTypes , parameter . getSchema ( ) ) ; 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 SchemaImpl ( ) . type ( SchemaType . ARRAY ) ) ; } if ( parameter . getSchema ( ) . getType ( ) == SchemaType . ARRAY ) { Integer min = ( Integer ) annotation . annotationType ( ) . getMethod ( "min" ) . invoke ( annotation ) ; if ( min != null ) { parameter . getSchema ( ) . setMinItems ( min ) ; } Integer max = ( Integer ) annotation . annotationType ( ) . getMethod ( "max" ) . invoke ( annotation ) ; if ( max != null ) { parameter . getSchema ( ) . setMaxItems ( max ) ; } } } catch ( Exception e ) { } } } final String defaultValue = helper . getDefaultValue ( ) ; Schema paramSchema = parameter . getSchema ( ) ; if ( paramSchema == null ) { if ( parameter . getContent ( ) != null && parameter . getContent ( ) . values ( ) . size ( ) > 0 ) { paramSchema = parameter . getContent ( ) . values ( ) . iterator ( ) . next ( ) . getSchema ( ) ; } } if ( paramSchema != null ) { if ( paramSchema . getType ( ) == SchemaType . ARRAY ) { if ( defaultValue != null ) { paramSchema . getItems ( ) . setDefaultValue ( defaultValue ) ; } } else { if ( defaultValue != null ) { paramSchema . setDefaultValue ( defaultValue ) ; } } } return parameter ; }
static Logger LOGGER = LoggerFactory.getLogger(ParameterProcessor.class);