001// Copyright 2021 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007//     http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014package org.apache.tapestry5.services.rest;
015
016import java.lang.reflect.Parameter;
017
018import org.apache.tapestry5.ioc.annotations.UsesOrderedConfiguration;
019import org.apache.tapestry5.json.JSONObject;
020
021import java.lang.reflect.Method;
022
023/**
024 * Interface that describes the type of a REST endpoint parameter, return type or request body.
025 * It should add a <code>schema</code> (in most cases) or <code>content</code> property to the 
026 * provided {@linkplain JSONObject} if the given type is supported. This can be be also
027 * used to customize specific parameters or return type or request body of specific paths.
028 * As a service, this is a chain of instances of itself. All instances will be called.
029 */
030@UsesOrderedConfiguration(OpenApiTypeDescriber.class)
031public interface OpenApiTypeDescriber 
032{
033
034    /**
035     * Describes a REST event handler method parameter.
036     * @param description {@link JSONObject} containing the description of an event handler parameter.
037     * @param parameter the event handler method parameter.
038     */
039    void describe(final JSONObject description, Parameter parameter);
040    
041    /**
042     * Describes a REST event handler method return type.
043     * @param description {@link JSONObject} containing the description of a path response.
044     * @param method the event handler method itself.
045     */
046    void describeReturnType(final JSONObject description, Method method);
047
048    /**
049     * Describes the schema of a mapped entity class
050     * @param entity an entity class.
051     * @param schemas {@link JSONObject} where the entity description should be added.
052     * @see MappedEntityManager
053     */
054    void describeSchema(Class<?> entity, JSONObject schemas);
055
056}