diff --git a/bin/configs/other/java-undertow-server-java-undertow.yaml b/bin/configs/java-undertow-server-java-undertow.yaml similarity index 100% rename from bin/configs/other/java-undertow-server-java-undertow.yaml rename to bin/configs/java-undertow-server-java-undertow.yaml diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaUndertowServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaUndertowServerCodegen.java index 384d14d4ca1..92e5d2e1bea 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaUndertowServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaUndertowServerCodegen.java @@ -106,6 +106,7 @@ public class JavaUndertowServerCodegen extends AbstractJavaCodegen { // keep the yaml in config folder for framework validation. supportingFiles.add(new SupportingFile("openapi.mustache", ("src.main.resources.config").replace(".", java.io.File.separator), "openapi.json")); + supportingFiles.add(new SupportingFile("interface.mustache", (String.format(Locale.ROOT, "src.main.java.%s", apiPackage)).replace(".", java.io.File.separator), "PathHandlerInterface.java")); supportingFiles.add(new SupportingFile("handler.mustache", (String.format(Locale.ROOT, "src.main.java.%s", apiPackage)).replace(".", java.io.File.separator), "PathHandlerProvider.java")); supportingFiles.add(new SupportingFile("service.mustache", ("src.main.resources.META-INF.services").replace(".", java.io.File.separator), "com.networknt.server.HandlerProvider")); diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/README.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/README.mustache index a983dba343c..f452d35095a 100644 --- a/modules/openapi-generator/src/main/resources/java-undertow-server/README.mustache +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/README.mustache @@ -10,15 +10,13 @@ mvn package exec:exec ## Test -By default, all endpoints are protected by OAuth jwt token verifier. It can be turned off with config change through for development. - +By default, all endpoints are protected by the OAuth JWT token verifier. It can be turned off with a config change, when required. In order to access the server, there is a long lived token below issued by my -oauth2 server [undertow-server-oauth2](https://github.com/networknt/undertow-server-oauth2) +OAuth2 server [undertow-server-oauth2](https://github.com/networknt/undertow-server-oauth2). ``` Bearer eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ1cm46Y29tOm5ldHdvcmtudDpvYXV0aDI6djEiLCJhdWQiOiJ1cm46Y29tLm5ldHdvcmtudCIsImV4cCI6MTc4ODEzMjczNSwianRpIjoiNWtyM2ZWOHJaelBZNEJrSnNYZzFpQSIsImlhdCI6MTQ3Mjc3MjczNSwibmJmIjoxNDcyNzcyNjE1LCJ2ZXJzaW9uIjoiMS4wIiwidXNlcl9pZCI6InN0ZXZlIiwidXNlcl90eXBlIjoiRU1QTE9ZRUUiLCJjbGllbnRfaWQiOiJkZGNhZjBiYS0xMTMxLTIyMzItMzMxMy1kNmYyNzUzZjI1ZGMiLCJzY29wZSI6WyJhcGkuciIsImFwaS53Il19.gteJiy1uao8HLeWRljpZxHWUgQfofwmnFP-zv3EPUyXjyCOy3xclnfeTnTE39j8PgBwdFASPcDLLk1YfZJbsU6pLlmYXLtdpHDBsVmIRuch6LFPCVQ3JdqSQVci59OhSK0bBThGWqCD3UzDI_OnX4IVCAahcT9Bu94m5u_H_JNmwDf1XaP3Lt4I34buYMuRD9stchsnZi-tuIRkL13FARm1XA9aPZUMUXFdedBWDXo1zMREQ_qCJXOpaZDJM9Im0rIkq9wTEVU00pbRp_Vcdya3dfkFteBMHiwFVt6VNQaco5BXURDAIzXidwQxNEbX1ek03wra8AIani65ZK7fy_w ``` Add "Authorization" header with value as above token and a dummy message will return from the generated stub. - diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/bodyParams.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/bodyParams.mustache index c7d1abfe527..cf3f9c3add9 100644 --- a/modules/openapi-generator/src/main/resources/java-undertow-server/bodyParams.mustache +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/bodyParams.mustache @@ -1 +1 @@ -{{#isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}} \ No newline at end of file +{{#isBodyParam}}{{{dataType}}} {{{paramName}}}{{/isBodyParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/enumOuterClass.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/enumOuterClass.mustache index 5333fff8c06..f2805b0f72a 100644 --- a/modules/openapi-generator/src/main/resources/java-undertow-server/enumOuterClass.mustache +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/enumOuterClass.mustache @@ -3,8 +3,8 @@ {{/jackson}} /** -* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}} -*/ + * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}} + */ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { {{#gson}} {{#allowableValues}}{{#enumVars}} diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/generatedAnnotation.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/generatedAnnotation.mustache index 875d7b97afe..10843695a9a 100644 --- a/modules/openapi-generator/src/main/resources/java-undertow-server/generatedAnnotation.mustache +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/generatedAnnotation.mustache @@ -1 +1 @@ -@javax.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}}) \ No newline at end of file +@javax.annotation.Generated(value = "{{{generatorClass}}}"{{^hideGenerationTimestamp}}, date = "{{{generatedDate}}}"{{/hideGenerationTimestamp}}) \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/handler.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/handler.mustache index 4cb411f79d6..acf876b7975 100644 --- a/modules/openapi-generator/src/main/resources/java-undertow-server/handler.mustache +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/handler.mustache @@ -1,34 +1,161 @@ +{{>licenseInfo}} package org.openapitools.handler; -import com.networknt.config.Config; import com.networknt.server.HandlerProvider; import io.undertow.Handlers; import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; +import io.undertow.server.RoutingHandler; +import io.undertow.server.handlers.PathHandler; import io.undertow.util.Methods; -public class PathHandlerProvider implements HandlerProvider { +/** + * The default implementation for {@link HandlerProvider} and {@link PathHandlerInterface}. + * + *

There are two flavors of {@link HttpHandler}s to choose from, depending on your needs:

+ * + * + *

Note: Stateful flavor is more performant than Stateless.

+ */ +@SuppressWarnings("TooManyFunctions") +abstract public class PathHandlerProvider implements HandlerProvider, PathHandlerInterface { + /** + * Returns the default base path to access this server. + */ + @javax.annotation.Nonnull + public String getBasePath() { + return "{{{basePathWithoutHost}}}"; + } + /** + * Returns a stateless {@link HttpHandler} that configures all endpoints in this server. + * + *

Endpoints bound in this method do NOT start with "{{{basePathWithoutHost}}}", and + * it's your responsibility to configure a {@link PathHandler} with a prefix path + * by calling {@link PathHandler#addPrefixPath} like so:

+ * + * pathHandler.addPrefixPath("{{{basePathWithoutHost}}}", handler) + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateless and won't + * retain any state between multiple sessions.

+ * + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @javax.annotation.Nonnull + @Override public HttpHandler getHandler() { - HttpHandler handler = Handlers.routing() + return getHandler(false); + } + /** + * Returns a stateless {@link HttpHandler} that configures all endpoints in this server. + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateless and won't + * retain any state between multiple sessions.

+ * + * @param withBasePath if true, all endpoints would start with "{{{basePathWithoutHost}}}" + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @javax.annotation.Nonnull + public HttpHandler getHandler(final boolean withBasePath) { + return getHandler(withBasePath ? getBasePath() : ""); + } + + /** + * Returns a stateless {@link HttpHandler} that configures all endpoints in this server. + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateless and won't + * retain any state between multiple sessions.

+ * + * @param basePath base path to set for all endpoints + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @SuppressWarnings("Convert2Lambda") + @javax.annotation.Nonnull + public HttpHandler getHandler(final String basePath) { + return Handlers.routing() {{#apiInfo}} -{{#apis}} -{{#operations}} -{{#operation}} - - .add(Methods.{{httpMethod}}, "{{{basePathWithoutHost}}}{{{path}}}", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("{{operationId}}"); - } - }) - -{{/operation}} -{{/operations}} -{{/apis}} + {{#apis}} + {{#operations}} + {{#operation}} + .add(Methods.{{{httpMethod}}}, basePath + "{{{path}}}", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + {{{operationId}}}().handleRequest(exchange); + } + }) + {{/operation}} + {{/operations}} + {{/apis}} + ; +{{/apiInfo}} + } + + /** + * Returns a stateful {@link HttpHandler} that configures all endpoints in this server. + * + *

Endpoints bound in this method do NOT start with "{{{basePathWithoutHost}}}", and + * it's your responsibility to configure a {@link PathHandler} with a prefix path + * by calling {@link PathHandler#addPrefixPath} like so:

+ * + * pathHandler.addPrefixPath("{{{basePathWithoutHost}}}", handler) + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateful and will + * retain any state between multiple sessions.

+ * + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @javax.annotation.Nonnull + public HttpHandler getStatefulHandler() { + return getStatefulHandler(false); + } + + /** + * Returns a stateful {@link HttpHandler} that configures all endpoints in this server. + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateful and will + * retain any state between multiple sessions.

+ * + * @param withBasePath if true, all endpoints would start with "{{{basePathWithoutHost}}}" + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @javax.annotation.Nonnull + public HttpHandler getStatefulHandler(final boolean withBasePath) { + return getStatefulHandler(withBasePath ? getBasePath() : ""); + } + + /** + * Returns a stateful {@link HttpHandler} that configures all endpoints in this server. + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateful and will + * retain any state between multiple sessions.

+ * + * @param basePath base path to set for all endpoints + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @javax.annotation.Nonnull + public HttpHandler getStatefulHandler(final String basePath) { + return Handlers.routing() +{{#apiInfo}} + {{#apis}} + {{#operations}} + {{#operation}} + .add(Methods.{{{httpMethod}}}, basePath + "{{{path}}}", {{{operationId}}}()) + {{/operation}} + {{/operations}} + {{/apis}} + ; {{/apiInfo}} - ; - return handler; } } - diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/inflector.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/inflector.mustache index 87fc5581316..c4b62bbd8a9 100644 --- a/modules/openapi-generator/src/main/resources/java-undertow-server/inflector.mustache +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/inflector.mustache @@ -1,10 +1,10 @@ -controllerPackage: {{invokerPackage}} -modelPackage: {{modelPackage}} +controllerPackage: {{{invokerPackage}}} +modelPackage: {{{modelPackage}}} swaggerUrl: ./src/main/swagger/swagger.yaml modelMappings: # to enable explicit mappings, use this syntax: DefinitionFromSwaggerSpecification: fully.qualified.path.to.Model - {{#models}}{{#model}}{{classname}} : {{modelPackage}}.{{classname}}{{/model}} + {{#models}}{{#model}}{{{classname}}} : {{{modelPackage}}}.{{{classname}}}{{/model}} {{/models}} entityProcessors: diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/interface.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/interface.mustache new file mode 100644 index 00000000000..7dfd94228a8 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/interface.mustache @@ -0,0 +1,76 @@ +{{>licenseInfo}} +package org.openapitools.handler; + +import io.undertow.server.*; +import io.undertow.util.*; + +import {{modelPackage}}.*; + +@SuppressWarnings("TooManyFunctions") +public interface PathHandlerInterface { +{{#apiInfo}} + {{#apis}} + {{#operations}} + {{#operation}} + + /** +{{#summary}} *

{{{summary}}}

+ * +{{/summary}} +{{#notes}} *

{{{notes}}}

+ * +{{/notes}} + *

Endpoint: {@link Methods#{{{httpMethod}}} {{{httpMethod}}}} "{{{basePathWithoutHost}}}{{{path}}}" (privileged: {{{hasAuthMethods}}})

+{{#hasParams}} + * + *

Request parameters:

+ * +{{/hasParams}} +{{#hasResponseHeaders}} + *

Response headers: [{{#responseHeaders}}{{{.}}}{{^-last}}, {{/-last}}{{/responseHeaders}}]

+{{/hasResponseHeaders}} +{{#hasConsumes}} + * + *

Consumes: {{{consumes}}}

+{{#hasBodyParam}}{{#bodyParam}} *

Payload: {{>isContainerDoc}}{{#isModel}}{@link {{{dataType}}}}{{/isModel}}{{^isModel}}{{#isFile}}{{#isBinary}}Binary {{/isBinary}}File{{/isFile}}{{^isFile}}{@link {{baseType}}}{{/isFile}}{{/isModel}} (required: {{{required}}}{{/bodyParam}})

+{{/hasBodyParam}} +{{/hasConsumes}} + * +{{#hasProduces}} *

Produces: {{{produces}}}

+{{/hasProduces}} +{{#returnBaseType}} *

Returns: {{>isContainerDoc}}{@link {{{returnBaseType}}}}

+{{/returnBaseType}} + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull +{{#isDeprecated}} @Deprecated +{{/isDeprecated}} + HttpHandler {{{operationId}}}(); + {{/operation}} + {{/operations}} + {{/apis}} +{{/apiInfo}} +} diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/isContainerDoc.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/isContainerDoc.mustache new file mode 100644 index 00000000000..d219fde2cc3 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/isContainerDoc.mustache @@ -0,0 +1 @@ +{{#isArray}}{@link java.util.List List} of {{/isArray}}{{#isMap}}{@link java.util.Map Map} of {{/isMap}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/licenseInfo.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/licenseInfo.mustache new file mode 100644 index 00000000000..09f65c73d83 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/licenseInfo.mustache @@ -0,0 +1,10 @@ +/* + * {{{appName}}} + * + * {{{appDescription}}} + * + * {{#version}}OpenAPI document version: {{{version}}}{{/version}} + * {{#infoEmail}}Maintained by: {{{infoEmail}}}{{/infoEmail}} + * + * AUTO-GENERATED FILE, DO NOT MODIFY! + */ \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/model.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/model.mustache index b9512d2b83c..addae4dd4d4 100644 --- a/modules/openapi-generator/src/main/resources/java-undertow-server/model.mustache +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/model.mustache @@ -1,15 +1,16 @@ +{{>licenseInfo}} package {{package}}; import java.util.Objects; -{{#imports}}import {{import}}; +{{#imports}}import {{{import}}}; {{/imports}} {{#serializableModel}}import java.io.Serializable;{{/serializableModel}} {{#models}} {{#model}}{{#description}} /** - * {{description}} - **/{{/description}} + * {{{description}}} + */{{/description}} {{#isEnum}}{{>enumOuterClass}}{{/isEnum}} {{^isEnum}}{{>pojo}}{{/isEnum}} {{/model}} diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/pathParams.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/pathParams.mustache index 6829cf8c7a6..e31bf798d10 100644 --- a/modules/openapi-generator/src/main/resources/java-undertow-server/pathParams.mustache +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/pathParams.mustache @@ -1 +1 @@ -{{#isPathParam}}{{{dataType}}} {{paramName}}{{/isPathParam}} \ No newline at end of file +{{#isPathParam}}{{{dataType}}} {{{paramName}}}{{/isPathParam}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/pojo.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/pojo.mustache index 03c38d0ed77..f40d5b3de4a 100644 --- a/modules/openapi-generator/src/main/resources/java-undertow-server/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/pojo.mustache @@ -4,23 +4,23 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali {{#vars}}{{#isEnum}}{{^isContainer}} {{>enumClass}}{{/isContainer}}{{#isContainer}}{{#mostInnerItems}} - + {{>enumClass}}{{/mostInnerItems}}{{/isContainer}}{{/isEnum}} - private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};{{/vars}} + private {{{datatypeWithEnum}}} {{{name}}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};{{/vars}} {{#vars}} /**{{#description}} * {{{description}}}{{/description}}{{#minimum}} - * minimum: {{minimum}}{{/minimum}}{{#maximum}} - * maximum: {{maximum}}{{/maximum}} - **/ - public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) { - this.{{name}} = {{name}}; + * minimum: {{{minimum}}}{{/minimum}}{{#maximum}} + * maximum: {{{maximum}}}{{/maximum}} + */ + public {{{classname}}} {{{name}}}({{{datatypeWithEnum}}} {{{name}}}) { + this.{{{name}}} = {{{name}}}; return this; } {{#vendorExtensions.x-extra-annotation}}{{{vendorExtensions.x-extra-annotation}}}{{/vendorExtensions.x-extra-annotation}} - @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") + @ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{{required}}}, {{/required}}value = "{{{description}}}") @JsonProperty("{{baseName}}") public {{{datatypeWithEnum}}} {{getter}}() { return {{name}}; @@ -39,23 +39,23 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali if (o == null || getClass() != o.getClass()) { return false; } - {{classname}} {{classVarName}} = ({{classname}}) o;{{#hasVars}} - return {{#vars}}Objects.equals({{name}}, {{classVarName}}.{{name}}){{^-last}} && + {{{classname}}} {{{classVarName}}} = ({{{classname}}}) o;{{#hasVars}} + return {{#vars}}Objects.equals({{{name}}}, {{{classVarName}}}.{{{name}}}){{^-last}} && {{/-last}}{{#-last}};{{/-last}}{{/vars}}{{/hasVars}}{{^hasVars}} return true;{{/hasVars}} } @Override public int hashCode() { - return Objects.hash({{#vars}}{{name}}{{^-last}}, {{/-last}}{{/vars}}); + return Objects.hash({{#vars}}{{{name}}}{{^-last}}, {{/-last}}{{/vars}}); } @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class {{classname}} {\n"); + sb.append("class {{{classname}}} {\n"); {{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}} - {{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n"); + {{#vars}}sb.append(" {{{name}}}: ").append(toIndentedString({{{name}}})).append("\n"); {{/vars}}sb.append("}"); return sb.toString(); } diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/pom.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/pom.mustache index 3a63b72d59d..12ee539f8a3 100644 --- a/modules/openapi-generator/src/main/resources/java-undertow-server/pom.mustache +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/pom.mustache @@ -6,11 +6,11 @@ 5 4.0.0 - {{groupId}} - {{artifactId}} + {{{groupId}}} + {{{artifactId}}} jar - {{artifactId}} - {{artifactVersion}} + {{{artifactId}}} + {{{artifactVersion}}} 1.8 diff --git a/modules/openapi-generator/src/main/resources/java-undertow-server/queryParams.mustache b/modules/openapi-generator/src/main/resources/java-undertow-server/queryParams.mustache index ff79730471d..711bb3cf918 100644 --- a/modules/openapi-generator/src/main/resources/java-undertow-server/queryParams.mustache +++ b/modules/openapi-generator/src/main/resources/java-undertow-server/queryParams.mustache @@ -1 +1 @@ -{{#isQueryParam}}{{{dataType}}} {{paramName}}{{/isQueryParam}} \ No newline at end of file +{{#isQueryParam}}{{{dataType}}} {{{paramName}}}{{/isQueryParam}} \ No newline at end of file diff --git a/samples/server/petstore/java-undertow/.openapi-generator/FILES b/samples/server/petstore/java-undertow/.openapi-generator/FILES index 8857fbfab67..780862a8b8f 100644 --- a/samples/server/petstore/java-undertow/.openapi-generator/FILES +++ b/samples/server/petstore/java-undertow/.openapi-generator/FILES @@ -1,5 +1,6 @@ README.md pom.xml +src/main/java/org/openapitools/handler/PathHandlerInterface.java src/main/java/org/openapitools/handler/PathHandlerProvider.java src/main/java/org/openapitools/model/Category.java src/main/java/org/openapitools/model/ModelApiResponse.java diff --git a/samples/server/petstore/java-undertow/.openapi-generator/VERSION b/samples/server/petstore/java-undertow/.openapi-generator/VERSION index d99e7162d01..3fa3b389a57 100644 --- a/samples/server/petstore/java-undertow/.openapi-generator/VERSION +++ b/samples/server/petstore/java-undertow/.openapi-generator/VERSION @@ -1 +1 @@ -5.0.0-SNAPSHOT \ No newline at end of file +5.0.1-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/java-undertow/README.md b/samples/server/petstore/java-undertow/README.md index a983dba343c..f452d35095a 100644 --- a/samples/server/petstore/java-undertow/README.md +++ b/samples/server/petstore/java-undertow/README.md @@ -10,15 +10,13 @@ mvn package exec:exec ## Test -By default, all endpoints are protected by OAuth jwt token verifier. It can be turned off with config change through for development. - +By default, all endpoints are protected by the OAuth JWT token verifier. It can be turned off with a config change, when required. In order to access the server, there is a long lived token below issued by my -oauth2 server [undertow-server-oauth2](https://github.com/networknt/undertow-server-oauth2) +OAuth2 server [undertow-server-oauth2](https://github.com/networknt/undertow-server-oauth2). ``` Bearer eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ1cm46Y29tOm5ldHdvcmtudDpvYXV0aDI6djEiLCJhdWQiOiJ1cm46Y29tLm5ldHdvcmtudCIsImV4cCI6MTc4ODEzMjczNSwianRpIjoiNWtyM2ZWOHJaelBZNEJrSnNYZzFpQSIsImlhdCI6MTQ3Mjc3MjczNSwibmJmIjoxNDcyNzcyNjE1LCJ2ZXJzaW9uIjoiMS4wIiwidXNlcl9pZCI6InN0ZXZlIiwidXNlcl90eXBlIjoiRU1QTE9ZRUUiLCJjbGllbnRfaWQiOiJkZGNhZjBiYS0xMTMxLTIyMzItMzMxMy1kNmYyNzUzZjI1ZGMiLCJzY29wZSI6WyJhcGkuciIsImFwaS53Il19.gteJiy1uao8HLeWRljpZxHWUgQfofwmnFP-zv3EPUyXjyCOy3xclnfeTnTE39j8PgBwdFASPcDLLk1YfZJbsU6pLlmYXLtdpHDBsVmIRuch6LFPCVQ3JdqSQVci59OhSK0bBThGWqCD3UzDI_OnX4IVCAahcT9Bu94m5u_H_JNmwDf1XaP3Lt4I34buYMuRD9stchsnZi-tuIRkL13FARm1XA9aPZUMUXFdedBWDXo1zMREQ_qCJXOpaZDJM9Im0rIkq9wTEVU00pbRp_Vcdya3dfkFteBMHiwFVt6VNQaco5BXURDAIzXidwQxNEbX1ek03wra8AIani65ZK7fy_w ``` Add "Authorization" header with value as above token and a dummy message will return from the generated stub. - diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java new file mode 100644 index 00000000000..5733e1ee0b0 --- /dev/null +++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerInterface.java @@ -0,0 +1,604 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI document version: 1.0.0 + * + * + * AUTO-GENERATED FILE, DO NOT MODIFY! + */ +package org.openapitools.handler; + +import io.undertow.server.*; +import io.undertow.util.*; + +import org.openapitools.model.*; + +@SuppressWarnings("TooManyFunctions") +public interface PathHandlerInterface { + + /** + *

Add a new pet to the store

+ * + *

Endpoint: {@link Methods#POST POST} "/v2/pet" (privileged: true)

+ * + *

Request parameters:

+ * + * + *

Consumes: [{mediaType=application/json}, {mediaType=application/xml}]

+ *

Payload: {@link Pet} (required: true)

+ * + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler addPet(); + + /** + *

Deletes a pet

+ * + *

Endpoint: {@link Methods#DELETE DELETE} "/v2/pet/{petId}" (privileged: true)

+ * + *

Request parameters:

+ * + * + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler deletePet(); + + /** + *

Finds Pets by status

+ * + *

Multiple status values can be provided with comma separated strings

+ * + *

Endpoint: {@link Methods#GET GET} "/v2/pet/findByStatus" (privileged: true)

+ * + *

Request parameters:

+ * + * + *

Produces: [{mediaType=application/xml}, {mediaType=application/json}]

+ *

Returns: {@link java.util.List List} of {@link Pet}

+ * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler findPetsByStatus(); + + /** + *

Finds Pets by tags

+ * + *

Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.

+ * + *

Endpoint: {@link Methods#GET GET} "/v2/pet/findByTags" (privileged: true)

+ * + *

Request parameters:

+ * + * + *

Produces: [{mediaType=application/xml}, {mediaType=application/json}]

+ *

Returns: {@link java.util.List List} of {@link Pet}

+ * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + @Deprecated + HttpHandler findPetsByTags(); + + /** + *

Find pet by ID

+ * + *

Returns a single pet

+ * + *

Endpoint: {@link Methods#GET GET} "/v2/pet/{petId}" (privileged: true)

+ * + *

Request parameters:

+ * + * + *

Produces: [{mediaType=application/xml}, {mediaType=application/json}]

+ *

Returns: {@link Pet}

+ * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler getPetById(); + + /** + *

Update an existing pet

+ * + *

Endpoint: {@link Methods#PUT PUT} "/v2/pet" (privileged: true)

+ * + *

Request parameters:

+ * + * + *

Consumes: [{mediaType=application/json}, {mediaType=application/xml}]

+ *

Payload: {@link Pet} (required: true)

+ * + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler updatePet(); + + /** + *

Updates a pet in the store with form data

+ * + *

Endpoint: {@link Methods#POST POST} "/v2/pet/{petId}" (privileged: true)

+ * + *

Request parameters:

+ * + * + *

Consumes: [{mediaType=application/x-www-form-urlencoded}]

+ * + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler updatePetWithForm(); + + /** + *

uploads an image

+ * + *

Endpoint: {@link Methods#POST POST} "/v2/pet/{petId}/uploadImage" (privileged: true)

+ * + *

Request parameters:

+ * + * + *

Consumes: [{mediaType=multipart/form-data}]

+ * + *

Produces: [{mediaType=application/json}]

+ *

Returns: {@link ModelApiResponse}

+ * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler uploadFile(); + + /** + *

Delete purchase order by ID

+ * + *

For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors

+ * + *

Endpoint: {@link Methods#DELETE DELETE} "/v2/store/order/{orderId}" (privileged: false)

+ * + *

Request parameters:

+ * + * + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler deleteOrder(); + + /** + *

Returns pet inventories by status

+ * + *

Returns a map of status codes to quantities

+ * + *

Endpoint: {@link Methods#GET GET} "/v2/store/inventory" (privileged: true)

+ * + *

Produces: [{mediaType=application/json}]

+ *

Returns: {@link java.util.Map Map} of {@link Integer}

+ * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler getInventory(); + + /** + *

Find purchase order by ID

+ * + *

For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions

+ * + *

Endpoint: {@link Methods#GET GET} "/v2/store/order/{orderId}" (privileged: false)

+ * + *

Request parameters:

+ * + * + *

Produces: [{mediaType=application/xml}, {mediaType=application/json}]

+ *

Returns: {@link Order}

+ * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler getOrderById(); + + /** + *

Place an order for a pet

+ * + *

Endpoint: {@link Methods#POST POST} "/v2/store/order" (privileged: false)

+ * + *

Request parameters:

+ * + * + *

Produces: [{mediaType=application/xml}, {mediaType=application/json}]

+ *

Returns: {@link Order}

+ * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler placeOrder(); + + /** + *

Create user

+ * + *

This can only be done by the logged in user.

+ * + *

Endpoint: {@link Methods#POST POST} "/v2/user" (privileged: false)

+ * + *

Request parameters:

+ * + * + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler createUser(); + + /** + *

Creates list of users with given input array

+ * + *

Endpoint: {@link Methods#POST POST} "/v2/user/createWithArray" (privileged: false)

+ * + *

Request parameters:

+ * + * + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler createUsersWithArrayInput(); + + /** + *

Creates list of users with given input array

+ * + *

Endpoint: {@link Methods#POST POST} "/v2/user/createWithList" (privileged: false)

+ * + *

Request parameters:

+ * + * + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler createUsersWithListInput(); + + /** + *

Delete user

+ * + *

This can only be done by the logged in user.

+ * + *

Endpoint: {@link Methods#DELETE DELETE} "/v2/user/{username}" (privileged: false)

+ * + *

Request parameters:

+ * + * + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler deleteUser(); + + /** + *

Get user by user name

+ * + *

Endpoint: {@link Methods#GET GET} "/v2/user/{username}" (privileged: false)

+ * + *

Request parameters:

+ * + * + *

Produces: [{mediaType=application/xml}, {mediaType=application/json}]

+ *

Returns: {@link User}

+ * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler getUserByName(); + + /** + *

Logs user into the system

+ * + *

Endpoint: {@link Methods#GET GET} "/v2/user/login" (privileged: false)

+ * + *

Request parameters:

+ * + *

Response headers: [CodegenProperty{openApiType='integer', baseName='X-Rate-Limit', complexType='null', getter='getxRateLimit', setter='setxRateLimit', description='calls per hour allowed by the user', dataType='Integer', datatypeWithEnum='Integer', dataFormat='int32', name='xRateLimit', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Rate-Limit;', baseType='Integer', containerType='null', title='null', unescapedDescription='calls per hour allowed by the user', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ + "type" : "integer", + "format" : "int32" +}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=true, isInteger=true, isLong=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='XRateLimit', nameInSnakeCase='X_RATE_LIMIT', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false}, CodegenProperty{openApiType='string', baseName='X-Expires-After', complexType='Date', getter='getxExpiresAfter', setter='setxExpiresAfter', description='date in UTC when toekn expires', dataType='Date', datatypeWithEnum='Date', dataFormat='date-time', name='xExpiresAfter', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.X-Expires-After;', baseType='Date', containerType='null', title='null', unescapedDescription='date in UTC when toekn expires', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ + "type" : "string", + "format" : "date-time" +}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=false, isModel=false, isContainer=false, isString=false, isNumeric=false, isInteger=false, isLong=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=true, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='XExpiresAfter', nameInSnakeCase='X_EXPIRES_AFTER', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false}]

+ * + *

Produces: [{mediaType=application/xml}, {mediaType=application/json}]

+ *

Returns: {@link String}

+ * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler loginUser(); + + /** + *

Logs out current logged in user session

+ * + *

Endpoint: {@link Methods#GET GET} "/v2/user/logout" (privileged: false)

+ * + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler logoutUser(); + + /** + *

Updated user

+ * + *

This can only be done by the logged in user.

+ * + *

Endpoint: {@link Methods#PUT PUT} "/v2/user/{username}" (privileged: false)

+ * + *

Request parameters:

+ * + * + * + *

Responses:

+ * + */ + @javax.annotation.Nonnull + HttpHandler updateUser(); +} diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerProvider.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerProvider.java index 2fc96fbbba3..0636e605513 100644 --- a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerProvider.java +++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/handler/PathHandlerProvider.java @@ -1,159 +1,287 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI document version: 1.0.0 + * + * + * AUTO-GENERATED FILE, DO NOT MODIFY! + */ package org.openapitools.handler; -import com.networknt.config.Config; import com.networknt.server.HandlerProvider; import io.undertow.Handlers; import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; +import io.undertow.server.RoutingHandler; +import io.undertow.server.handlers.PathHandler; import io.undertow.util.Methods; -public class PathHandlerProvider implements HandlerProvider { +/** + * The default implementation for {@link HandlerProvider} and {@link PathHandlerInterface}. + * + *

There are two flavors of {@link HttpHandler}s to choose from, depending on your needs:

+ * + * + *

Note: Stateful flavor is more performant than Stateless.

+ */ +@SuppressWarnings("TooManyFunctions") +abstract public class PathHandlerProvider implements HandlerProvider, PathHandlerInterface { + /** + * Returns the default base path to access this server. + */ + @javax.annotation.Nonnull + public String getBasePath() { + return "/v2"; + } + /** + * Returns a stateless {@link HttpHandler} that configures all endpoints in this server. + * + *

Endpoints bound in this method do NOT start with "/v2", and + * it's your responsibility to configure a {@link PathHandler} with a prefix path + * by calling {@link PathHandler#addPrefixPath} like so:

+ * + * pathHandler.addPrefixPath("/v2", handler) + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateless and won't + * retain any state between multiple sessions.

+ * + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @javax.annotation.Nonnull + @Override public HttpHandler getHandler() { - HttpHandler handler = Handlers.routing() + return getHandler(false); + } + /** + * Returns a stateless {@link HttpHandler} that configures all endpoints in this server. + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateless and won't + * retain any state between multiple sessions.

+ * + * @param withBasePath if true, all endpoints would start with "/v2" + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @javax.annotation.Nonnull + public HttpHandler getHandler(final boolean withBasePath) { + return getHandler(withBasePath ? getBasePath() : ""); + } - .add(Methods.POST, "/v2/pet", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("addPet"); - } - }) + /** + * Returns a stateless {@link HttpHandler} that configures all endpoints in this server. + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateless and won't + * retain any state between multiple sessions.

+ * + * @param basePath base path to set for all endpoints + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @SuppressWarnings("Convert2Lambda") + @javax.annotation.Nonnull + public HttpHandler getHandler(final String basePath) { + return Handlers.routing() + .add(Methods.POST, basePath + "/pet", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + addPet().handleRequest(exchange); + } + }) + .add(Methods.DELETE, basePath + "/pet/{petId}", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + deletePet().handleRequest(exchange); + } + }) + .add(Methods.GET, basePath + "/pet/findByStatus", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + findPetsByStatus().handleRequest(exchange); + } + }) + .add(Methods.GET, basePath + "/pet/findByTags", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + findPetsByTags().handleRequest(exchange); + } + }) + .add(Methods.GET, basePath + "/pet/{petId}", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + getPetById().handleRequest(exchange); + } + }) + .add(Methods.PUT, basePath + "/pet", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + updatePet().handleRequest(exchange); + } + }) + .add(Methods.POST, basePath + "/pet/{petId}", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + updatePetWithForm().handleRequest(exchange); + } + }) + .add(Methods.POST, basePath + "/pet/{petId}/uploadImage", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + uploadFile().handleRequest(exchange); + } + }) + .add(Methods.DELETE, basePath + "/store/order/{orderId}", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + deleteOrder().handleRequest(exchange); + } + }) + .add(Methods.GET, basePath + "/store/inventory", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + getInventory().handleRequest(exchange); + } + }) + .add(Methods.GET, basePath + "/store/order/{orderId}", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + getOrderById().handleRequest(exchange); + } + }) + .add(Methods.POST, basePath + "/store/order", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + placeOrder().handleRequest(exchange); + } + }) + .add(Methods.POST, basePath + "/user", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + createUser().handleRequest(exchange); + } + }) + .add(Methods.POST, basePath + "/user/createWithArray", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + createUsersWithArrayInput().handleRequest(exchange); + } + }) + .add(Methods.POST, basePath + "/user/createWithList", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + createUsersWithListInput().handleRequest(exchange); + } + }) + .add(Methods.DELETE, basePath + "/user/{username}", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + deleteUser().handleRequest(exchange); + } + }) + .add(Methods.GET, basePath + "/user/{username}", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + getUserByName().handleRequest(exchange); + } + }) + .add(Methods.GET, basePath + "/user/login", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + loginUser().handleRequest(exchange); + } + }) + .add(Methods.GET, basePath + "/user/logout", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + logoutUser().handleRequest(exchange); + } + }) + .add(Methods.PUT, basePath + "/user/{username}", new HttpHandler() { + @Override + public void handleRequest(HttpServerExchange exchange) throws Exception { + updateUser().handleRequest(exchange); + } + }) + ; + } + /** + * Returns a stateful {@link HttpHandler} that configures all endpoints in this server. + * + *

Endpoints bound in this method do NOT start with "/v2", and + * it's your responsibility to configure a {@link PathHandler} with a prefix path + * by calling {@link PathHandler#addPrefixPath} like so:

+ * + * pathHandler.addPrefixPath("/v2", handler) + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateful and will + * retain any state between multiple sessions.

+ * + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @javax.annotation.Nonnull + public HttpHandler getStatefulHandler() { + return getStatefulHandler(false); + } - .add(Methods.DELETE, "/v2/pet/{petId}", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("deletePet"); - } - }) + /** + * Returns a stateful {@link HttpHandler} that configures all endpoints in this server. + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateful and will + * retain any state between multiple sessions.

+ * + * @param withBasePath if true, all endpoints would start with "/v2" + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @javax.annotation.Nonnull + public HttpHandler getStatefulHandler(final boolean withBasePath) { + return getStatefulHandler(withBasePath ? getBasePath() : ""); + } - - .add(Methods.GET, "/v2/pet/findByStatus", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("findPetsByStatus"); - } - }) - - - .add(Methods.GET, "/v2/pet/findByTags", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("findPetsByTags"); - } - }) - - - .add(Methods.GET, "/v2/pet/{petId}", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("getPetById"); - } - }) - - - .add(Methods.PUT, "/v2/pet", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("updatePet"); - } - }) - - - .add(Methods.POST, "/v2/pet/{petId}", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("updatePetWithForm"); - } - }) - - - .add(Methods.POST, "/v2/pet/{petId}/uploadImage", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("uploadFile"); - } - }) - - - .add(Methods.DELETE, "/v2/store/order/{orderId}", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("deleteOrder"); - } - }) - - - .add(Methods.GET, "/v2/store/inventory", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("getInventory"); - } - }) - - - .add(Methods.GET, "/v2/store/order/{orderId}", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("getOrderById"); - } - }) - - - .add(Methods.POST, "/v2/store/order", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("placeOrder"); - } - }) - - - .add(Methods.POST, "/v2/user", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("createUser"); - } - }) - - - .add(Methods.POST, "/v2/user/createWithArray", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("createUsersWithArrayInput"); - } - }) - - - .add(Methods.POST, "/v2/user/createWithList", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("createUsersWithListInput"); - } - }) - - - .add(Methods.DELETE, "/v2/user/{username}", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("deleteUser"); - } - }) - - - .add(Methods.GET, "/v2/user/{username}", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("getUserByName"); - } - }) - - - .add(Methods.GET, "/v2/user/login", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("loginUser"); - } - }) - - - .add(Methods.GET, "/v2/user/logout", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("logoutUser"); - } - }) - - - .add(Methods.PUT, "/v2/user/{username}", new HttpHandler() { - public void handleRequest(HttpServerExchange exchange) throws Exception { - exchange.getResponseSender().send("updateUser"); - } - }) - - ; - return handler; + /** + * Returns a stateful {@link HttpHandler} that configures all endpoints in this server. + * + *

Note: the endpoints bound to the returned {@link HttpHandler} are stateful and will + * retain any state between multiple sessions.

+ * + * @param basePath base path to set for all endpoints + * @return an {@link HttpHandler} of type {@link RoutingHandler} + */ + @javax.annotation.Nonnull + public HttpHandler getStatefulHandler(final String basePath) { + return Handlers.routing() + .add(Methods.POST, basePath + "/pet", addPet()) + .add(Methods.DELETE, basePath + "/pet/{petId}", deletePet()) + .add(Methods.GET, basePath + "/pet/findByStatus", findPetsByStatus()) + .add(Methods.GET, basePath + "/pet/findByTags", findPetsByTags()) + .add(Methods.GET, basePath + "/pet/{petId}", getPetById()) + .add(Methods.PUT, basePath + "/pet", updatePet()) + .add(Methods.POST, basePath + "/pet/{petId}", updatePetWithForm()) + .add(Methods.POST, basePath + "/pet/{petId}/uploadImage", uploadFile()) + .add(Methods.DELETE, basePath + "/store/order/{orderId}", deleteOrder()) + .add(Methods.GET, basePath + "/store/inventory", getInventory()) + .add(Methods.GET, basePath + "/store/order/{orderId}", getOrderById()) + .add(Methods.POST, basePath + "/store/order", placeOrder()) + .add(Methods.POST, basePath + "/user", createUser()) + .add(Methods.POST, basePath + "/user/createWithArray", createUsersWithArrayInput()) + .add(Methods.POST, basePath + "/user/createWithList", createUsersWithListInput()) + .add(Methods.DELETE, basePath + "/user/{username}", deleteUser()) + .add(Methods.GET, basePath + "/user/{username}", getUserByName()) + .add(Methods.GET, basePath + "/user/login", loginUser()) + .add(Methods.GET, basePath + "/user/logout", logoutUser()) + .add(Methods.PUT, basePath + "/user/{username}", updateUser()) + ; } } - diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Category.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Category.java index bda35d2f045..4700938d352 100644 --- a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Category.java +++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Category.java @@ -1,3 +1,13 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI document version: 1.0.0 + * + * + * AUTO-GENERATED FILE, DO NOT MODIFY! + */ package org.openapitools.model; import java.util.Objects; @@ -10,7 +20,7 @@ import io.swagger.annotations.ApiModelProperty; /** * A category for a pet - **/ + */ @ApiModel(description = "A category for a pet") @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaUndertowServerCodegen") @@ -20,7 +30,7 @@ public class Category { private String name; /** - **/ + */ public Category id(Long id) { this.id = id; return this; @@ -37,7 +47,7 @@ public class Category { } /** - **/ + */ public Category name(String name) { this.name = name; return this; diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/ModelApiResponse.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/ModelApiResponse.java index 0d4cb3865cb..04568d59bb5 100644 --- a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/ModelApiResponse.java +++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/ModelApiResponse.java @@ -1,3 +1,13 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI document version: 1.0.0 + * + * + * AUTO-GENERATED FILE, DO NOT MODIFY! + */ package org.openapitools.model; import java.util.Objects; @@ -10,7 +20,7 @@ import io.swagger.annotations.ApiModelProperty; /** * Describes the result of uploading an image resource - **/ + */ @ApiModel(description = "Describes the result of uploading an image resource") @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaUndertowServerCodegen") @@ -21,7 +31,7 @@ public class ModelApiResponse { private String message; /** - **/ + */ public ModelApiResponse code(Integer code) { this.code = code; return this; @@ -38,7 +48,7 @@ public class ModelApiResponse { } /** - **/ + */ public ModelApiResponse type(String type) { this.type = type; return this; @@ -55,7 +65,7 @@ public class ModelApiResponse { } /** - **/ + */ public ModelApiResponse message(String message) { this.message = message; return this; diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Order.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Order.java index f057848f0cf..2f7209f8ef7 100644 --- a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Order.java +++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Order.java @@ -1,3 +1,13 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI document version: 1.0.0 + * + * + * AUTO-GENERATED FILE, DO NOT MODIFY! + */ package org.openapitools.model; import java.util.Objects; @@ -12,7 +22,7 @@ import java.util.Date; /** * An order for a pets from the pet store - **/ + */ @ApiModel(description = "An order for a pets from the pet store") @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaUndertowServerCodegen") @@ -46,7 +56,7 @@ public class Order { private Boolean complete = false; /** - **/ + */ public Order id(Long id) { this.id = id; return this; @@ -63,7 +73,7 @@ public class Order { } /** - **/ + */ public Order petId(Long petId) { this.petId = petId; return this; @@ -80,7 +90,7 @@ public class Order { } /** - **/ + */ public Order quantity(Integer quantity) { this.quantity = quantity; return this; @@ -97,7 +107,7 @@ public class Order { } /** - **/ + */ public Order shipDate(Date shipDate) { this.shipDate = shipDate; return this; @@ -115,7 +125,7 @@ public class Order { /** * Order Status - **/ + */ public Order status(StatusEnum status) { this.status = status; return this; @@ -132,7 +142,7 @@ public class Order { } /** - **/ + */ public Order complete(Boolean complete) { this.complete = complete; return this; diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Pet.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Pet.java index a80d291fc41..2837ebec20a 100644 --- a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Pet.java +++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Pet.java @@ -1,3 +1,13 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI document version: 1.0.0 + * + * + * AUTO-GENERATED FILE, DO NOT MODIFY! + */ package org.openapitools.model; import java.util.Objects; @@ -15,7 +25,7 @@ import org.openapitools.model.Tag; /** * A pet for sale in the pet store - **/ + */ @ApiModel(description = "A pet for sale in the pet store") @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaUndertowServerCodegen") @@ -49,7 +59,7 @@ public class Pet { private StatusEnum status; /** - **/ + */ public Pet id(Long id) { this.id = id; return this; @@ -66,7 +76,7 @@ public class Pet { } /** - **/ + */ public Pet category(Category category) { this.category = category; return this; @@ -83,7 +93,7 @@ public class Pet { } /** - **/ + */ public Pet name(String name) { this.name = name; return this; @@ -100,7 +110,7 @@ public class Pet { } /** - **/ + */ public Pet photoUrls(List photoUrls) { this.photoUrls = photoUrls; return this; @@ -117,7 +127,7 @@ public class Pet { } /** - **/ + */ public Pet tags(List tags) { this.tags = tags; return this; @@ -135,7 +145,7 @@ public class Pet { /** * pet status in the store - **/ + */ public Pet status(StatusEnum status) { this.status = status; return this; diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Tag.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Tag.java index a68f772854e..bab2a254cf2 100644 --- a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Tag.java +++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/Tag.java @@ -1,3 +1,13 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI document version: 1.0.0 + * + * + * AUTO-GENERATED FILE, DO NOT MODIFY! + */ package org.openapitools.model; import java.util.Objects; @@ -10,7 +20,7 @@ import io.swagger.annotations.ApiModelProperty; /** * A tag for a pet - **/ + */ @ApiModel(description = "A tag for a pet") @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaUndertowServerCodegen") @@ -20,7 +30,7 @@ public class Tag { private String name; /** - **/ + */ public Tag id(Long id) { this.id = id; return this; @@ -37,7 +47,7 @@ public class Tag { } /** - **/ + */ public Tag name(String name) { this.name = name; return this; diff --git a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/User.java b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/User.java index 7ef8b096a8f..2e66108f65d 100644 --- a/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/User.java +++ b/samples/server/petstore/java-undertow/src/main/java/org/openapitools/model/User.java @@ -1,3 +1,13 @@ +/* + * OpenAPI Petstore + * + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI document version: 1.0.0 + * + * + * AUTO-GENERATED FILE, DO NOT MODIFY! + */ package org.openapitools.model; import java.util.Objects; @@ -10,7 +20,7 @@ import io.swagger.annotations.ApiModelProperty; /** * A User who is purchasing from the pet store - **/ + */ @ApiModel(description = "A User who is purchasing from the pet store") @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaUndertowServerCodegen") @@ -26,7 +36,7 @@ public class User { private Integer userStatus; /** - **/ + */ public User id(Long id) { this.id = id; return this; @@ -43,7 +53,7 @@ public class User { } /** - **/ + */ public User username(String username) { this.username = username; return this; @@ -60,7 +70,7 @@ public class User { } /** - **/ + */ public User firstName(String firstName) { this.firstName = firstName; return this; @@ -77,7 +87,7 @@ public class User { } /** - **/ + */ public User lastName(String lastName) { this.lastName = lastName; return this; @@ -94,7 +104,7 @@ public class User { } /** - **/ + */ public User email(String email) { this.email = email; return this; @@ -111,7 +121,7 @@ public class User { } /** - **/ + */ public User password(String password) { this.password = password; return this; @@ -128,7 +138,7 @@ public class User { } /** - **/ + */ public User phone(String phone) { this.phone = phone; return this; @@ -146,7 +156,7 @@ public class User { /** * User Status - **/ + */ public User userStatus(Integer userStatus) { this.userStatus = userStatus; return this; diff --git a/samples/server/petstore/java-undertow/src/main/resources/config/openapi.json b/samples/server/petstore/java-undertow/src/main/resources/config/openapi.json index 1a863721712..e1554af7b8f 100644 --- a/samples/server/petstore/java-undertow/src/main/resources/config/openapi.json +++ b/samples/server/petstore/java-undertow/src/main/resources/config/openapi.json @@ -1037,5 +1037,6 @@ "type" : "apiKey" } } - } + }, + "x-original-swagger-version" : "2.0" } \ No newline at end of file