+ * The class maintains a set of aliases derived from the OpenAPI document's information. These + * aliases typically include the title of the API and its version, providing easy reference and + * identification. For example, if the OpenAPI document's title is "Sample API" and its version is + * "1.0", the aliases set will include "Sample API" and "Sample API/1.0". + *
+ * Users are responsible for ensuring that the sources provided to this class have unique aliases,
+ * or at least use the correct alias. If the same API is registered with different versions, all
+ * versions will likely share the same title alias but can be distinguished by the version alias
+ * (e.g., "Sample API/1.0" and "Sample API/2.0"). This distinction is crucial to avoid conflicts and
+ * ensure the correct identification and reference of each OpenAPI specification. Also note, that
+ * aliases may be added manually or programmatically by
+ * {@link OpenApiSpecification#addAlias(String)}.
*/
public class OpenApiSpecification {
- /** URL to load the OpenAPI specification */
+ private static final Logger logger = LoggerFactory.getLogger(OpenApiSpecification.class);
+
+ private static final String HTTPS = "https";
+ private static final String HTTP = "http";
+
+ /**
+ * A unique identifier (UID) for this specification at runtime. The UID is generated based on
+ * the SHA of the OpenAPI document combined with the full context path to which the API is
+ * attached.
+ *
+ * @see OpenApiSpecification#determineUid for detailed information on how the UID is generated.
+ */
+ private String uid;
+
+ private final Set
+ * If set to {@code true}, the base path will be omitted from the final URL path construction.
+ * This allows for more flexible path handling where the base path is not required.
+ *
+ * This path is prepended to the base path specified in the OpenAPI configuration. If no root
+ * context path is specified, only the base path and additional segments are used when
+ * constructing the complete URL path.
+ *
+ * This path will be prepended to the base path when constructing the full URL path. After
+ * setting the root context path, the internal path lookups are re-initialized to reflect the
+ * updated configuration.
+ * Side Effect: Invokes {@link #initPathLookups()} to update internal path mappings
+ * based on the new root context path.
+ * The full path is constructed by concatenating the root context path, the base path (if
+ * applicable), and the path of the given {@code oasPathItem}. The resulting format is:
+ *
+ * The full base-path is constructed by concatenating the base path (if applicable), and the
+ * path of the given {@code oasPathItem}. The resulting format is:
+ *
+ * The full context path is constructed by appending the root context path to the base path
+ * specified in the OpenAPI document. If the base path should be neglected (as indicated by
+ * {@link #neglectBasePath}), only the root context path will be used.
+ * Side Effect: Invokes {@link #initPathLookups()} to update internal path mappings
+ * based on the new root context path.
+ * This interface is designed to be implemented by custom processors that handle OpenAPI specifications.
+ * Implementations of this interface are discovered by the standard citrus SPI mechanism.
+ */
+public interface OpenApiSpecificationProcessor {
+
+ /**
+ * Logger
+ */
+ Logger logger = LoggerFactory.getLogger(OpenApiSpecificationProcessor.class);
+
+ /**
+ * OpenAPI processors resource lookup path
+ */
+ String RESOURCE_PATH = "META-INF/citrus/openapi/processor";
+
+ /**
+ * Type resolver to find OpenAPI processors on classpath via resource path lookup
+ */
+ TypeResolver TYPE_RESOLVER = new ResourcePathTypeResolver(RESOURCE_PATH);
+
+ /**
+ * Resolves all available processors from resource path lookup. Scans classpath for processors meta information
+ * and instantiates those processors.
+ */
+ static Map
+ * /rootContextPath/basePath/pathItemPath
+ *
+ * If the base path is to be neglected, it is excluded from the final constructed path.
+ *
+ * @param oasPathItem the OpenAPI path item whose full path is to be constructed
+ * @return the full URL path, consisting of the root context path, base path, and the given path
+ * item
+ */
+ public String getFullPath(OasPathItem oasPathItem) {
+ return appendSegmentToUrlPath(rootContextPath,
+ getFullBasePath(oasPathItem));
}
- public void setValidateOptionalFields(boolean validateOptionalFields) {
- this.validateOptionalFields = validateOptionalFields;
+ /**
+ * Get the full base-path for the given {@link OasPathItem}.
+ *
+ * /basePath/pathItemPath
+ *
+ * If the base path is to be neglected, it is excluded from the final constructed path.
+ *
+ * @param oasPathItem the OpenAPI path item whose full base-path is to be constructed
+ * @return the full base URL path, consisting of the base path, and the given path item
+ */
+ public String getFullBasePath(OasPathItem oasPathItem) {
+ return appendSegmentToUrlPath(
+ getApplicableBasePath(), oasPathItem.getPath());
}
+
+
+ /**
+ * Constructs the full context path for the given {@link OasPathItem}.
+ *