diff --git a/bin/configs/java-camel-petstore-new.yaml b/bin/configs/java-camel-petstore-new.yaml new file mode 100644 index 000000000000..51f66553da7f --- /dev/null +++ b/bin/configs/java-camel-petstore-new.yaml @@ -0,0 +1,17 @@ +generatorName: java-camel +outputDir: samples/server/petstore/java-camel +inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/java-camel-server +additionalProperties: + oas3: "true" + hideGenerationTimestamp: true + camelRestBindingMode: "auto" + performBeanValidation: true + #dateLibrary: "java8-localdatetime" + camelDataformatProperties: "json.out.disableFeatures=WRITE_DATES_AS_TIMESTAMPS" + library: "spring-boot" + withXml: true + jackson: true + camelUseDefaulValidationtErrorProcessor: true + camelRestClientRequestValidation: true + camelSecurityDefinitions: true diff --git a/docs/generators.md b/docs/generators.md index 2d8876879115..acd34b9daaa4 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -97,6 +97,7 @@ The following generators are available: * [graphql-nodejs-express-server](generators/graphql-nodejs-express-server.md) * [haskell](generators/haskell.md) * [haskell-yesod (beta)](generators/haskell-yesod.md) +* [java-camel](generators/java-camel.md) * [java-inflector](generators/java-inflector.md) * [java-msf4j](generators/java-msf4j.md) * [java-pkmst](generators/java-pkmst.md) diff --git a/docs/generators/java-camel.md b/docs/generators/java-camel.md new file mode 100644 index 000000000000..0f2631991b6b --- /dev/null +++ b/docs/generators/java-camel.md @@ -0,0 +1,314 @@ +--- +title: Config Options for java-camel +sidebar_label: java-camel +--- + +These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details. + +| Option | Description | Values | Default | +| ------ | ----------- | ------ | ------- | +|additionalEnumTypeAnnotations|Additional annotations for enum type(class level annotations)| |null| +|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null| +|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false| +|apiFirst|Generate the API from the OAI spec at server compile time (API first approach)| |false| +|apiPackage|package for generated api classes| |org.openapitools.api| +|artifactDescription|artifact description in generated pom.xml| |OpenAPI Java| +|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |openapi-spring| +|artifactUrl|artifact URL in generated pom.xml| |https://github.com/openapitools/openapi-generator| +|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0| +|async|use async Callable controllers| |false| +|basePackage|base package (invokerPackage) for generated code| |org.openapitools| +|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false| +|booleanGetterPrefix|Set booleanGetterPrefix| |get| +|camelDataformatProperties|list of dataformat properties separated by comma (propertyName1=propertyValue2,...| || +|camelRestBindingMode|binding mode to be used by the REST consumer| |auto| +|camelRestClientRequestValidation|enable validation of the client request to check whether the Content-Type and Accept headers from the client is supported by the Rest-DSL configuration| |false| +|camelRestComponent|name of the Camel component to use as the REST consumer| |servlet| +|camelSecurityDefinitions|generate camel security definitions| |true| +|camelUseDefaulValidationtErrorProcessor|generate default validation error processor| |true| +|camelValidationErrorProcessor|validation error processor bean name| |validationErrorProcessor| +|configPackage|configuration package for generated code| |org.openapitools.configuration| +|dateLibrary|Option. Date library to use|
**joda**
Joda (for legacy app only)
**legacy**
Legacy java.util.Date (if you really have a good reason not to use threetenbp
**java8-localdatetime**
Java 8 using LocalDateTime (for legacy app only)
**java8**
Java 8 native JSR310 (preferred for jdk 1.8+) - note: this also sets "java8" to true
**threetenbp**
Backport of JSR310 (preferred for jdk < 1.8)
|threetenbp| +|delegatePattern|Whether to generate the server files using the delegate pattern| |false| +|developerEmail|developer email in generated pom.xml| |team@openapitools.org| +|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors| +|developerOrganization|developer organization in generated pom.xml| |OpenAPITools.org| +|developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| +|disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| +|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| +|discriminatorCaseSensitive|Whether the discriminator value lookup should be case-sensitive or not. This option only works for Java API client| |true| +|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| +|fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| +|groupId|groupId in generated pom.xml| |org.openapitools| +|hateoas|Use Spring HATEOAS library to allow adding HATEOAS links| |false| +|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |false| +|ignoreAnyOfInEnum|Ignore anyOf keyword in enum| |false| +|implicitHeaders|Skip header parameters in the generated API methods using @ApiImplicitParams annotation.| |false| +|interfaceOnly|Whether to generate only API interface stubs without the server files.| |false| +|invokerPackage|root package for generated code| |org.openapitools.api| +|java8|Use Java8 classes instead of third party equivalents. Starting in 5.x, JDK8 is the default and the support for JDK7, JDK6 has been dropped|
**true**
Use Java 8 classes such as Base64. Use java8 default interface when a responseWrapper is used. IMPORTANT: This option has been deprecated as Java 8 is the default.
**false**
Various third party libraries as needed
|true| +|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|
**true**
The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.
**false**
The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.
|true| +|library|library template (sub-template)|
**spring-boot**
Spring-boot Server application using the SpringFox integration.
**spring-mvc**
Spring-MVC Server application using the SpringFox integration.
**spring-cloud**
Spring-Cloud-Feign client with Spring-Boot auto-configured settings.
|spring-boot| +|licenseName|The name of the license| |Unlicense| +|licenseUrl|The URL of the license| |http://unlicense.org| +|modelPackage|package for generated models| |org.openapitools.model| +|oas3|Use OAS 3 Swagger annotations instead of OAS 2 annotations| |false| +|openApiNullable|Enable OpenAPI Jackson Nullable library| |true| +|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|parentVersion|parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| +|performBeanValidation|Use Bean Validation Impl. to perform BeanValidation| |false| +|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| +|reactive|wrap responses in Mono/Flux Reactor types (spring-boot only)| |false| +|responseWrapper|wrap the responses in given type (Future, Callable, CompletableFuture,ListenableFuture, DeferredResult, RxObservable, RxSingle or fully qualified type)| |null| +|returnSuccessCode|Generated server returns 2xx code| |false| +|scmConnection|SCM connection in generated pom.xml| |scm:git:git@github.com:openapitools/openapi-generator.git| +|scmDeveloperConnection|SCM developer connection in generated pom.xml| |scm:git:git@github.com:openapitools/openapi-generator.git| +|scmUrl|SCM URL in generated pom.xml| |https://github.com/openapitools/openapi-generator| +|serializableModel|boolean - toggle "implements Serializable" for generated models| |false| +|singleContentTypes|Whether to select only one produces/consumes content-type by operation.| |false| +|skipDefaultInterface|Whether to generate default implementations for java8 interfaces| |false| +|snapshotVersion|Uses a SNAPSHOT version.|
**true**
Use a SnapShot Version
**false**
Use a Release Version
|null| +|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| +|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| +|sourceFolder|source folder for generated code| |src/main/java| +|swaggerDocketConfig|Generate Spring OpenAPI Docket configuration class.| |false| +|title|server title name or client service name| |OpenAPI Spring| +|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false| +|useBeanValidation|Use BeanValidation API annotations| |true| +|useOptional|Use Optional container for optional parameters| |false| +|useSpringController|Annotate the generated API as a Spring Controller| |false| +|useTags|use tags for creating interface and controller classnames| |false| +|virtualService|Generates the virtual service. For more details refer - https://github.com/virtualansoftware/virtualan/wiki| |false| +|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false| + +## IMPORT MAPPING + +| Type/Alias | Imports | +| ---------- | ------- | +|Array|java.util.List| +|ArrayList|java.util.ArrayList| +|BigDecimal|java.math.BigDecimal| +|Date|java.util.Date| +|DateTime|org.joda.time.*| +|File|java.io.File| +|HashMap|java.util.HashMap| +|LinkedHashSet|java.util.LinkedHashSet| +|List|java.util.*| +|LocalDate|org.joda.time.*| +|LocalDateTime|org.joda.time.*| +|LocalTime|org.joda.time.*| +|Map|java.util.Map| +|Set|java.util.*| +|Timestamp|java.sql.Timestamp| +|URI|java.net.URI| +|UUID|java.util.UUID| + + +## INSTANTIATION TYPES + +| Type/Alias | Instantiated By | +| ---------- | --------------- | +|array|ArrayList| +|map|HashMap| +|set|LinkedHashSet| + + +## LANGUAGE PRIMITIVES + + + +## RESERVED WORDS + + + +## FEATURE SET + + +### Client Modification Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|BasePath|✓|ToolingExtension +|Authorizations|✗|ToolingExtension +|UserAgent|✗|ToolingExtension +|MockServer|✗|ToolingExtension + +### Data Type Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|Custom|✗|OAS2,OAS3 +|Int32|✓|OAS2,OAS3 +|Int64|✓|OAS2,OAS3 +|Float|✓|OAS2,OAS3 +|Double|✓|OAS2,OAS3 +|Decimal|✓|ToolingExtension +|String|✓|OAS2,OAS3 +|Byte|✓|OAS2,OAS3 +|Binary|✓|OAS2,OAS3 +|Boolean|✓|OAS2,OAS3 +|Date|✓|OAS2,OAS3 +|DateTime|✓|OAS2,OAS3 +|Password|✓|OAS2,OAS3 +|File|✓|OAS2 +|Array|✓|OAS2,OAS3 +|Maps|✓|ToolingExtension +|CollectionFormat|✓|OAS2 +|CollectionFormatMulti|✓|OAS2 +|Enum|✓|OAS2,OAS3 +|ArrayOfEnum|✓|ToolingExtension +|ArrayOfModel|✓|ToolingExtension +|ArrayOfCollectionOfPrimitives|✓|ToolingExtension +|ArrayOfCollectionOfModel|✓|ToolingExtension +|ArrayOfCollectionOfEnum|✓|ToolingExtension +|MapOfEnum|✓|ToolingExtension +|MapOfModel|✓|ToolingExtension +|MapOfCollectionOfPrimitives|✓|ToolingExtension +|MapOfCollectionOfModel|✓|ToolingExtension +|MapOfCollectionOfEnum|✓|ToolingExtension + +### Documentation Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|Readme|✓|ToolingExtension +|Model|✓|ToolingExtension +|Api|✓|ToolingExtension + +### Global Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|Host|✓|OAS2,OAS3 +|BasePath|✓|OAS2,OAS3 +|Info|✓|OAS2,OAS3 +|Schemes|✗|OAS2,OAS3 +|PartialSchemes|✓|OAS2,OAS3 +|Consumes|✓|OAS2 +|Produces|✓|OAS2 +|ExternalDocumentation|✓|OAS2,OAS3 +|Examples|✓|OAS2,OAS3 +|XMLStructureDefinitions|✓|OAS2,OAS3 +|MultiServer|✗|OAS3 +|ParameterizedServer|✗|OAS3 +|ParameterStyling|✗|OAS3 +|Callbacks|✗|OAS3 +|LinkObjects|✗|OAS3 + +### Parameter Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|Path|✓|OAS2,OAS3 +|Query|✓|OAS2,OAS3 +|Header|✓|OAS2,OAS3 +|Body|✓|OAS2 +|FormUnencoded|✓|OAS2 +|FormMultipart|✓|OAS2 +|Cookie|✗|OAS3 + +### Schema Support Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|Simple|✓|OAS2,OAS3 +|Composite|✓|OAS2,OAS3 +|Polymorphism|✓|OAS2,OAS3 +|Union|✗|OAS3 + +### Security Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|BasicAuth|✓|OAS2,OAS3 +|ApiKey|✓|OAS2,OAS3 +|OpenIDConnect|✗|OAS3 +|BearerToken|✗|OAS3 +|OAuth2_Implicit|✓|OAS2,OAS3 +|OAuth2_Password|✓|OAS2,OAS3 +|OAuth2_ClientCredentials|✓|OAS2,OAS3 +|OAuth2_AuthorizationCode|✓|OAS2,OAS3 + +### Wire Format Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|JSON|✓|OAS2,OAS3 +|XML|✓|OAS2,OAS3 +|PROTOBUF|✗|ToolingExtension +|Custom|✓|OAS2,OAS3 diff --git a/modules/openapi-generator-maven-plugin/examples/camel.xml b/modules/openapi-generator-maven-plugin/examples/camel.xml new file mode 100644 index 000000000000..afcc2632bc39 --- /dev/null +++ b/modules/openapi-generator-maven-plugin/examples/camel.xml @@ -0,0 +1,198 @@ + + 4.0.0 + org.openapitools + sample-project + jar + 1.0-SNAPSHOT + sample-project + https://maven.apache.org + + + + + + + org.openapitools + openapi-generator-maven-plugin + + 5.3.1-SNAPSHOT + + + + camel-server + + generate + + + + ${project.basedir}/swagger.yaml + + + camel + + + + + + auto + true + true + json.out.disableFeatures=WRITE_DATES_AS_TIMESTAMPS + true + true + true + + true + true + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + none + + + + + + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + + + + + org.apache.camel + camel-bom + 3.13.0 + pom + import + + + org.apache.camel.springboot + camel-spring-boot-bom + 3.13.0 + pom + import + + + org.springframework.boot + spring-boot-dependencies + 2.6.1 + pom + import + + + + + + + org.apache.camel.springboot + camel-spring-boot-starter + + + + org.apache.camel.springboot + camel-servlet-starter + + + + org.springframework.boot + spring-boot-starter-web + + + + org.openapitools + jackson-databind-nullable + 0.2.1 + + + io.swagger + swagger-annotations + 1.6.3 + + + io.swagger.core.v3 + swagger-annotations + 2.1.11 + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.13.0 + + + com.fasterxml.jackson.datatype + jackson-datatype-jdk8 + 2.13.0 + + + org.apache.camel + camel-jackson + + + org.apache.camel + camel-jacksonxml + + + + org.apache.camel + camel-jaxb + + + org.apache.camel + camel-direct + + + + org.apache.camel + camel-bean-validator + + + + + com.mashape.unirest + unirest-java + 1.4.9 + test + + + + org.apache.camel + camel-test-spring-junit5 + test + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + 1.5.8 + + 2.2.1.RELEASE + 2.8.0 + + diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaCamelServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaCamelServerCodegen.java new file mode 100644 index 000000000000..39240ff329e6 --- /dev/null +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaCamelServerCodegen.java @@ -0,0 +1,186 @@ +package org.openapitools.codegen.languages; + +import io.swagger.v3.oas.models.Operation; +import org.openapitools.codegen.CliOption; +import org.openapitools.codegen.CodegenOperation; +import org.openapitools.codegen.CodegenType; +import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.languages.features.BeanValidationFeatures; +import org.openapitools.codegen.languages.features.OptionalFeatures; +import org.openapitools.codegen.languages.features.PerformBeanValidationFeatures; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class JavaCamelServerCodegen extends SpringCodegen implements BeanValidationFeatures, PerformBeanValidationFeatures, OptionalFeatures { + private static final String APPLICATION_JSON = "application/json"; + private static final String APPLICATION_XML = "application/xml"; + + public static final String PROJECT_NAME = "projectName"; + public static final String CAMEL_REST_COMPONENT = "camelRestComponent"; + public static final String CAMEL_REST_BINDING_MODE = "camelRestBindingMode"; + public static final String CAMEL_REST_CLIENT_REQUEST_VALIDATION = "camelRestClientRequestValidation"; + public static final String CAMEL_USE_DEFAULT_VALIDATION_ERROR_PROCESSOR = "camelUseDefaulValidationtErrorProcessor"; + public static final String CAMEL_VALIDATION_ERROR_PROCESSOR = "camelValidationErrorProcessor"; + public static final String CAMEL_SECURITY_DEFINITIONS = "camelSecurityDefinitions"; + public static final String CAMEL_DATAFORMAT_PROPERTIES = "camelDataformatProperties"; + + private String camelRestComponent = "servlet"; + private String camelRestBindingMode = "auto"; + private boolean camelRestClientRequestValidation = false; + private boolean camelUseDefaulValidationtErrorProcessor = true; + private String camelValidationErrorProcessor = "validationErrorProcessor"; + private boolean camelSecurityDefinitions = true; + private String camelDataformatProperties = ""; + + private final Logger LOGGER = LoggerFactory.getLogger(JavaCamelServerCodegen.class); + + public CodegenType getTag() { + return CodegenType.SERVER; + } + + public String getName() { + return "java-camel"; + } + + public String getHelp() { + return "Generates a camel server."; + } + + public JavaCamelServerCodegen() { + super(); + templateDir = "java-camel-server"; + addCliOptions(); + artifactId = "openapi-camel"; + super.library = ""; + } + + @Override + public void processOpts() { + if (!additionalProperties.containsKey(DATE_LIBRARY)) { + additionalProperties.put(DATE_LIBRARY, "legacy"); + } + super.processOpts(); + super.apiTemplateFiles.remove("apiController.mustache"); + LOGGER.info("***** Java Apache Camel Server Generator *****"); + supportingFiles.clear(); + manageAdditionalProperties(); + + Map dataFormatProperties = new HashMap<>(); + if (!"off".equals(camelRestBindingMode)) { + Arrays.stream(camelDataformatProperties.split(",")).forEach(property -> { + String[] dataFormatProperty = property.split("="); + if (dataFormatProperty.length == 2) { + dataFormatProperties.put(dataFormatProperty[0].trim(), dataFormatProperty[1].trim()); + } + }); + } + additionalProperties.put(CAMEL_DATAFORMAT_PROPERTIES, dataFormatProperties.entrySet()); + + supportingFiles.add(new SupportingFile("restConfiguration.mustache", + (sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), + "RestConfiguration.java")); + if (performBeanValidation) { + apiTemplateFiles.put("validation.mustache", "Validator.java"); + if (camelUseDefaulValidationtErrorProcessor) { + supportingFiles.add(new SupportingFile("errorProcessor.mustache", + (sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), + "ValidationErrorProcessor.java")); + } + } + if (SPRING_BOOT.equals(library)) { + supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); + supportingFiles.add(new SupportingFile("openapi2SpringBoot.mustache", + (sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), + "OpenAPI2SpringBoot.java")); + + if (!interfaceOnly) { + apiTemplateFiles.put("routesImpl.mustache", "RoutesImpl.java"); + } + + supportingFiles.add(new SupportingFile("application.mustache", + ("src.main.resources").replace(".", java.io.File.separator), "application.properties")); + supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); + supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache", + (sourceFolder + File.separator + basePackage).replace(".", java.io.File.separator), + "RFC3339DateFormat.java")); + apiTestTemplateFiles.put("test.mustache", ".java"); + } + } + + @Override + public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations) { + boolean bindingModeOff = false; + if (co.hasProduces) { + for (Map produces : co.produces) { + String mediaType = produces.get("mediaType"); + if (!APPLICATION_JSON.equals(mediaType) && !APPLICATION_XML.equals(mediaType)) { + bindingModeOff = true; + } + if (APPLICATION_JSON.equals(mediaType)) { + produces.put("isJson", "true"); + } + if (APPLICATION_XML.equals(mediaType)) { + produces.put("isXml", "true"); + } + } + } + if (co.hasConsumes) { + for (Map consumes : co.consumes) { + String mediaType = consumes.get("mediaType"); + if (!APPLICATION_JSON.equals(mediaType) && !APPLICATION_XML.equals(mediaType)) { + bindingModeOff = true; + } + if (APPLICATION_JSON.equals(mediaType)) { + consumes.put("isJson", "true"); + } + if (APPLICATION_XML.equals(mediaType)) { + consumes.put("isXml", "true"); + } + } + } + co.vendorExtensions.put(CAMEL_REST_BINDING_MODE, bindingModeOff); + super.addOperationToGroup(tag, resourcePath, operation, co, operations); + } + + private void addCliOptions() { + cliOptions.add(new CliOption(CAMEL_REST_COMPONENT, "name of the Camel component to use as the REST consumer").defaultValue(camelRestComponent)); + cliOptions.add(new CliOption(CAMEL_REST_BINDING_MODE, "binding mode to be used by the REST consumer").defaultValue(camelRestBindingMode)); + cliOptions.add(CliOption.newBoolean(CAMEL_REST_CLIENT_REQUEST_VALIDATION, "enable validation of the client request to check whether the Content-Type and Accept headers from the client is supported by the Rest-DSL configuration", camelRestClientRequestValidation)); + cliOptions.add(CliOption.newBoolean(CAMEL_USE_DEFAULT_VALIDATION_ERROR_PROCESSOR, "generate default validation error processor", camelUseDefaulValidationtErrorProcessor)); + cliOptions.add(new CliOption(CAMEL_VALIDATION_ERROR_PROCESSOR, "validation error processor bean name").defaultValue(camelValidationErrorProcessor)); + cliOptions.add(CliOption.newBoolean(CAMEL_SECURITY_DEFINITIONS, "generate camel security definitions", camelSecurityDefinitions)); + cliOptions.add(new CliOption(CAMEL_DATAFORMAT_PROPERTIES, "list of dataformat properties separated by comma (propertyName1=propertyValue2,...").defaultValue(camelDataformatProperties)); + } + + private void manageAdditionalProperties() { + camelRestComponent = manageAdditionalProperty(CAMEL_REST_COMPONENT, camelRestComponent); + camelRestBindingMode = manageAdditionalProperty(CAMEL_REST_BINDING_MODE, camelRestBindingMode); + camelRestClientRequestValidation = manageAdditionalProperty(CAMEL_REST_CLIENT_REQUEST_VALIDATION, camelRestClientRequestValidation); + camelUseDefaulValidationtErrorProcessor = manageAdditionalProperty(CAMEL_USE_DEFAULT_VALIDATION_ERROR_PROCESSOR, camelUseDefaulValidationtErrorProcessor); + camelValidationErrorProcessor = manageAdditionalProperty(CAMEL_VALIDATION_ERROR_PROCESSOR, camelValidationErrorProcessor); + camelSecurityDefinitions = manageAdditionalProperty(CAMEL_SECURITY_DEFINITIONS, camelSecurityDefinitions); + camelDataformatProperties = manageAdditionalProperty(CAMEL_DATAFORMAT_PROPERTIES, camelDataformatProperties); + } + + private T manageAdditionalProperty(String propertyName, T defaultValue) { + if (additionalProperties.containsKey(propertyName)) { + Object propertyValue = additionalProperties.get(propertyName); + if (defaultValue instanceof Boolean && !(propertyValue instanceof Boolean)) { + return (T) manageBooleanAdditionalProperty((String) propertyValue); + } + return (T) additionalProperties.get(propertyName); + } + additionalProperties.put(propertyName, defaultValue); + return defaultValue; + } + + private Boolean manageBooleanAdditionalProperty(String propertyValue) { + return Boolean.parseBoolean(propertyValue); + } +} diff --git a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig index c353b2a28464..d5911a2139bd 100644 --- a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig +++ b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig @@ -141,3 +141,5 @@ org.openapitools.codegen.languages.TypeScriptNodeClientCodegen org.openapitools.codegen.languages.TypeScriptReduxQueryClientCodegen org.openapitools.codegen.languages.TypeScriptRxjsClientCodegen org.openapitools.codegen.languages.WsdlSchemaCodegen + +org.openapitools.codegen.languages.JavaCamelServerCodegen diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/README.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/README.mustache new file mode 100644 index 000000000000..e20452e84920 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-camel-server/README.mustache @@ -0,0 +1,7 @@ +# OpenAPI generated server + +Apache Camel Server + +```bash +mvn clean test +``` \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/api.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/api.mustache new file mode 100644 index 000000000000..6e6e769904fb --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-camel-server/api.mustache @@ -0,0 +1,95 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package {{apiPackage}}; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.rest.RestParamType; +import org.springframework.stereotype.Component; +import {{modelPackage}}.*; +import org.apache.camel.model.rest.RestBindingMode; +import org.apache.camel.LoggingLevel; + +@Component +public class {{classname}} extends RouteBuilder { + + @Override + public void configure() throws Exception { + {{#performBeanValidation}} + onException(Exception.class) + .log(LoggingLevel.ERROR, "${exception.message}: ${exception.stacktrace}") + .handled(true) + .process("{{camelValidationErrorProcessor}}"); + {{/performBeanValidation}} + {{#operations}}{{#operation}} + + /** + {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}} + **/ + rest(){{#camelSecurityDefinitions}}{{#hasAuthMethods}} + .securityDefinitions(){{#authMethods}}{{#isOAuth}} + .oauth2("{{name}}"){{#flow}} + .flow("{{flow}}"){{/flow}}{{#tokenUrl}} + .tokenUrl("{{tokenUrl}}"){{/tokenUrl}}{{#authorizationUrl}} + .authorizationUrl("{{authorizationUrl}}"){{/authorizationUrl}}{{#refreshUrl}} + .refreshUrl("{{refreshUrl}}"){{/refreshUrl}}{{#scopes}} + .withScope("{{scope}}"{{#description}},"{{{.}}}"{{/description}}){{/scopes}} + {{^-last}}.end(){{/-last}}{{#-last}} + .endSecurityDefinition(){{/-last}}{{/isOAuth}}{{#isApiKey}} + .apiKey("{{name}}"){{#isKeyInHeader}} + .withHeader("{{name}}"){{/isKeyInHeader}}{{#isKeyInQuery}} + .withQuery("{{name}}").{{/isKeyInQuery}}{{#isKeyInCookie}} + .withCookie("{{name}}").{{/isKeyInCookie}} + {{^-last}}.end(){{/-last}}{{#-last}} + .endSecurityDefinition(){{/-last}}{{/isApiKey}}{{#isBasic}}{{#isBasicBasic}} + .basicAuth("{{name}}"){{#-last}}.end(){{/-last}}{{/isBasicBasic}}{{#isBasicBearer}} + .bearerToken("{{name}}"{{#bearerFormat}}, "{{bearerFormat}}"{{/bearerFormat}}){{#-last}}.end(){{/-last}}{{/isBasicBearer}}{{/isBasic}}{{/authMethods}}{{/hasAuthMethods}}{{/camelSecurityDefinitions}} + .{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}("{{path}}") + .description("{{#summary}}{{{.}}}{{/summary}}") + .id("{{operationId}}Api"){{#vendorExtensions}}{{#camelRestBindingMode}} + .clientRequestValidation(false) + .bindingMode(RestBindingMode.off){{/camelRestBindingMode}}{{/vendorExtensions}}{{#hasProduces}} + .produces("{{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}"){{^isArray}}{{^isMap}}{{^isPrimitiveType}} + .outType({{returnType}}.class){{/isPrimitiveType}}{{/isMap}}{{/isArray}}{{#isArray}} + .outType({{returnBaseType}}[].class){{/isArray}}{{/hasProduces}}{{#hasConsumes}} + .consumes("{{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}"){{#bodyParams}}{{^isArray}}{{^isMap}}{{^isPrimitiveType}} + .type({{baseType}}.class){{/isPrimitiveType}}{{/isMap}}{{/isArray}}{{#isArray}} + .type({{baseType}}[].class){{/isArray}}{{/bodyParams}} + {{/hasConsumes}}{{#pathParams}} + .param() + .name("{{paramName}}") + .type(RestParamType.path) + .required({{required}}){{#description}} + .description("{{{.}}}"){{/description}} + .endParam(){{/pathParams}}{{#queryParams}} + .param() + .name("{{paramName}}") + .type(RestParamType.query) + .required({{required}}){{#description}} + .description("{{{.}}}"){{/description}} + .endParam(){{/queryParams}}{{#headerParams}} + .param() + .name("{{paramName}}") + .type(RestParamType.header) + .required({{required}}){{#description}} + .description("{{{.}}}"){{/description}} + .endParam(){{/headerParams}}{{#bodyParams}} + .param() + .name("{{paramName}}") + .type(RestParamType.body) + .required({{required}}){{#description}} + .description("{{{.}}}"){{/description}} + .endParam(){{/bodyParams}}{{#formParams}} + .param() + .name("{{paramName}}") + .type(RestParamType.formData) + .required({{required}}){{#description}} + .description("{{{.}}}"){{/description}} + .endParam(){{/formParams}}{{#performBeanValidation}} + .to("direct:validate-{{operationId}}");{{/performBeanValidation}}{{^performBeanValidation}} + .to("direct:{{operationId}}");{{/performBeanValidation}} + {{/operation}}{{/operations}} + } +} diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/application.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/application.mustache new file mode 100644 index 000000000000..1975bd195307 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-camel-server/application.mustache @@ -0,0 +1,8 @@ +# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}). +# https://openapi-generator.tech +# Do not edit the class manually. + +camel.springboot.name=camel-{{artifactId}} +camel.servlet.mapping.context-path=/api/v1/* + +server.port=8080 \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/errorProcessor.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/errorProcessor.mustache new file mode 100644 index 000000000000..0df67de43bb7 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-camel-server/errorProcessor.mustache @@ -0,0 +1,33 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package {{basePackage}}; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.component.bean.validator.BeanValidationException; +import org.springframework.stereotype.Component; +{{#jackson}} +import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;{{/jackson}} + +@Component("{{camelValidationErrorProcessor}}") +public class ValidationErrorProcessor implements Processor { + + @Override + public void process(Exchange exchange) throws Exception { + Exception fault = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); + int httpStatusCode = 500; + if (fault instanceof BeanValidationException) { + httpStatusCode = 400; + } + {{#jackson}} + if (fault instanceof UnrecognizedPropertyException) { + httpStatusCode = 400; + } + {{/jackson}} + exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, httpStatusCode); + exchange.getIn().setBody(fault.getMessage()); + } +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/exampleString.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/exampleString.mustache new file mode 100644 index 000000000000..1f72a330ef62 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-camel-server/exampleString.mustache @@ -0,0 +1 @@ +{{#lambdaSplitString}}{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{#lambdaTrimWhitespace}}{{{example}}}{{/lambdaTrimWhitespace}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}{{/lambdaSplitString}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/exampleStringArray.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/exampleStringArray.mustache new file mode 100644 index 000000000000..99e5f81bdb8f --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-camel-server/exampleStringArray.mustache @@ -0,0 +1 @@ +{{#lambdaSplitString}}{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{#lambdaTrimWhitespace}}[{{{example}}}]{{/lambdaTrimWhitespace}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}{{/lambdaSplitString}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/pom.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/pom.mustache new file mode 100644 index 000000000000..d7c006cc40c1 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-camel-server/pom.mustache @@ -0,0 +1,193 @@ + + + + 4.0.0 + + {{groupId}} + {{artifactId}} + jar + {{artifactId}} + {{artifactVersion}} + + + {{scmConnection}} + {{scmDeveloperConnection}} + {{scmUrl}} + + + + + {{licenseName}} + {{licenseUrl}} + repo + + + + + + {{developerName}} + {{developerEmail}} + {{developerOrganization}} + {{developerOrganizationUrl}} + + + + + 2.6.2 + 3.14.0 + + + + + + org.apache.camel + camel-bom + ${org.apache.camel.version} + pom + import + + + org.apache.camel.springboot + camel-spring-boot-bom + ${org.apache.camel.version} + pom + import + + + org.springframework.boot + spring-boot-dependencies + ${org.springframework.boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + maven-surefire-plugin + 2.22.2 + + + + + + + org.apache.camel.springboot + camel-spring-boot-starter + + + + org.apache.camel.springboot + camel-servlet-starter + + + + org.springframework.boot + spring-boot-starter-web + + + + org.openapitools + jackson-databind-nullable + 0.2.1 + + + io.swagger + swagger-annotations + 1.6.3 + + {{#oas3}} + + io.swagger.core.v3 + swagger-annotations + 2.1.11 + + {{/oas3}} + {{#jackson}} + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.13.0 + + + com.fasterxml.jackson.datatype + jackson-datatype-jdk8 + 2.13.0 + + + org.apache.camel + camel-jackson + + {{#withXml}} + + org.apache.camel + camel-jacksonxml + + {{/withXml}}{{/jackson}} + {{#withXml}} + + org.apache.camel + camel-jaxb + + {{/withXml}} + + org.apache.camel + camel-direct + + + {{#useBeanValidation}} + + org.apache.camel + camel-bean-validator + + {{/useBeanValidation}} + + + + com.mashape.unirest + unirest-java + 1.4.9 + test + + + + org.apache.camel + camel-test-spring-junit5 + test + + + + org.springframework.boot + spring-boot-starter-test + test + + + + \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/restConfiguration.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/restConfiguration.mustache new file mode 100644 index 000000000000..44af274af40a --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-camel-server/restConfiguration.mustache @@ -0,0 +1,22 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package {{apiPackage}}; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +import org.apache.camel.model.rest.RestBindingMode; + +@Component +public class RestConfiguration extends RouteBuilder { + @Override + public void configure() throws Exception { + restConfiguration() + .component("{{camelRestComponent}}") + .bindingMode(RestBindingMode.{{camelRestBindingMode}}){{#camelDataformatProperties}} + .dataFormatProperty("{{key}}", "{{value}}"){{/camelDataformatProperties}} + .clientRequestValidation({{camelRestClientRequestValidation}}); + } +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/routesImpl.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/routesImpl.mustache new file mode 100644 index 000000000000..427aa3021d71 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-camel-server/routesImpl.mustache @@ -0,0 +1,34 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package {{apiPackage}}; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +import org.apache.camel.LoggingLevel; +import {{modelPackage}}.*; +import org.apache.camel.model.dataformat.JsonLibrary; + +@Component +public class {{classname}}RoutesImpl extends RouteBuilder { + @Override + public void configure() throws Exception { + {{#operations}}{{#operation}} + /** + {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}} + **/ + from("direct:{{operationId}}") + .id("{{operationId}}") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"){{#hasProduces}}{{#examples}}{{#-first}}{{^isArray}}{{^isMap}}{{^isPrimitiveType}} + .setBody(constant({{>exampleString}})) + .unmarshal().json(JsonLibrary.Jackson, {{returnType}}.class){{/isPrimitiveType}}{{/isMap}}{{/isArray}}{{#isArray}} + .setBody(constant({{>exampleStringArray}})) + .unmarshal().json(JsonLibrary.Jackson, {{returnBaseType}}[].class){{/isArray}}{{/-first}}{{/examples}}{{/hasProduces}};{{/operation}}{{/operations}} + } +} diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/test.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/test.mustache new file mode 100644 index 000000000000..677f0e522ac0 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-camel-server/test.mustache @@ -0,0 +1,63 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package {{apiPackage}}; + +import org.junit.jupiter.api.Test; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.springframework.boot.test.context.SpringBootTest; +import com.mashape.unirest.request.HttpRequest; +import com.mashape.unirest.request.HttpRequestWithBody; +import com.mashape.unirest.http.Unirest; +import com.mashape.unirest.http.JsonNode; +import com.mashape.unirest.http.HttpResponse; +import java.io.InputStream; +import org.junit.jupiter.api.Assertions; + +@CamelSpringBootTest +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class {{classname}}Test { + private static final String API_URL = "http://127.0.0.1:8080/api/v1"; +{{#operations}}{{#operation}}{{#examples}}{{#-first}}{{#vendorExtensions}}{{^camelRestBindingMode}} + @Test + public void {{operationId}}TestJson() throws Exception { + String contentType = "application/json"; + String accept = "application/json"; + String url = API_URL + "{{path}}"; + HttpRequest httpRequest = Unirest.{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}(url);{{#hasConsumes}} + httpRequest = httpRequest.header("Content-Type", contentType);{{/hasConsumes}}{{#hasProduces}} + httpRequest = httpRequest.header("Accept", accept);{{/hasProduces}}{{#pathParams}} + httpRequest = httpRequest.routeParam("{{paramName}}", "1");{{/pathParams}}{{#queryParams}} + httpRequest = httpRequest.queryString("{{paramName}}", "1");{{/queryParams}} + {{#hasConsumes}}{{#examples}}{{#-first}} + String requestBody = {{>exampleString}}; + httpRequest = ((HttpRequestWithBody) httpRequest).body(requestBody).getHttpRequest(); + {{/-first}}{{/examples}}{{/hasConsumes}} + {{#hasProduces}}{{#produces}}{{#isJson}} + HttpResponse httpResponse = httpRequest.asJson();{{/isJson}}{{/produces}}{{/hasProduces}}{{^hasProduces}} + HttpResponse httpResponse = httpRequest.asBinary();{{/hasProduces}} + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + {{#examples}}{{#-last}}{{^isArray}} + @Test + public void {{operationId}}TestXml() throws Exception { + String contentType = "application/xml"; + String accept = "application/xml"; + String url = API_URL + "{{path}}"; + HttpRequest httpRequest = Unirest.{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}(url);{{#hasConsumes}} + httpRequest = httpRequest.header("Content-Type", contentType);{{/hasConsumes}}{{#hasProduces}} + httpRequest = httpRequest.header("Accept", accept);{{/hasProduces}}{{#pathParams}} + httpRequest = httpRequest.routeParam("{{paramName}}", "1");{{/pathParams}}{{#queryParams}} + httpRequest = httpRequest.queryString("{{paramName}}", "1");{{/queryParams}} + {{#hasConsumes}}{{#examples}}{{^-first}} + String requestBody = {{>exampleString}}; + httpRequest = ((HttpRequestWithBody) httpRequest).body(requestBody).getHttpRequest(); + {{/-first}}{{/examples}}{{/hasConsumes}} + {{#hasProduces}}{{#produces}}{{#isXml}} + HttpResponse httpResponse = httpRequest.asString();{{/isXml}}{{/produces}}{{/hasProduces}}{{^hasProduces}} + HttpResponse httpResponse = httpRequest.asBinary();{{/hasProduces}} + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + }{{/isArray}}{{/-last}}{{/examples}}{{/camelRestBindingMode}}{{/vendorExtensions}}{{/-first}}{{/examples}}{{/operation}}{{/operations}} +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-camel-server/validation.mustache b/modules/openapi-generator/src/main/resources/java-camel-server/validation.mustache new file mode 100644 index 000000000000..27aa2ce4ec70 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-camel-server/validation.mustache @@ -0,0 +1,28 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package {{apiPackage}}; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +import org.apache.camel.LoggingLevel; + +@Component +public class {{classname}}Validator extends RouteBuilder { + @Override + public void configure() throws Exception { + onException(Exception.class) + .log(LoggingLevel.ERROR, "${exception.message}: ${exception.stacktrace}") + .handled(true) + .process("{{camelValidationErrorProcessor}}"); + {{#operations}}{{#operation}} + from("direct:validate-{{operationId}}") + .id("validate-{{operationId}}"){{#hasConsumes}} + .to("bean-validator://validate-request"){{/hasConsumes}} + .to("direct:{{operationId}}"){{^hasProduces}};{{/hasProduces}}{{#hasProduces}} + .to("bean-validator://validate-response");{{/hasProduces}} + {{/operation}}{{/operations}} + } +} diff --git a/samples/server/petstore/java-camel/.openapi-generator-ignore b/samples/server/petstore/java-camel/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/petstore/java-camel/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/java-camel/.openapi-generator/FILES b/samples/server/petstore/java-camel/.openapi-generator/FILES new file mode 100644 index 000000000000..4c9d78d30ebe --- /dev/null +++ b/samples/server/petstore/java-camel/.openapi-generator/FILES @@ -0,0 +1,22 @@ +README.md +pom.xml +src/main/java/org/openapitools/OpenAPI2SpringBoot.java +src/main/java/org/openapitools/RFC3339DateFormat.java +src/main/java/org/openapitools/RestConfiguration.java +src/main/java/org/openapitools/ValidationErrorProcessor.java +src/main/java/org/openapitools/api/PetApi.java +src/main/java/org/openapitools/api/PetApiRoutesImpl.java +src/main/java/org/openapitools/api/PetApiValidator.java +src/main/java/org/openapitools/api/StoreApi.java +src/main/java/org/openapitools/api/StoreApiRoutesImpl.java +src/main/java/org/openapitools/api/StoreApiValidator.java +src/main/java/org/openapitools/api/UserApi.java +src/main/java/org/openapitools/api/UserApiRoutesImpl.java +src/main/java/org/openapitools/api/UserApiValidator.java +src/main/java/org/openapitools/model/Category.java +src/main/java/org/openapitools/model/ModelApiResponse.java +src/main/java/org/openapitools/model/Order.java +src/main/java/org/openapitools/model/Pet.java +src/main/java/org/openapitools/model/Tag.java +src/main/java/org/openapitools/model/User.java +src/main/resources/application.properties diff --git a/samples/server/petstore/java-camel/.openapi-generator/VERSION b/samples/server/petstore/java-camel/.openapi-generator/VERSION new file mode 100644 index 000000000000..0984c4c1ad21 --- /dev/null +++ b/samples/server/petstore/java-camel/.openapi-generator/VERSION @@ -0,0 +1 @@ +5.4.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/java-camel/README.md b/samples/server/petstore/java-camel/README.md new file mode 100644 index 000000000000..e20452e84920 --- /dev/null +++ b/samples/server/petstore/java-camel/README.md @@ -0,0 +1,7 @@ +# OpenAPI generated server + +Apache Camel Server + +```bash +mvn clean test +``` \ No newline at end of file diff --git a/samples/server/petstore/java-camel/pom.xml b/samples/server/petstore/java-camel/pom.xml new file mode 100644 index 000000000000..8391657c52fc --- /dev/null +++ b/samples/server/petstore/java-camel/pom.xml @@ -0,0 +1,185 @@ + + + + 4.0.0 + + org.openapitools + openapi-camel + jar + openapi-camel + 1.0.0 + + + scm:git:git@github.com:openapitools/openapi-generator.git + scm:git:git@github.com:openapitools/openapi-generator.git + https://github.com/openapitools/openapi-generator + + + + + Unlicense + https://www.apache.org/licenses/LICENSE-2.0.html + repo + + + + + + OpenAPI-Generator Contributors + team@openapitools.org + OpenAPITools.org + http://openapitools.org + + + + + 2.6.2 + 3.14.0 + + + + + + org.apache.camel + camel-bom + ${org.apache.camel.version} + pom + import + + + org.apache.camel.springboot + camel-spring-boot-bom + ${org.apache.camel.version} + pom + import + + + org.springframework.boot + spring-boot-dependencies + ${org.springframework.boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + maven-surefire-plugin + 2.22.2 + + + + + + + org.apache.camel.springboot + camel-spring-boot-starter + + + + org.apache.camel.springboot + camel-servlet-starter + + + + org.springframework.boot + spring-boot-starter-web + + + + org.openapitools + jackson-databind-nullable + 0.2.1 + + + io.swagger + swagger-annotations + 1.6.3 + + + io.swagger.core.v3 + swagger-annotations + 2.1.11 + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.13.0 + + + com.fasterxml.jackson.datatype + jackson-datatype-jdk8 + 2.13.0 + + + org.apache.camel + camel-jackson + + + org.apache.camel + camel-jacksonxml + + + + org.apache.camel + camel-jaxb + + + org.apache.camel + camel-direct + + + + org.apache.camel + camel-bean-validator + + + + + com.mashape.unirest + unirest-java + 1.4.9 + test + + + + org.apache.camel + camel-test-spring-junit5 + test + + + + org.springframework.boot + spring-boot-starter-test + test + + + + \ No newline at end of file diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/OpenAPI2SpringBoot.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/OpenAPI2SpringBoot.java new file mode 100644 index 000000000000..7caef40973ef --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/OpenAPI2SpringBoot.java @@ -0,0 +1,64 @@ +package org.openapitools; + +import com.fasterxml.jackson.databind.Module; +import org.openapitools.jackson.nullable.JsonNullableModule; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.ExitCodeGenerator; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@SpringBootApplication +@ComponentScan(basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"}) +public class OpenAPI2SpringBoot implements CommandLineRunner { + + @Override + public void run(String... arg0) throws Exception { + if (arg0.length > 0 && arg0[0].equals("exitcode")) { + throw new ExitException(); + } + } + + public static void main(String[] args) throws Exception { + new SpringApplication(OpenAPI2SpringBoot.class).run(args); + } + + static class ExitException extends RuntimeException implements ExitCodeGenerator { + private static final long serialVersionUID = 1L; + + @Override + public int getExitCode() { + return 10; + } + + } + + @Bean + public WebMvcConfigurer webConfigurer() { + return new WebMvcConfigurerAdapter() { + /*@Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("*") + .allowedHeaders("Content-Type"); + }*/ + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.14.2/"); + } + }; + } + + @Bean + public Module jsonNullableModule() { + return new JsonNullableModule(); + } + +} diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/RFC3339DateFormat.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/RFC3339DateFormat.java new file mode 100644 index 000000000000..bcd3936d8b34 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/RFC3339DateFormat.java @@ -0,0 +1,38 @@ +package org.openapitools; + +import com.fasterxml.jackson.databind.util.StdDateFormat; + +import java.text.DateFormat; +import java.text.FieldPosition; +import java.text.ParsePosition; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +public class RFC3339DateFormat extends DateFormat { + private static final long serialVersionUID = 1L; + private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); + + private final StdDateFormat fmt = new StdDateFormat() + .withTimeZone(TIMEZONE_Z) + .withColonInTimeZone(true); + + public RFC3339DateFormat() { + this.calendar = new GregorianCalendar(); + } + + @Override + public Date parse(String source, ParsePosition pos) { + return fmt.parse(source, pos); + } + + @Override + public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { + return fmt.format(date, toAppendTo, fieldPosition); + } + + @Override + public Object clone() { + return this; + } +} \ No newline at end of file diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/RestConfiguration.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/RestConfiguration.java new file mode 100644 index 000000000000..f9273736a2f3 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/RestConfiguration.java @@ -0,0 +1,22 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +import org.apache.camel.model.rest.RestBindingMode; + +@Component +public class RestConfiguration extends RouteBuilder { + @Override + public void configure() throws Exception { + restConfiguration() + .component("servlet") + .bindingMode(RestBindingMode.auto) + .dataFormatProperty("json.out.disableFeatures", "WRITE_DATES_AS_TIMESTAMPS") + .clientRequestValidation(true); + } +} \ No newline at end of file diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/ValidationErrorProcessor.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/ValidationErrorProcessor.java new file mode 100644 index 000000000000..d74fcf78d216 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/ValidationErrorProcessor.java @@ -0,0 +1,30 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.component.bean.validator.BeanValidationException; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; + +@Component("validationErrorProcessor") +public class ValidationErrorProcessor implements Processor { + + @Override + public void process(Exchange exchange) throws Exception { + Exception fault = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); + int httpStatusCode = 500; + if (fault instanceof BeanValidationException) { + httpStatusCode = 400; + } + if (fault instanceof UnrecognizedPropertyException) { + httpStatusCode = 400; + } + exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, httpStatusCode); + exchange.getIn().setBody(fault.getMessage()); + } +} \ No newline at end of file diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/PetApi.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/PetApi.java new file mode 100644 index 000000000000..01d874fca95f --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/PetApi.java @@ -0,0 +1,268 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.rest.RestParamType; +import org.springframework.stereotype.Component; +import org.openapitools.model.*; +import org.apache.camel.model.rest.RestBindingMode; +import org.apache.camel.LoggingLevel; + +@Component +public class PetApi extends RouteBuilder { + + @Override + public void configure() throws Exception { + onException(Exception.class) + .log(LoggingLevel.ERROR, "${exception.message}: ${exception.stacktrace}") + .handled(true) + .process("validationErrorProcessor"); + + + /** + POST /pet : Add a new pet to the store + **/ + rest() + .securityDefinitions() + .oauth2("petstore_auth") + .flow("implicit") + .authorizationUrl("http://petstore.swagger.io/api/oauth/dialog") + .withScope("write:pets","modify pets in your account") + .withScope("read:pets","read your pets") + + .endSecurityDefinition() + .post("/pet") + .description("Add a new pet to the store") + .id("addPetApi") + .produces("application/xml, application/json") + .outType(Pet.class) + .consumes("application/json, application/xml") + .type(Pet.class) + + .param() + .name("pet") + .type(RestParamType.body) + .required(true) + .description("Pet object that needs to be added to the store") + .endParam() + .to("direct:validate-addPet"); + + + /** + DELETE /pet/{petId} : Deletes a pet + **/ + rest() + .securityDefinitions() + .oauth2("petstore_auth") + .flow("implicit") + .authorizationUrl("http://petstore.swagger.io/api/oauth/dialog") + .withScope("write:pets","modify pets in your account") + .withScope("read:pets","read your pets") + + .endSecurityDefinition() + .delete("/pet/{petId}") + .description("Deletes a pet") + .id("deletePetApi") + .param() + .name("petId") + .type(RestParamType.path) + .required(true) + .description("Pet id to delete") + .endParam() + .param() + .name("apiKey") + .type(RestParamType.header) + .required(false) + .endParam() + .to("direct:validate-deletePet"); + + + /** + GET /pet/findByStatus : Finds Pets by status + **/ + rest() + .securityDefinitions() + .oauth2("petstore_auth") + .flow("implicit") + .authorizationUrl("http://petstore.swagger.io/api/oauth/dialog") + .withScope("read:pets","read your pets") + + .endSecurityDefinition() + .get("/pet/findByStatus") + .description("Finds Pets by status") + .id("findPetsByStatusApi") + .produces("application/xml, application/json") + .outType(Pet[].class) + .param() + .name("status") + .type(RestParamType.query) + .required(true) + .description("Status values that need to be considered for filter") + .endParam() + .to("direct:validate-findPetsByStatus"); + + + /** + GET /pet/findByTags : Finds Pets by tags + **/ + rest() + .securityDefinitions() + .oauth2("petstore_auth") + .flow("implicit") + .authorizationUrl("http://petstore.swagger.io/api/oauth/dialog") + .withScope("read:pets","read your pets") + + .endSecurityDefinition() + .get("/pet/findByTags") + .description("Finds Pets by tags") + .id("findPetsByTagsApi") + .produces("application/xml, application/json") + .outType(Pet[].class) + .param() + .name("tags") + .type(RestParamType.query) + .required(true) + .description("Tags to filter by") + .endParam() + .to("direct:validate-findPetsByTags"); + + + /** + GET /pet/{petId} : Find pet by ID + **/ + rest() + .securityDefinitions() + .apiKey("api_key") + .withHeader("api_key") + + .endSecurityDefinition() + .get("/pet/{petId}") + .description("Find pet by ID") + .id("getPetByIdApi") + .produces("application/xml, application/json") + .outType(Pet.class) + .param() + .name("petId") + .type(RestParamType.path) + .required(true) + .description("ID of pet to return") + .endParam() + .to("direct:validate-getPetById"); + + + /** + PUT /pet : Update an existing pet + **/ + rest() + .securityDefinitions() + .oauth2("petstore_auth") + .flow("implicit") + .authorizationUrl("http://petstore.swagger.io/api/oauth/dialog") + .withScope("write:pets","modify pets in your account") + .withScope("read:pets","read your pets") + + .endSecurityDefinition() + .put("/pet") + .description("Update an existing pet") + .id("updatePetApi") + .produces("application/xml, application/json") + .outType(Pet.class) + .consumes("application/json, application/xml") + .type(Pet.class) + + .param() + .name("pet") + .type(RestParamType.body) + .required(true) + .description("Pet object that needs to be added to the store") + .endParam() + .to("direct:validate-updatePet"); + + + /** + POST /pet/{petId} : Updates a pet in the store with form data + **/ + rest() + .securityDefinitions() + .oauth2("petstore_auth") + .flow("implicit") + .authorizationUrl("http://petstore.swagger.io/api/oauth/dialog") + .withScope("write:pets","modify pets in your account") + .withScope("read:pets","read your pets") + + .endSecurityDefinition() + .post("/pet/{petId}") + .description("Updates a pet in the store with form data") + .id("updatePetWithFormApi") + .clientRequestValidation(false) + .bindingMode(RestBindingMode.off) + .consumes("application/x-www-form-urlencoded") + + .param() + .name("petId") + .type(RestParamType.path) + .required(true) + .description("ID of pet that needs to be updated") + .endParam() + .param() + .name("name") + .type(RestParamType.formData) + .required(false) + .description("Updated name of the pet") + .endParam() + .param() + .name("status") + .type(RestParamType.formData) + .required(false) + .description("Updated status of the pet") + .endParam() + .to("direct:validate-updatePetWithForm"); + + + /** + POST /pet/{petId}/uploadImage : uploads an image + **/ + rest() + .securityDefinitions() + .oauth2("petstore_auth") + .flow("implicit") + .authorizationUrl("http://petstore.swagger.io/api/oauth/dialog") + .withScope("write:pets","modify pets in your account") + .withScope("read:pets","read your pets") + + .endSecurityDefinition() + .post("/pet/{petId}/uploadImage") + .description("uploads an image") + .id("uploadFileApi") + .clientRequestValidation(false) + .bindingMode(RestBindingMode.off) + .produces("application/json") + .outType(ModelApiResponse.class) + .consumes("multipart/form-data") + + .param() + .name("petId") + .type(RestParamType.path) + .required(true) + .description("ID of pet to update") + .endParam() + .param() + .name("additionalMetadata") + .type(RestParamType.formData) + .required(false) + .description("Additional data to pass to server") + .endParam() + .param() + .name("file") + .type(RestParamType.formData) + .required(false) + .description("file to upload") + .endParam() + .to("direct:validate-uploadFile"); + + } +} diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/PetApiRoutesImpl.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/PetApiRoutesImpl.java new file mode 100644 index 000000000000..65de1c7c3d5b --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/PetApiRoutesImpl.java @@ -0,0 +1,112 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +import org.apache.camel.LoggingLevel; +import org.openapitools.model.*; +import org.apache.camel.model.dataformat.JsonLibrary; + +@Component +public class PetApiRoutesImpl extends RouteBuilder { + @Override + public void configure() throws Exception { + + /** + POST /pet : Add a new pet to the store + **/ + from("direct:addPet") + .id("addPet") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}") + .setBody(constant("{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }")) + .unmarshal().json(JsonLibrary.Jackson, Pet.class); + /** + DELETE /pet/{petId} : Deletes a pet + **/ + from("direct:deletePet") + .id("deletePet") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"); + /** + GET /pet/findByStatus : Finds Pets by status + **/ + from("direct:findPetsByStatus") + .id("findPetsByStatus") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}") + .setBody(constant("[{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }]")) + .unmarshal().json(JsonLibrary.Jackson, Pet[].class); + /** + GET /pet/findByTags : Finds Pets by tags + **/ + from("direct:findPetsByTags") + .id("findPetsByTags") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}") + .setBody(constant("[{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }]")) + .unmarshal().json(JsonLibrary.Jackson, Pet[].class); + /** + GET /pet/{petId} : Find pet by ID + **/ + from("direct:getPetById") + .id("getPetById") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}") + .setBody(constant("{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }")) + .unmarshal().json(JsonLibrary.Jackson, Pet.class); + /** + PUT /pet : Update an existing pet + **/ + from("direct:updatePet") + .id("updatePet") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}") + .setBody(constant("{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }")) + .unmarshal().json(JsonLibrary.Jackson, Pet.class); + /** + POST /pet/{petId} : Updates a pet in the store with form data + **/ + from("direct:updatePetWithForm") + .id("updatePetWithForm") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"); + /** + POST /pet/{petId}/uploadImage : uploads an image + **/ + from("direct:uploadFile") + .id("uploadFile") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}") + .setBody(constant("{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }")) + .unmarshal().json(JsonLibrary.Jackson, ModelApiResponse.class); + } +} diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/PetApiValidator.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/PetApiValidator.java new file mode 100644 index 000000000000..f32d4c7d2d85 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/PetApiValidator.java @@ -0,0 +1,64 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +import org.apache.camel.LoggingLevel; + +@Component +public class PetApiValidator extends RouteBuilder { + @Override + public void configure() throws Exception { + onException(Exception.class) + .log(LoggingLevel.ERROR, "${exception.message}: ${exception.stacktrace}") + .handled(true) + .process("validationErrorProcessor"); + + from("direct:validate-addPet") + .id("validate-addPet") + .to("bean-validator://validate-request") + .to("direct:addPet") + .to("bean-validator://validate-response"); + + from("direct:validate-deletePet") + .id("validate-deletePet") + .to("direct:deletePet"); + + from("direct:validate-findPetsByStatus") + .id("validate-findPetsByStatus") + .to("direct:findPetsByStatus") + .to("bean-validator://validate-response"); + + from("direct:validate-findPetsByTags") + .id("validate-findPetsByTags") + .to("direct:findPetsByTags") + .to("bean-validator://validate-response"); + + from("direct:validate-getPetById") + .id("validate-getPetById") + .to("direct:getPetById") + .to("bean-validator://validate-response"); + + from("direct:validate-updatePet") + .id("validate-updatePet") + .to("bean-validator://validate-request") + .to("direct:updatePet") + .to("bean-validator://validate-response"); + + from("direct:validate-updatePetWithForm") + .id("validate-updatePetWithForm") + .to("bean-validator://validate-request") + .to("direct:updatePetWithForm"); + + from("direct:validate-uploadFile") + .id("validate-uploadFile") + .to("bean-validator://validate-request") + .to("direct:uploadFile") + .to("bean-validator://validate-response"); + + } +} diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/StoreApi.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/StoreApi.java new file mode 100644 index 000000000000..55d8651439e3 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/StoreApi.java @@ -0,0 +1,97 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.rest.RestParamType; +import org.springframework.stereotype.Component; +import org.openapitools.model.*; +import org.apache.camel.model.rest.RestBindingMode; +import org.apache.camel.LoggingLevel; + +@Component +public class StoreApi extends RouteBuilder { + + @Override + public void configure() throws Exception { + onException(Exception.class) + .log(LoggingLevel.ERROR, "${exception.message}: ${exception.stacktrace}") + .handled(true) + .process("validationErrorProcessor"); + + + /** + DELETE /store/order/{orderId} : Delete purchase order by ID + **/ + rest() + .delete("/store/order/{orderId}") + .description("Delete purchase order by ID") + .id("deleteOrderApi") + .param() + .name("orderId") + .type(RestParamType.path) + .required(true) + .description("ID of the order that needs to be deleted") + .endParam() + .to("direct:validate-deleteOrder"); + + + /** + GET /store/inventory : Returns pet inventories by status + **/ + rest() + .securityDefinitions() + .apiKey("api_key") + .withHeader("api_key") + + .endSecurityDefinition() + .get("/store/inventory") + .description("Returns pet inventories by status") + .id("getInventoryApi") + .produces("application/json") + .to("direct:validate-getInventory"); + + + /** + GET /store/order/{orderId} : Find purchase order by ID + **/ + rest() + .get("/store/order/{orderId}") + .description("Find purchase order by ID") + .id("getOrderByIdApi") + .produces("application/xml, application/json") + .outType(Order.class) + .param() + .name("orderId") + .type(RestParamType.path) + .required(true) + .description("ID of pet that needs to be fetched") + .endParam() + .to("direct:validate-getOrderById"); + + + /** + POST /store/order : Place an order for a pet + **/ + rest() + .post("/store/order") + .description("Place an order for a pet") + .id("placeOrderApi") + .produces("application/xml, application/json") + .outType(Order.class) + .consumes("application/json") + .type(Order.class) + + .param() + .name("order") + .type(RestParamType.body) + .required(true) + .description("order placed for purchasing the pet") + .endParam() + .to("direct:validate-placeOrder"); + + } +} diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/StoreApiRoutesImpl.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/StoreApiRoutesImpl.java new file mode 100644 index 000000000000..c9fd610e3f2f --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/StoreApiRoutesImpl.java @@ -0,0 +1,64 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +import org.apache.camel.LoggingLevel; +import org.openapitools.model.*; +import org.apache.camel.model.dataformat.JsonLibrary; + +@Component +public class StoreApiRoutesImpl extends RouteBuilder { + @Override + public void configure() throws Exception { + + /** + DELETE /store/order/{orderId} : Delete purchase order by ID + **/ + from("direct:deleteOrder") + .id("deleteOrder") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"); + /** + GET /store/inventory : Returns pet inventories by status + **/ + from("direct:getInventory") + .id("getInventory") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"); + /** + GET /store/order/{orderId} : Find purchase order by ID + **/ + from("direct:getOrderById") + .id("getOrderById") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}") + .setBody(constant("{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\" }")) + .unmarshal().json(JsonLibrary.Jackson, Order.class); + /** + POST /store/order : Place an order for a pet + **/ + from("direct:placeOrder") + .id("placeOrder") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}") + .setBody(constant("{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\" }")) + .unmarshal().json(JsonLibrary.Jackson, Order.class); + } +} diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/StoreApiValidator.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/StoreApiValidator.java new file mode 100644 index 000000000000..ce6ad8207104 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/StoreApiValidator.java @@ -0,0 +1,42 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +import org.apache.camel.LoggingLevel; + +@Component +public class StoreApiValidator extends RouteBuilder { + @Override + public void configure() throws Exception { + onException(Exception.class) + .log(LoggingLevel.ERROR, "${exception.message}: ${exception.stacktrace}") + .handled(true) + .process("validationErrorProcessor"); + + from("direct:validate-deleteOrder") + .id("validate-deleteOrder") + .to("direct:deleteOrder"); + + from("direct:validate-getInventory") + .id("validate-getInventory") + .to("direct:getInventory") + .to("bean-validator://validate-response"); + + from("direct:validate-getOrderById") + .id("validate-getOrderById") + .to("direct:getOrderById") + .to("bean-validator://validate-response"); + + from("direct:validate-placeOrder") + .id("validate-placeOrder") + .to("bean-validator://validate-request") + .to("direct:placeOrder") + .to("bean-validator://validate-response"); + + } +} diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/UserApi.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/UserApi.java new file mode 100644 index 000000000000..3babbf719cc2 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/UserApi.java @@ -0,0 +1,206 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.rest.RestParamType; +import org.springframework.stereotype.Component; +import org.openapitools.model.*; +import org.apache.camel.model.rest.RestBindingMode; +import org.apache.camel.LoggingLevel; + +@Component +public class UserApi extends RouteBuilder { + + @Override + public void configure() throws Exception { + onException(Exception.class) + .log(LoggingLevel.ERROR, "${exception.message}: ${exception.stacktrace}") + .handled(true) + .process("validationErrorProcessor"); + + + /** + POST /user : Create user + **/ + rest() + .securityDefinitions() + .apiKey("api_key") + .withHeader("api_key") + + .endSecurityDefinition() + .post("/user") + .description("Create user") + .id("createUserApi") + .consumes("application/json") + .type(User.class) + + .param() + .name("user") + .type(RestParamType.body) + .required(true) + .description("Created user object") + .endParam() + .to("direct:validate-createUser"); + + + /** + POST /user/createWithArray : Creates list of users with given input array + **/ + rest() + .securityDefinitions() + .apiKey("api_key") + .withHeader("api_key") + + .endSecurityDefinition() + .post("/user/createWithArray") + .description("Creates list of users with given input array") + .id("createUsersWithArrayInputApi") + .consumes("application/json") + .type(User[].class) + + .param() + .name("user") + .type(RestParamType.body) + .required(true) + .description("List of user object") + .endParam() + .to("direct:validate-createUsersWithArrayInput"); + + + /** + POST /user/createWithList : Creates list of users with given input array + **/ + rest() + .securityDefinitions() + .apiKey("api_key") + .withHeader("api_key") + + .endSecurityDefinition() + .post("/user/createWithList") + .description("Creates list of users with given input array") + .id("createUsersWithListInputApi") + .consumes("application/json") + .type(User[].class) + + .param() + .name("user") + .type(RestParamType.body) + .required(true) + .description("List of user object") + .endParam() + .to("direct:validate-createUsersWithListInput"); + + + /** + DELETE /user/{username} : Delete user + **/ + rest() + .securityDefinitions() + .apiKey("api_key") + .withHeader("api_key") + + .endSecurityDefinition() + .delete("/user/{username}") + .description("Delete user") + .id("deleteUserApi") + .param() + .name("username") + .type(RestParamType.path) + .required(true) + .description("The name that needs to be deleted") + .endParam() + .to("direct:validate-deleteUser"); + + + /** + GET /user/{username} : Get user by user name + **/ + rest() + .get("/user/{username}") + .description("Get user by user name") + .id("getUserByNameApi") + .produces("application/xml, application/json") + .outType(User.class) + .param() + .name("username") + .type(RestParamType.path) + .required(true) + .description("The name that needs to be fetched. Use user1 for testing.") + .endParam() + .to("direct:validate-getUserByName"); + + + /** + GET /user/login : Logs user into the system + **/ + rest() + .get("/user/login") + .description("Logs user into the system") + .id("loginUserApi") + .produces("application/xml, application/json") + .outType(String.class) + .param() + .name("username") + .type(RestParamType.query) + .required(true) + .description("The user name for login") + .endParam() + .param() + .name("password") + .type(RestParamType.query) + .required(true) + .description("The password for login in clear text") + .endParam() + .to("direct:validate-loginUser"); + + + /** + GET /user/logout : Logs out current logged in user session + **/ + rest() + .securityDefinitions() + .apiKey("api_key") + .withHeader("api_key") + + .endSecurityDefinition() + .get("/user/logout") + .description("Logs out current logged in user session") + .id("logoutUserApi") + .to("direct:validate-logoutUser"); + + + /** + PUT /user/{username} : Updated user + **/ + rest() + .securityDefinitions() + .apiKey("api_key") + .withHeader("api_key") + + .endSecurityDefinition() + .put("/user/{username}") + .description("Updated user") + .id("updateUserApi") + .consumes("application/json") + .type(User.class) + + .param() + .name("username") + .type(RestParamType.path) + .required(true) + .description("name that need to be deleted") + .endParam() + .param() + .name("user") + .type(RestParamType.body) + .required(true) + .description("Updated user object") + .endParam() + .to("direct:validate-updateUser"); + + } +} diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/UserApiRoutesImpl.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/UserApiRoutesImpl.java new file mode 100644 index 000000000000..b2fd13058a0a --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/UserApiRoutesImpl.java @@ -0,0 +1,102 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +import org.apache.camel.LoggingLevel; +import org.openapitools.model.*; +import org.apache.camel.model.dataformat.JsonLibrary; + +@Component +public class UserApiRoutesImpl extends RouteBuilder { + @Override + public void configure() throws Exception { + + /** + POST /user : Create user + **/ + from("direct:createUser") + .id("createUser") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"); + /** + POST /user/createWithArray : Creates list of users with given input array + **/ + from("direct:createUsersWithArrayInput") + .id("createUsersWithArrayInput") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"); + /** + POST /user/createWithList : Creates list of users with given input array + **/ + from("direct:createUsersWithListInput") + .id("createUsersWithListInput") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"); + /** + DELETE /user/{username} : Delete user + **/ + from("direct:deleteUser") + .id("deleteUser") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"); + /** + GET /user/{username} : Get user by user name + **/ + from("direct:getUserByName") + .id("getUserByName") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}") + .setBody(constant("{ \"firstName\" : \"firstName\", \"lastName\" : \"lastName\", \"password\" : \"password\", \"userStatus\" : 6, \"phone\" : \"phone\", \"id\" : 0, \"email\" : \"email\", \"username\" : \"username\" }")) + .unmarshal().json(JsonLibrary.Jackson, User.class); + /** + GET /user/login : Logs user into the system + **/ + from("direct:loginUser") + .id("loginUser") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"); + /** + GET /user/logout : Logs out current logged in user session + **/ + from("direct:logoutUser") + .id("logoutUser") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"); + /** + PUT /user/{username} : Updated user + **/ + from("direct:updateUser") + .id("updateUser") + .choice() + .when(simple("${body} != null")) + .log(LoggingLevel.INFO, "BODY TYPE: ${body.getClass().getName()}") + .end() + .log(LoggingLevel.INFO, "HEADERS: ${headers}"); + } +} diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/UserApiValidator.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/UserApiValidator.java new file mode 100644 index 000000000000..da259ae0c537 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/api/UserApiValidator.java @@ -0,0 +1,60 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +import org.apache.camel.LoggingLevel; + +@Component +public class UserApiValidator extends RouteBuilder { + @Override + public void configure() throws Exception { + onException(Exception.class) + .log(LoggingLevel.ERROR, "${exception.message}: ${exception.stacktrace}") + .handled(true) + .process("validationErrorProcessor"); + + from("direct:validate-createUser") + .id("validate-createUser") + .to("bean-validator://validate-request") + .to("direct:createUser"); + + from("direct:validate-createUsersWithArrayInput") + .id("validate-createUsersWithArrayInput") + .to("bean-validator://validate-request") + .to("direct:createUsersWithArrayInput"); + + from("direct:validate-createUsersWithListInput") + .id("validate-createUsersWithListInput") + .to("bean-validator://validate-request") + .to("direct:createUsersWithListInput"); + + from("direct:validate-deleteUser") + .id("validate-deleteUser") + .to("direct:deleteUser"); + + from("direct:validate-getUserByName") + .id("validate-getUserByName") + .to("direct:getUserByName") + .to("bean-validator://validate-response"); + + from("direct:validate-loginUser") + .id("validate-loginUser") + .to("direct:loginUser") + .to("bean-validator://validate-response"); + + from("direct:validate-logoutUser") + .id("validate-logoutUser") + .to("direct:logoutUser"); + + from("direct:validate-updateUser") + .id("validate-updateUser") + .to("bean-validator://validate-request") + .to("direct:updateUser"); + + } +} diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Category.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Category.java new file mode 100644 index 000000000000..b5835986beca --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Category.java @@ -0,0 +1,117 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import org.hibernate.validator.constraints.*; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.*; + +import java.util.*; + +/** + * A category for a pet + */ +@Schema(name = "Category",description = "A category for a pet") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaCamelServerCodegen")@JacksonXmlRootElement(localName = "Category") +@XmlRootElement(name = "Category") +@XmlAccessorType(XmlAccessType.FIELD) +public class Category { + @JsonProperty("id") + @JacksonXmlProperty(localName = "id") + private Long id; + + @JsonProperty("name") + @JacksonXmlProperty(localName = "name") + private String name; + + public Category id(Long id) { + this.id = id; + return this; + } + + /** + * Get id + * @return id + */ + @Schema(name = "id", defaultValue = "") + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Category name(String name) { + this.name = name; + return this; + } + + /** + * Get name + * @return name + */ + @Schema(name = "name", defaultValue = "") + +@Pattern(regexp = "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Category category = (Category) o; + return Objects.equals(this.id, category.id) && + Objects.equals(this.name, category.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Category {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/ModelApiResponse.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/ModelApiResponse.java new file mode 100644 index 000000000000..4029a7a8be32 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/ModelApiResponse.java @@ -0,0 +1,143 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import org.hibernate.validator.constraints.*; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.*; + +import java.util.*; + +/** + * Describes the result of uploading an image resource + */ +@Schema(name = "ApiResponse",description = "Describes the result of uploading an image resource") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaCamelServerCodegen")@JacksonXmlRootElement(localName = "ModelApiResponse") +@XmlRootElement(name = "ModelApiResponse") +@XmlAccessorType(XmlAccessType.FIELD) +public class ModelApiResponse { + @JsonProperty("code") + @JacksonXmlProperty(localName = "code") + private Integer code; + + @JsonProperty("type") + @JacksonXmlProperty(localName = "type") + private String type; + + @JsonProperty("message") + @JacksonXmlProperty(localName = "message") + private String message; + + public ModelApiResponse code(Integer code) { + this.code = code; + return this; + } + + /** + * Get code + * @return code + */ + @Schema(name = "code", defaultValue = "") + + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public ModelApiResponse type(String type) { + this.type = type; + return this; + } + + /** + * Get type + * @return type + */ + @Schema(name = "type", defaultValue = "") + + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public ModelApiResponse message(String message) { + this.message = message; + return this; + } + + /** + * Get message + * @return message + */ + @Schema(name = "message", defaultValue = "") + + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ModelApiResponse _apiResponse = (ModelApiResponse) o; + return Objects.equals(this.code, _apiResponse.code) && + Objects.equals(this.type, _apiResponse.type) && + Objects.equals(this.message, _apiResponse.message); + } + + @Override + public int hashCode() { + return Objects.hash(code, type, message); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ModelApiResponse {\n"); + + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Order.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Order.java new file mode 100644 index 000000000000..50fc948d4d59 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Order.java @@ -0,0 +1,262 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Date; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import org.hibernate.validator.constraints.*; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.*; + +import java.util.*; + +/** + * An order for a pets from the pet store + */ +@Schema(name = "Order",description = "An order for a pets from the pet store") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaCamelServerCodegen")@JacksonXmlRootElement(localName = "Order") +@XmlRootElement(name = "Order") +@XmlAccessorType(XmlAccessType.FIELD) +public class Order { + @JsonProperty("id") + @JacksonXmlProperty(localName = "id") + private Long id; + + @JsonProperty("petId") + @JacksonXmlProperty(localName = "petId") + private Long petId; + + @JsonProperty("quantity") + @JacksonXmlProperty(localName = "quantity") + private Integer quantity; + + @JsonProperty("shipDate") + @JacksonXmlProperty(localName = "shipDate") + @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME) + private Date shipDate; + + /** + * Order Status + */ + public enum StatusEnum { + PLACED("placed"), + + APPROVED("approved"), + + DELIVERED("delivered"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static StatusEnum fromValue(String value) { + for (StatusEnum b : StatusEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("status") + @JacksonXmlProperty(localName = "status") + private StatusEnum status; + + @JsonProperty("complete") + @JacksonXmlProperty(localName = "complete") + private Boolean complete = false; + + public Order id(Long id) { + this.id = id; + return this; + } + + /** + * Get id + * @return id + */ + @Schema(name = "id", defaultValue = "") + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Order petId(Long petId) { + this.petId = petId; + return this; + } + + /** + * Get petId + * @return petId + */ + @Schema(name = "petId", defaultValue = "") + + + public Long getPetId() { + return petId; + } + + public void setPetId(Long petId) { + this.petId = petId; + } + + public Order quantity(Integer quantity) { + this.quantity = quantity; + return this; + } + + /** + * Get quantity + * @return quantity + */ + @Schema(name = "quantity", defaultValue = "") + + + public Integer getQuantity() { + return quantity; + } + + public void setQuantity(Integer quantity) { + this.quantity = quantity; + } + + public Order shipDate(Date shipDate) { + this.shipDate = shipDate; + return this; + } + + /** + * Get shipDate + * @return shipDate + */ + @Schema(name = "shipDate", defaultValue = "") + + @Valid + + public Date getShipDate() { + return shipDate; + } + + public void setShipDate(Date shipDate) { + this.shipDate = shipDate; + } + + public Order status(StatusEnum status) { + this.status = status; + return this; + } + + /** + * Order Status + * @return status + */ + @Schema(name = "status", defaultValue = "Order Status") + + + public StatusEnum getStatus() { + return status; + } + + public void setStatus(StatusEnum status) { + this.status = status; + } + + public Order complete(Boolean complete) { + this.complete = complete; + return this; + } + + /** + * Get complete + * @return complete + */ + @Schema(name = "complete", defaultValue = "") + + + public Boolean getComplete() { + return complete; + } + + public void setComplete(Boolean complete) { + this.complete = complete; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Order order = (Order) o; + return Objects.equals(this.id, order.id) && + Objects.equals(this.petId, order.petId) && + Objects.equals(this.quantity, order.quantity) && + Objects.equals(this.shipDate, order.shipDate) && + Objects.equals(this.status, order.status) && + Objects.equals(this.complete, order.complete); + } + + @Override + public int hashCode() { + return Objects.hash(id, petId, quantity, shipDate, status, complete); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Order {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" petId: ").append(toIndentedString(petId)).append("\n"); + sb.append(" quantity: ").append(toIndentedString(quantity)).append("\n"); + sb.append(" shipDate: ").append(toIndentedString(shipDate)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" complete: ").append(toIndentedString(complete)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Pet.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Pet.java new file mode 100644 index 000000000000..04fe97643f6e --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Pet.java @@ -0,0 +1,282 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.List; +import org.openapitools.model.Category; +import org.openapitools.model.Tag; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import org.hibernate.validator.constraints.*; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.*; + +import java.util.*; + +/** + * A pet for sale in the pet store + */ +@Schema(name = "Pet",description = "A pet for sale in the pet store") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaCamelServerCodegen")@JacksonXmlRootElement(localName = "Pet") +@XmlRootElement(name = "Pet") +@XmlAccessorType(XmlAccessType.FIELD) +public class Pet { + @JsonProperty("id") + @JacksonXmlProperty(localName = "id") + private Long id; + + @JsonProperty("category") + @JacksonXmlProperty(localName = "category") + private Category category; + + @JsonProperty("name") + @JacksonXmlProperty(localName = "name") + private String name; + + @JsonProperty("photoUrls") + @JacksonXmlProperty(localName = "photoUrl") + @Valid + private List photoUrls = new ArrayList(); + + @JsonProperty("tags") + @JacksonXmlProperty(localName = "tag") + @Valid + private List tags = null; + + /** + * pet status in the store + */ + public enum StatusEnum { + AVAILABLE("available"), + + PENDING("pending"), + + SOLD("sold"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static StatusEnum fromValue(String value) { + for (StatusEnum b : StatusEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("status") + @JacksonXmlProperty(localName = "status") + private StatusEnum status; + + public Pet id(Long id) { + this.id = id; + return this; + } + + /** + * Get id + * @return id + */ + @Schema(name = "id", defaultValue = "") + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Pet category(Category category) { + this.category = category; + return this; + } + + /** + * Get category + * @return category + */ + @Schema(name = "category", defaultValue = "") + + @Valid + + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } + + public Pet name(String name) { + this.name = name; + return this; + } + + /** + * Get name + * @return name + */ + @Schema(name = "name", example = "doggie", required = true, defaultValue = "") + @NotNull + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Pet photoUrls(List photoUrls) { + this.photoUrls = photoUrls; + return this; + } + + public Pet addPhotoUrlsItem(String photoUrlsItem) { + this.photoUrls.add(photoUrlsItem); + return this; + } + + /** + * Get photoUrls + * @return photoUrls + */ + @Schema(name = "photoUrls", required = true, defaultValue = "") + @NotNull + + + public List getPhotoUrls() { + return photoUrls; + } + + public void setPhotoUrls(List photoUrls) { + this.photoUrls = photoUrls; + } + + public Pet tags(List tags) { + this.tags = tags; + return this; + } + + public Pet addTagsItem(Tag tagsItem) { + if (this.tags == null) { + this.tags = new ArrayList(); + } + this.tags.add(tagsItem); + return this; + } + + /** + * Get tags + * @return tags + */ + @Schema(name = "tags", defaultValue = "") + + @Valid + + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + public Pet status(StatusEnum status) { + this.status = status; + return this; + } + + /** + * pet status in the store + * @return status + */ + @Schema(name = "status", defaultValue = "pet status in the store") + + + public StatusEnum getStatus() { + return status; + } + + public void setStatus(StatusEnum status) { + this.status = status; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Pet pet = (Pet) o; + return Objects.equals(this.id, pet.id) && + Objects.equals(this.category, pet.category) && + Objects.equals(this.name, pet.name) && + Objects.equals(this.photoUrls, pet.photoUrls) && + Objects.equals(this.tags, pet.tags) && + Objects.equals(this.status, pet.status); + } + + @Override + public int hashCode() { + return Objects.hash(id, category, name, photoUrls, tags, status); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Pet {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" category: ").append(toIndentedString(category)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" photoUrls: ").append(toIndentedString(photoUrls)).append("\n"); + sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Tag.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Tag.java new file mode 100644 index 000000000000..1c26d8799952 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/Tag.java @@ -0,0 +1,117 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import org.hibernate.validator.constraints.*; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.*; + +import java.util.*; + +/** + * A tag for a pet + */ +@Schema(name = "Tag",description = "A tag for a pet") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaCamelServerCodegen")@JacksonXmlRootElement(localName = "Tag") +@XmlRootElement(name = "Tag") +@XmlAccessorType(XmlAccessType.FIELD) +public class Tag { + @JsonProperty("id") + @JacksonXmlProperty(localName = "id") + private Long id; + + @JsonProperty("name") + @JacksonXmlProperty(localName = "name") + private String name; + + public Tag id(Long id) { + this.id = id; + return this; + } + + /** + * Get id + * @return id + */ + @Schema(name = "id", defaultValue = "") + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Tag name(String name) { + this.name = name; + return this; + } + + /** + * Get name + * @return name + */ + @Schema(name = "name", defaultValue = "") + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Tag tag = (Tag) o; + return Objects.equals(this.id, tag.id) && + Objects.equals(this.name, tag.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Tag {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/User.java b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/User.java new file mode 100644 index 000000000000..e6943a48f328 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/java/org/openapitools/model/User.java @@ -0,0 +1,273 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import org.hibernate.validator.constraints.*; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import io.swagger.v3.oas.annotations.media.Schema; + +import javax.xml.bind.annotation.*; + +import java.util.*; + +/** + * A User who is purchasing from the pet store + */ +@Schema(name = "User",description = "A User who is purchasing from the pet store") +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaCamelServerCodegen")@JacksonXmlRootElement(localName = "User") +@XmlRootElement(name = "User") +@XmlAccessorType(XmlAccessType.FIELD) +public class User { + @JsonProperty("id") + @JacksonXmlProperty(localName = "id") + private Long id; + + @JsonProperty("username") + @JacksonXmlProperty(localName = "username") + private String username; + + @JsonProperty("firstName") + @JacksonXmlProperty(localName = "firstName") + private String firstName; + + @JsonProperty("lastName") + @JacksonXmlProperty(localName = "lastName") + private String lastName; + + @JsonProperty("email") + @JacksonXmlProperty(localName = "email") + private String email; + + @JsonProperty("password") + @JacksonXmlProperty(localName = "password") + private String password; + + @JsonProperty("phone") + @JacksonXmlProperty(localName = "phone") + private String phone; + + @JsonProperty("userStatus") + @JacksonXmlProperty(localName = "userStatus") + private Integer userStatus; + + public User id(Long id) { + this.id = id; + return this; + } + + /** + * Get id + * @return id + */ + @Schema(name = "id", defaultValue = "") + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public User username(String username) { + this.username = username; + return this; + } + + /** + * Get username + * @return username + */ + @Schema(name = "username", defaultValue = "") + + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public User firstName(String firstName) { + this.firstName = firstName; + return this; + } + + /** + * Get firstName + * @return firstName + */ + @Schema(name = "firstName", defaultValue = "") + + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public User lastName(String lastName) { + this.lastName = lastName; + return this; + } + + /** + * Get lastName + * @return lastName + */ + @Schema(name = "lastName", defaultValue = "") + + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public User email(String email) { + this.email = email; + return this; + } + + /** + * Get email + * @return email + */ + @Schema(name = "email", defaultValue = "") + + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public User password(String password) { + this.password = password; + return this; + } + + /** + * Get password + * @return password + */ + @Schema(name = "password", defaultValue = "") + + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public User phone(String phone) { + this.phone = phone; + return this; + } + + /** + * Get phone + * @return phone + */ + @Schema(name = "phone", defaultValue = "") + + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public User userStatus(Integer userStatus) { + this.userStatus = userStatus; + return this; + } + + /** + * User Status + * @return userStatus + */ + @Schema(name = "userStatus", defaultValue = "User Status") + + + public Integer getUserStatus() { + return userStatus; + } + + public void setUserStatus(Integer userStatus) { + this.userStatus = userStatus; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + User user = (User) o; + return Objects.equals(this.id, user.id) && + Objects.equals(this.username, user.username) && + Objects.equals(this.firstName, user.firstName) && + Objects.equals(this.lastName, user.lastName) && + Objects.equals(this.email, user.email) && + Objects.equals(this.password, user.password) && + Objects.equals(this.phone, user.phone) && + Objects.equals(this.userStatus, user.userStatus); + } + + @Override + public int hashCode() { + return Objects.hash(id, username, firstName, lastName, email, password, phone, userStatus); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class User {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" username: ").append(toIndentedString(username)).append("\n"); + sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n"); + sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n"); + sb.append(" email: ").append(toIndentedString(email)).append("\n"); + sb.append(" password: ").append(toIndentedString(password)).append("\n"); + sb.append(" phone: ").append(toIndentedString(phone)).append("\n"); + sb.append(" userStatus: ").append(toIndentedString(userStatus)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/samples/server/petstore/java-camel/src/main/resources/application.properties b/samples/server/petstore/java-camel/src/main/resources/application.properties new file mode 100644 index 000000000000..36cdb9894176 --- /dev/null +++ b/samples/server/petstore/java-camel/src/main/resources/application.properties @@ -0,0 +1,8 @@ +# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +# https://openapi-generator.tech +# Do not edit the class manually. + +camel.springboot.name=camel-openapi-camel +camel.servlet.mapping.context-path=/api/v1/* + +server.port=8080 \ No newline at end of file diff --git a/samples/server/petstore/java-camel/src/test/java/org/openapitools/api/PetApiTest.java b/samples/server/petstore/java-camel/src/test/java/org/openapitools/api/PetApiTest.java new file mode 100644 index 000000000000..d02598dd1cc6 --- /dev/null +++ b/samples/server/petstore/java-camel/src/test/java/org/openapitools/api/PetApiTest.java @@ -0,0 +1,145 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.junit.jupiter.api.Test; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.springframework.boot.test.context.SpringBootTest; +import com.mashape.unirest.request.HttpRequest; +import com.mashape.unirest.request.HttpRequestWithBody; +import com.mashape.unirest.http.Unirest; +import com.mashape.unirest.http.JsonNode; +import com.mashape.unirest.http.HttpResponse; +import java.io.InputStream; +import org.junit.jupiter.api.Assertions; + +@CamelSpringBootTest +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class PetApiTest { + private static final String API_URL = "http://127.0.0.1:8080/api/v1"; + + @Test + public void addPetTestJson() throws Exception { + String contentType = "application/json"; + String accept = "application/json"; + String url = API_URL + "/pet"; + HttpRequest httpRequest = Unirest.post(url); + httpRequest = httpRequest.header("Content-Type", contentType); + httpRequest = httpRequest.header("Accept", accept); + + String requestBody = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }"; + httpRequest = ((HttpRequestWithBody) httpRequest).body(requestBody).getHttpRequest(); + + + HttpResponse httpResponse = httpRequest.asJson(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + + @Test + public void addPetTestXml() throws Exception { + String contentType = "application/xml"; + String accept = "application/xml"; + String url = API_URL + "/pet"; + HttpRequest httpRequest = Unirest.post(url); + httpRequest = httpRequest.header("Content-Type", contentType); + httpRequest = httpRequest.header("Accept", accept); + + String requestBody = " 123456789 doggie aeiou aeiou "; + httpRequest = ((HttpRequestWithBody) httpRequest).body(requestBody).getHttpRequest(); + + + HttpResponse httpResponse = httpRequest.asString(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + @Test + public void findPetsByStatusTestJson() throws Exception { + String contentType = "application/json"; + String accept = "application/json"; + String url = API_URL + "/pet/findByStatus"; + HttpRequest httpRequest = Unirest.get(url); + httpRequest = httpRequest.header("Accept", accept); + httpRequest = httpRequest.queryString("status", "1"); + + + HttpResponse httpResponse = httpRequest.asJson(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + + @Test + public void findPetsByTagsTestJson() throws Exception { + String contentType = "application/json"; + String accept = "application/json"; + String url = API_URL + "/pet/findByTags"; + HttpRequest httpRequest = Unirest.get(url); + httpRequest = httpRequest.header("Accept", accept); + httpRequest = httpRequest.queryString("tags", "1"); + + + HttpResponse httpResponse = httpRequest.asJson(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + + @Test + public void getPetByIdTestJson() throws Exception { + String contentType = "application/json"; + String accept = "application/json"; + String url = API_URL + "/pet/{petId}"; + HttpRequest httpRequest = Unirest.get(url); + httpRequest = httpRequest.header("Accept", accept); + httpRequest = httpRequest.routeParam("petId", "1"); + + + HttpResponse httpResponse = httpRequest.asJson(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + + @Test + public void getPetByIdTestXml() throws Exception { + String contentType = "application/xml"; + String accept = "application/xml"; + String url = API_URL + "/pet/{petId}"; + HttpRequest httpRequest = Unirest.get(url); + httpRequest = httpRequest.header("Accept", accept); + httpRequest = httpRequest.routeParam("petId", "1"); + + + HttpResponse httpResponse = httpRequest.asString(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + @Test + public void updatePetTestJson() throws Exception { + String contentType = "application/json"; + String accept = "application/json"; + String url = API_URL + "/pet"; + HttpRequest httpRequest = Unirest.put(url); + httpRequest = httpRequest.header("Content-Type", contentType); + httpRequest = httpRequest.header("Accept", accept); + + String requestBody = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }"; + httpRequest = ((HttpRequestWithBody) httpRequest).body(requestBody).getHttpRequest(); + + + HttpResponse httpResponse = httpRequest.asJson(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + + @Test + public void updatePetTestXml() throws Exception { + String contentType = "application/xml"; + String accept = "application/xml"; + String url = API_URL + "/pet"; + HttpRequest httpRequest = Unirest.put(url); + httpRequest = httpRequest.header("Content-Type", contentType); + httpRequest = httpRequest.header("Accept", accept); + + String requestBody = " 123456789 doggie aeiou aeiou "; + httpRequest = ((HttpRequestWithBody) httpRequest).body(requestBody).getHttpRequest(); + + + HttpResponse httpResponse = httpRequest.asString(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } +} \ No newline at end of file diff --git a/samples/server/petstore/java-camel/src/test/java/org/openapitools/api/StoreApiTest.java b/samples/server/petstore/java-camel/src/test/java/org/openapitools/api/StoreApiTest.java new file mode 100644 index 000000000000..f2d137065b79 --- /dev/null +++ b/samples/server/petstore/java-camel/src/test/java/org/openapitools/api/StoreApiTest.java @@ -0,0 +1,84 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.junit.jupiter.api.Test; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.springframework.boot.test.context.SpringBootTest; +import com.mashape.unirest.request.HttpRequest; +import com.mashape.unirest.request.HttpRequestWithBody; +import com.mashape.unirest.http.Unirest; +import com.mashape.unirest.http.JsonNode; +import com.mashape.unirest.http.HttpResponse; +import java.io.InputStream; +import org.junit.jupiter.api.Assertions; + +@CamelSpringBootTest +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class StoreApiTest { + private static final String API_URL = "http://127.0.0.1:8080/api/v1"; + + @Test + public void getOrderByIdTestJson() throws Exception { + String contentType = "application/json"; + String accept = "application/json"; + String url = API_URL + "/store/order/{orderId}"; + HttpRequest httpRequest = Unirest.get(url); + httpRequest = httpRequest.header("Accept", accept); + httpRequest = httpRequest.routeParam("orderId", "1"); + + + HttpResponse httpResponse = httpRequest.asJson(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + + @Test + public void getOrderByIdTestXml() throws Exception { + String contentType = "application/xml"; + String accept = "application/xml"; + String url = API_URL + "/store/order/{orderId}"; + HttpRequest httpRequest = Unirest.get(url); + httpRequest = httpRequest.header("Accept", accept); + httpRequest = httpRequest.routeParam("orderId", "1"); + + + HttpResponse httpResponse = httpRequest.asString(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + @Test + public void placeOrderTestJson() throws Exception { + String contentType = "application/json"; + String accept = "application/json"; + String url = API_URL + "/store/order"; + HttpRequest httpRequest = Unirest.post(url); + httpRequest = httpRequest.header("Content-Type", contentType); + httpRequest = httpRequest.header("Accept", accept); + + String requestBody = "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\" }"; + httpRequest = ((HttpRequestWithBody) httpRequest).body(requestBody).getHttpRequest(); + + + HttpResponse httpResponse = httpRequest.asJson(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + + @Test + public void placeOrderTestXml() throws Exception { + String contentType = "application/xml"; + String accept = "application/xml"; + String url = API_URL + "/store/order"; + HttpRequest httpRequest = Unirest.post(url); + httpRequest = httpRequest.header("Content-Type", contentType); + httpRequest = httpRequest.header("Accept", accept); + + String requestBody = " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true "; + httpRequest = ((HttpRequestWithBody) httpRequest).body(requestBody).getHttpRequest(); + + + HttpResponse httpResponse = httpRequest.asString(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } +} \ No newline at end of file diff --git a/samples/server/petstore/java-camel/src/test/java/org/openapitools/api/UserApiTest.java b/samples/server/petstore/java-camel/src/test/java/org/openapitools/api/UserApiTest.java new file mode 100644 index 000000000000..c278b12de3b1 --- /dev/null +++ b/samples/server/petstore/java-camel/src/test/java/org/openapitools/api/UserApiTest.java @@ -0,0 +1,51 @@ +/** +* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.4.0-SNAPSHOT). +* https://openapi-generator.tech +* Do not edit the class manually. +*/ +package org.openapitools.api; + +import org.junit.jupiter.api.Test; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.springframework.boot.test.context.SpringBootTest; +import com.mashape.unirest.request.HttpRequest; +import com.mashape.unirest.request.HttpRequestWithBody; +import com.mashape.unirest.http.Unirest; +import com.mashape.unirest.http.JsonNode; +import com.mashape.unirest.http.HttpResponse; +import java.io.InputStream; +import org.junit.jupiter.api.Assertions; + +@CamelSpringBootTest +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class UserApiTest { + private static final String API_URL = "http://127.0.0.1:8080/api/v1"; + + @Test + public void getUserByNameTestJson() throws Exception { + String contentType = "application/json"; + String accept = "application/json"; + String url = API_URL + "/user/{username}"; + HttpRequest httpRequest = Unirest.get(url); + httpRequest = httpRequest.header("Accept", accept); + httpRequest = httpRequest.routeParam("username", "1"); + + + HttpResponse httpResponse = httpRequest.asJson(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } + + @Test + public void getUserByNameTestXml() throws Exception { + String contentType = "application/xml"; + String accept = "application/xml"; + String url = API_URL + "/user/{username}"; + HttpRequest httpRequest = Unirest.get(url); + httpRequest = httpRequest.header("Accept", accept); + httpRequest = httpRequest.routeParam("username", "1"); + + + HttpResponse httpResponse = httpRequest.asString(); + Assertions.assertTrue(httpResponse.getStatus() < 400 || httpResponse.getStatus() == 415); + } +} \ No newline at end of file