-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#1175): OpenAPI connector enhancements for simulator random messa…
…ge generation
- Loading branch information
Thorsten Schlathoelter
committed
Jun 11, 2024
1 parent
40e7de2
commit 1b1adfe
Showing
23 changed files
with
1,600 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.citrusframework.openapi; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.citrusframework.repository.BaseRepository; | ||
import org.citrusframework.spi.Resource; | ||
|
||
/** | ||
* OpenApi repository holding a set of OpenApi json schema resources known in the test scope. | ||
* @since 4.4.0 | ||
*/ | ||
public class OpenApiRepository extends BaseRepository { | ||
|
||
private static final String DEFAULT_NAME = "openApiSchemaRepository"; | ||
|
||
/** List of schema resources */ | ||
private final List<OpenApiSpecification> openApiSpecifications = new ArrayList<>(); | ||
|
||
|
||
/** An optional context path, used for each api, without taking into account any {@link OpenApiSpecification} specific context path. */ | ||
private String rootContextPath; | ||
|
||
public OpenApiRepository() { | ||
super(DEFAULT_NAME); | ||
} | ||
|
||
public String getRootContextPath() { | ||
return rootContextPath; | ||
} | ||
|
||
public void setRootContextPath(String rootContextPath) { | ||
this.rootContextPath = rootContextPath; | ||
} | ||
|
||
@Override | ||
public void addRepository(Resource openApiResource) { | ||
|
||
OpenApiSpecification openApiSpecification = OpenApiSpecification.from(openApiResource); | ||
openApiSpecification.setRootContextPath(rootContextPath); | ||
|
||
this.openApiSpecifications.add(openApiSpecification); | ||
|
||
OpenApiSpecificationProcessor.lookup().values().forEach(processor -> processor.process(openApiSpecification)); | ||
} | ||
|
||
public List<OpenApiSpecification> getOpenApiSpecifications() { | ||
return openApiSpecifications; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...trus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecificationProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.citrusframework.openapi; | ||
|
||
import java.util.Map; | ||
import org.citrusframework.spi.ResourcePathTypeResolver; | ||
import org.citrusframework.spi.TypeResolver; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Interface for processing OpenAPI specifications. | ||
* <p> | ||
* 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. | ||
* </p> | ||
*/ | ||
public interface OpenApiSpecificationProcessor { | ||
|
||
/** Logger */ | ||
Logger logger = LoggerFactory.getLogger(OpenApiSpecificationProcessor.class); | ||
|
||
/** Message validator resource lookup path */ | ||
String RESOURCE_PATH = "META-INF/citrus/openapi/processor"; | ||
|
||
/** Type resolver to find custom message validators on classpath via resource path lookup */ | ||
TypeResolver TYPE_RESOLVER = new ResourcePathTypeResolver(RESOURCE_PATH); | ||
|
||
void process(OpenApiSpecification openApiSpecification); | ||
|
||
/** | ||
* Resolves all available validators from resource path lookup. Scans classpath for validator meta information | ||
* and instantiates those validators. | ||
*/ | ||
static Map<String, OpenApiSpecificationProcessor> lookup() { | ||
Map<String, OpenApiSpecificationProcessor> validators = TYPE_RESOLVER.resolveAll("", TypeResolver.DEFAULT_TYPE_PROPERTY, "name"); | ||
|
||
if (logger.isDebugEnabled()) { | ||
validators.forEach((k, v) -> logger.debug(String.format("Found openapi specification processor '%s' as %s", k, v.getClass()))); | ||
} | ||
|
||
return validators; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.