Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#285): support OpenAPI 3.0 from HttpOperationScenario #286

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<maven.nexus-staging.plugin.version>1.6.13</maven.nexus-staging.plugin.version>

<lombok.version>1.18.30</lombok.version>
<citrus.version>4.2.1</citrus.version>
<citrus.version>4.3.0-SNAPSHOT</citrus.version>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, this will not build. but I think it's dependent on citrusframework/citrus#1177, right?


<spring-boot.version>3.3.0</spring-boot.version>
<spring.version>6.3.0</spring.version>
Expand Down
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 @@ -102,6 +108,13 @@ public class SimulatorConfigurationProperties implements EnvironmentAware, Initi
*/
private String outboundJsonDictionary = "outbound-json-dictionary.properties";

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 @@ -114,4 +127,13 @@ public void setEnvironment(Environment environment) {
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;
}
}
Loading
Loading