Skip to content

Commit

Permalink
feat(citrusframework#285): support OpenAPI 3.0 from HttpOperationScen…
Browse files Browse the repository at this point in the history
…ario
  • Loading branch information
Thorsten Schlathoelter committed Nov 6, 2024
1 parent 3062970 commit 057e551
Show file tree
Hide file tree
Showing 19 changed files with 1,075 additions and 652 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"swagger": "3.0.3",
"swagger": "2.0",
"info": {
"description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",
"version": "1.0.0",
Expand Down Expand Up @@ -1032,4 +1032,4 @@
"description": "Find out more about Swagger",
"url": "http://swagger.io"
}
}
}
4 changes: 4 additions & 0 deletions simulator-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
<groupId>org.citrusframework</groupId>
<artifactId>citrus-http</artifactId>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-openapi</artifactId>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-ws</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.citrusframework.simulator.config;

/**
* Enumeration representing the modes for generating scenario IDs in an OpenAPI context.
* This enumeration defines two modes:
* <ul>
* <li>{@link #OPERATION_ID}: Uses the operation ID defined in the OpenAPI specification.</li>
* <li>{@link #FULL_PATH}: Uses the full path of the API endpoint.</li>
* </ul>
* The choice of mode affects how scenario IDs are generated, with important implications:
* <ul>
* <li><b>OPERATION_ID:</b> This mode relies on the {@code operationId} field in the OpenAPI specification, which
* provides a unique identifier for each operation. However, the {@code operationId} is not mandatory in the OpenAPI
* specification. If an {@code operationId} is not specified, this mode cannot be used effectively.</li>
* <li><b>FULL_PATH:</b> This mode constructs scenario IDs based on the entire URL path of the API endpoint, including
* path parameters. This is particularly useful when simulating multiple versions of the same API, as it allows for
* differentiation based on the endpoint path. This mode ensures unique scenario IDs even when {@code operationId}
* is not available or when versioning of APIs needs to be distinguished.</li>
* </ul>
* </p>
*/
public enum OpenApiScenarioIdGenerationMode {
FULL_PATH,
OPERATION_ID
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@

package org.citrusframework.simulator.config;

import jakarta.annotation.Nonnull;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;

Expand All @@ -33,7 +37,7 @@
@Setter
@ToString
@ConfigurationProperties(prefix = "citrus.simulator")
public class SimulatorConfigurationProperties implements EnvironmentAware, InitializingBean {
public class SimulatorConfigurationProperties implements ApplicationContextAware, EnvironmentAware, InitializingBean {

private static final Logger logger = LoggerFactory.getLogger(SimulatorConfigurationProperties.class);

Expand All @@ -46,6 +50,8 @@ public class SimulatorConfigurationProperties implements EnvironmentAware, Initi
private static final String SIMULATOR_OUTBOUND_JSON_DICTIONARY_PROPERTY = "citrus.simulator.outbound.json.dictionary.location";
private static final String SIMULATOR_OUTBOUND_JSON_DICTIONARY_ENV = "CITRUS_SIMULATOR_OUTBOUND_JSON_DICTIONARY_LOCATION";

private static ApplicationContext applicationContext;

/**
* Global option to enable/disable simulator support, default is true.
*/
Expand Down Expand Up @@ -104,6 +110,15 @@ public class SimulatorConfigurationProperties implements EnvironmentAware, Initi

private SimulationResults simulationResults = new SimulationResults();

public static ApplicationContext getApplicationContext() {
if (applicationContext == null) {
throw new IllegalStateException("Application context has not been initialized. This bean needs to be instantiated by Spring in order to function properly!");
}
return applicationContext;
}



@Override
public void setEnvironment(Environment environment) {
inboundXmlDictionary = environment.getProperty(SIMULATOR_INBOUND_XML_DICTIONARY_PROPERTY, environment.getProperty(SIMULATOR_INBOUND_XML_DICTIONARY_ENV, inboundXmlDictionary));
Expand All @@ -117,6 +132,15 @@ public void afterPropertiesSet() {
logger.info("Using the simulator configuration: {}", this);
}

@Override
public void setApplicationContext(@Nonnull ApplicationContext context) throws BeansException {
initStaticApplicationContext(context);
}

private static void initStaticApplicationContext(ApplicationContext context) {
applicationContext = context;
}

@Getter
@Setter
@ToString
Expand All @@ -127,4 +151,5 @@ public static class SimulationResults {
*/
private boolean resetEnabled = true;
}

}
Loading

0 comments on commit 057e551

Please sign in to comment.