forked from loafle/openapi-generator-original
Merge pull request #13513 from tjquinno/helidon-generation
Add server and client generators for Helidon
This commit is contained in:
commit
e02ebd822a
38
.github/workflows/openapi-generator.yaml
vendored
38
.github/workflows/openapi-generator.yaml
vendored
@ -80,6 +80,44 @@ jobs:
|
||||
name: surefire-test-results
|
||||
path: '**/surefire-reports/TEST-*.xml'
|
||||
|
||||
functional-test:
|
||||
name: Functional tests
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- build
|
||||
strategy:
|
||||
matrix:
|
||||
java-version: [11, 17]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: ${{ matrix.java-version }}
|
||||
distribution: 'temurin'
|
||||
- name: Cache maven dependencies
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-maven-repository
|
||||
with:
|
||||
path: |
|
||||
~/.m2/repository
|
||||
~/.gradle
|
||||
!~/.gradle/caches/*/plugin-resolution/
|
||||
!~/.m2/repository/org/openapitools/
|
||||
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
- name: Run unit tests
|
||||
run: cd modules/openapi-generator && mvn --no-snapshot-updates --batch-mode -Dtest="**/functional/*Test" test -Dorg.slf4j.simpleLogger.defaultLogLevel=error
|
||||
- name: Publish unit test reports
|
||||
if: ${{ always() }}
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: surefire-test-results
|
||||
path: '**/surefire-reports/TEST-*.xml'
|
||||
|
||||
documentation:
|
||||
name: Docs up-to-date
|
||||
runs-on: ubuntu-latest
|
||||
|
12
.github/workflows/samples-jdk17.yaml
vendored
12
.github/workflows/samples-jdk17.yaml
vendored
@ -4,14 +4,22 @@ on:
|
||||
paths:
|
||||
# clients
|
||||
- samples/openapi3/client/petstore/spring-cloud-3/**
|
||||
- samples/client/petstore/java-helidon-client/mp/**
|
||||
- samples/client/petstore/java-helidon-client/se/**
|
||||
# servers
|
||||
- samples/openapi3/server/petstore/springboot-3/**
|
||||
- samples/server/petstore/java-helidon-server/mp/**
|
||||
- samples/server/petstore/java-helidon-server/se/**
|
||||
pull_request:
|
||||
paths:
|
||||
# clients
|
||||
- samples/openapi3/client/petstore/spring-cloud-3/**
|
||||
- samples/client/petstore/java-helidon-client/mp/**
|
||||
- samples/client/petstore/java-helidon-client/se/**
|
||||
# servers
|
||||
- samples/openapi3/server/petstore/springboot-3/**
|
||||
- samples/server/petstore/java-helidon-server/mp/**
|
||||
- samples/server/petstore/java-helidon-server/se/**
|
||||
jobs:
|
||||
build:
|
||||
name: Build with JDK17
|
||||
@ -22,8 +30,12 @@ jobs:
|
||||
sample:
|
||||
# clients
|
||||
- samples/openapi3/client/petstore/spring-cloud-3
|
||||
- samples/client/petstore/java-helidon-client/mp
|
||||
- samples/client/petstore/java-helidon-client/se
|
||||
# servers
|
||||
- samples/openapi3/server/petstore/springboot-3
|
||||
- samples/server/petstore/java-helidon-server/mp
|
||||
- samples/server/petstore/java-helidon-server/se
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v3
|
||||
|
13
bin/configs/java-helidon-client-mp.yaml
Normal file
13
bin/configs/java-helidon-client-mp.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
generatorName: java-helidon-client
|
||||
library: mp
|
||||
outputDir: samples/client/petstore/java-helidon-client/mp
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
additionalProperties:
|
||||
artifactId: petstore-helidon-client-mp
|
||||
hideGenerationTimestamp: "true"
|
||||
configureAuth: "false"
|
||||
build: "all"
|
||||
test: "spock"
|
||||
requiredPropertiesInConstructor: "false"
|
||||
visitable: "true"
|
||||
fullProject: "true"
|
13
bin/configs/java-helidon-client-se.yaml
Normal file
13
bin/configs/java-helidon-client-se.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
generatorName: java-helidon-client
|
||||
library: se
|
||||
outputDir: samples/client/petstore/java-helidon-client/se
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
additionalProperties:
|
||||
artifactId: petstore-helidon-client-se
|
||||
hideGenerationTimestamp: "true"
|
||||
configureAuth: "false"
|
||||
build: "all"
|
||||
test: "spock"
|
||||
requiredPropertiesInConstructor: "false"
|
||||
visitable: "true"
|
||||
fullProject: "true"
|
12
bin/configs/java-helidon-server-mp.yaml
Normal file
12
bin/configs/java-helidon-server-mp.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
generatorName: java-helidon-server
|
||||
library: mp
|
||||
outputDir: samples/server/petstore/java-helidon-server/mp
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/java-helidon/server
|
||||
additionalProperties:
|
||||
artifactId: petstore-helidon-server-mp
|
||||
hideGenerationTimestamp: "true"
|
||||
build: "all"
|
||||
test: "spock"
|
||||
useAuth: "false"
|
||||
fullProject: "true"
|
9
bin/configs/java-helidon-server-se.yaml
Normal file
9
bin/configs/java-helidon-server-se.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
generatorName: java-helidon-server
|
||||
library: se
|
||||
outputDir: samples/server/petstore/java-helidon-server/se
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/java-helidon/server
|
||||
additionalProperties:
|
||||
artifactId: petstore-helidon-server-se
|
||||
hideGenerationTimestamp: "true"
|
||||
fullProject: "true"
|
@ -32,6 +32,7 @@ The following generators are available:
|
||||
* [groovy](generators/groovy.md)
|
||||
* [haskell-http-client](generators/haskell-http-client.md)
|
||||
* [java](generators/java.md)
|
||||
* [java-helidon-client (beta)](generators/java-helidon-client.md)
|
||||
* [java-micronaut-client (beta)](generators/java-micronaut-client.md)
|
||||
* [javascript](generators/javascript.md)
|
||||
* [javascript-apollo-deprecated (deprecated)](generators/javascript-apollo-deprecated.md)
|
||||
@ -92,6 +93,7 @@ The following generators are available:
|
||||
* [haskell](generators/haskell.md)
|
||||
* [haskell-yesod (beta)](generators/haskell-yesod.md)
|
||||
* [java-camel](generators/java-camel.md)
|
||||
* [java-helidon-server (beta)](generators/java-helidon-server.md)
|
||||
* [java-inflector](generators/java-inflector.md)
|
||||
* [java-micronaut-server (beta)](generators/java-micronaut-server.md)
|
||||
* [java-msf4j](generators/java-msf4j.md)
|
||||
|
316
docs/generators/java-helidon-client.md
Normal file
316
docs/generators/java-helidon-client.md
Normal file
@ -0,0 +1,316 @@
|
||||
---
|
||||
title: Documentation for the java-helidon-client Generator
|
||||
---
|
||||
|
||||
## METADATA
|
||||
|
||||
| Property | Value | Notes |
|
||||
| -------- | ----- | ----- |
|
||||
| generator name | java-helidon-client | pass this to the generate command after -g |
|
||||
| generator stability | BETA | |
|
||||
| generator type | CLIENT | |
|
||||
| generator language | Java | |
|
||||
| generator default templating engine | mustache | |
|
||||
| helpTxt | Generates a Helidon MP or SE client | |
|
||||
|
||||
## CONFIG OPTIONS
|
||||
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|
|
||||
|apiPackage|package for generated api classes| |org.openapitools.client.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-java-client|
|
||||
|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|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|configKey|Config key in @RegisterRestClient. Default to none.| |null|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|java8|
|
||||
|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.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|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.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>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.</dd></dl>|false|
|
||||
|fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false|
|
||||
|fullProject|If set to true, it will generate all files; if set to false, it will only generate API files. If unspecified, the behavior depends on whether a project exists or not: if it does not, same as true; if it does, same as false. Note that test files are never overwritten.| ||
|
||||
|groupId|groupId in generated pom.xml| |org.openapitools|
|
||||
|helidonVersion|Helidon version for generated code| |3.0.1|
|
||||
|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|
|
||||
|implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null|
|
||||
|invokerPackage|root package for generated code| |org.openapitools.client|
|
||||
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>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.</dd></dl>|true|
|
||||
|library|library template (sub-template) to use|<dl><dt>**mp**</dt><dd>Helidon MP Client</dd><dt>**se**</dt><dd>Helidon SE Client</dd></dl>|mp|
|
||||
|licenseName|The name of the license| |Unlicense|
|
||||
|licenseUrl|The URL of the license| |http://unlicense.org|
|
||||
|modelPackage|package for generated models| |org.openapitools.client.model|
|
||||
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|
||||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||
|rootJavaEEPackage|Root package name for Java EE| |Helidon 2.x and earlier: javax; Helidon 3.x and later: jakarta|
|
||||
|serializableModel|boolean - toggle "implements Serializable" for generated models| |false|
|
||||
|serializationLibrary|Serialization library, defaults to Jackson|<dl><dt>**jsonb**</dt><dd>Use JSON-B as serialization library</dd><dt>**jackson**</dt><dd>Use Jackson as serialization library</dd></dl>|null|
|
||||
|snapshotVersion|Uses a SNAPSHOT version.|<dl><dt>**true**</dt><dd>Use a SnapShot Version</dd><dt>**false**</dt><dd>Use a Release Version</dd></dl>|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|
|
||||
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|
||||
|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|
|
||||
|
||||
## SUPPORTED VENDOR EXTENSIONS
|
||||
|
||||
| Extension name | Description | Applicable for | Default value |
|
||||
| -------------- | ----------- | -------------- | ------------- |
|
||||
|x-discriminator-value|Used with model inheritance to specify value for discriminator that identifies current model|MODEL|
|
||||
|x-implements|Ability to specify interfaces that model must implements|MODEL|empty array
|
||||
|x-setter-extra-annotation|Custom annotation that can be specified over java setter for specific field|FIELD|When field is array & uniqueItems, then this extension is used to add `@JsonDeserialize(as = LinkedHashSet.class)` over setter, otherwise no value
|
||||
|x-tags|Specify multiple swagger tags for operation|OPERATION|null
|
||||
|x-accepts|Specify custom value for 'Accept' header for operation|OPERATION|null
|
||||
|x-content-type|Specify custom value for 'Content-Type' header for operation|OPERATION|null
|
||||
|x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null
|
||||
|x-field-extra-annotation|List of custom annotations to be added to property|FIELD|null
|
||||
|x-webclient-blocking|Specifies if method for specific operation should be blocking or non-blocking(ex: return `Mono<T>/Flux<T>` or `return T/List<T>/Set<T>` & execute `.block()` inside generated method)|OPERATION|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
|
||||
|
||||
<ul class="column-ul">
|
||||
<li>Boolean</li>
|
||||
<li>Double</li>
|
||||
<li>Float</li>
|
||||
<li>Integer</li>
|
||||
<li>Long</li>
|
||||
<li>Object</li>
|
||||
<li>String</li>
|
||||
<li>boolean</li>
|
||||
<li>byte[]</li>
|
||||
</ul>
|
||||
|
||||
## RESERVED WORDS
|
||||
|
||||
<ul class="column-ul">
|
||||
<li>abstract</li>
|
||||
<li>apiclient</li>
|
||||
<li>apiexception</li>
|
||||
<li>apiresponse</li>
|
||||
<li>assert</li>
|
||||
<li>boolean</li>
|
||||
<li>break</li>
|
||||
<li>byte</li>
|
||||
<li>case</li>
|
||||
<li>catch</li>
|
||||
<li>char</li>
|
||||
<li>class</li>
|
||||
<li>configuration</li>
|
||||
<li>const</li>
|
||||
<li>continue</li>
|
||||
<li>default</li>
|
||||
<li>do</li>
|
||||
<li>double</li>
|
||||
<li>else</li>
|
||||
<li>enum</li>
|
||||
<li>extends</li>
|
||||
<li>file</li>
|
||||
<li>final</li>
|
||||
<li>finally</li>
|
||||
<li>float</li>
|
||||
<li>for</li>
|
||||
<li>goto</li>
|
||||
<li>if</li>
|
||||
<li>implements</li>
|
||||
<li>import</li>
|
||||
<li>instanceof</li>
|
||||
<li>int</li>
|
||||
<li>interface</li>
|
||||
<li>list</li>
|
||||
<li>localreturntype</li>
|
||||
<li>localvaraccept</li>
|
||||
<li>localvaraccepts</li>
|
||||
<li>localvarauthnames</li>
|
||||
<li>localvarcollectionqueryparams</li>
|
||||
<li>localvarcontenttype</li>
|
||||
<li>localvarcontenttypes</li>
|
||||
<li>localvarcookieparams</li>
|
||||
<li>localvarformparams</li>
|
||||
<li>localvarheaderparams</li>
|
||||
<li>localvarpath</li>
|
||||
<li>localvarpostbody</li>
|
||||
<li>localvarqueryparams</li>
|
||||
<li>long</li>
|
||||
<li>native</li>
|
||||
<li>new</li>
|
||||
<li>null</li>
|
||||
<li>object</li>
|
||||
<li>package</li>
|
||||
<li>private</li>
|
||||
<li>protected</li>
|
||||
<li>public</li>
|
||||
<li>return</li>
|
||||
<li>short</li>
|
||||
<li>static</li>
|
||||
<li>strictfp</li>
|
||||
<li>stringutil</li>
|
||||
<li>super</li>
|
||||
<li>switch</li>
|
||||
<li>synchronized</li>
|
||||
<li>this</li>
|
||||
<li>throw</li>
|
||||
<li>throws</li>
|
||||
<li>transient</li>
|
||||
<li>try</li>
|
||||
<li>void</li>
|
||||
<li>volatile</li>
|
||||
<li>while</li>
|
||||
</ul>
|
||||
|
||||
## 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
|
||||
|Uuid|✗|
|
||||
|Array|✓|OAS2,OAS3
|
||||
|Null|✗|OAS3
|
||||
|AnyType|✗|OAS2,OAS3
|
||||
|Object|✓|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
|
||||
|allOf|✗|OAS2,OAS3
|
||||
|anyOf|✗|OAS3
|
||||
|oneOf|✗|OAS3
|
||||
|not|✗|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
|
318
docs/generators/java-helidon-server.md
Normal file
318
docs/generators/java-helidon-server.md
Normal file
@ -0,0 +1,318 @@
|
||||
---
|
||||
title: Documentation for the java-helidon-server Generator
|
||||
---
|
||||
|
||||
## METADATA
|
||||
|
||||
| Property | Value | Notes |
|
||||
| -------- | ----- | ----- |
|
||||
| generator name | java-helidon-server | pass this to the generate command after -g |
|
||||
| generator stability | BETA | |
|
||||
| generator type | SERVER | |
|
||||
| generator language | Java | |
|
||||
| generator default templating engine | mustache | |
|
||||
| helpTxt | Generates a Java Helidon Server application. | |
|
||||
|
||||
## CONFIG OPTIONS
|
||||
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|
|
||||
|apiPackage|package for generated api classes| |org.openapitools.server.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-java-server|
|
||||
|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|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|java8|
|
||||
|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.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|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.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>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.</dd></dl>|false|
|
||||
|fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false|
|
||||
|fullProject|If set to true, it will generate all files; if set to false, it will only generate API files. If unspecified, the behavior depends on whether a project exists or not: if it does not, same as true; if it does, same as false. Note that test files are never overwritten.| ||
|
||||
|gradleProject|Whether to generate gradle project instead of maven.| |false|
|
||||
|groupId|groupId in generated pom.xml| |org.openapitools|
|
||||
|helidonVersion|Helidon version for generated code| |3.0.1|
|
||||
|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|
|
||||
|implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null|
|
||||
|invokerPackage|root package for generated code| |org.openapitools.server|
|
||||
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>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.</dd></dl>|true|
|
||||
|library|library template (sub-template) to use|<dl><dt>**mp**</dt><dd>Helidon MP Server</dd><dt>**se**</dt><dd>Helidon SE Server</dd><dt>**nima**</dt><dd>Helidon NIMA Server</dd><dt>**nima-annotations**</dt><dd>Helidon NIMA Annotations Server</dd></dl>|se|
|
||||
|licenseName|The name of the license| |Unlicense|
|
||||
|licenseUrl|The URL of the license| |http://unlicense.org|
|
||||
|modelPackage|package for generated models| |org.openapitools.server.model|
|
||||
|openApiNullable|Enable OpenAPI Jackson Nullable library| |true|
|
||||
|performBeanValidation|Perform BeanValidation| |false|
|
||||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||
|rootJavaEEPackage|Root package name for Java EE| |Helidon 2.x and earlier: javax; Helidon 3.x and later: jakarta|
|
||||
|serializableModel|boolean - toggle "implements Serializable" for generated models| |false|
|
||||
|serializationLibrary|Serialization library, defaults to Jackson|<dl><dt>**jsonb**</dt><dd>Use JSON-B as serialization library</dd><dt>**jackson**</dt><dd>Use Jackson as serialization library</dd></dl>|null|
|
||||
|snapshotVersion|Uses a SNAPSHOT version.|<dl><dt>**true**</dt><dd>Use a SnapShot Version</dd><dt>**false**</dt><dd>Use a Release Version</dd></dl>|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|
|
||||
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|
||||
|useAbstractClass|Whether to generate abstract classes for REST API instead of interfaces.| |false|
|
||||
|useBeanValidation|Use Bean Validation| |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|
|
||||
|
||||
## SUPPORTED VENDOR EXTENSIONS
|
||||
|
||||
| Extension name | Description | Applicable for | Default value |
|
||||
| -------------- | ----------- | -------------- | ------------- |
|
||||
|x-discriminator-value|Used with model inheritance to specify value for discriminator that identifies current model|MODEL|
|
||||
|x-implements|Ability to specify interfaces that model must implements|MODEL|empty array
|
||||
|x-setter-extra-annotation|Custom annotation that can be specified over java setter for specific field|FIELD|When field is array & uniqueItems, then this extension is used to add `@JsonDeserialize(as = LinkedHashSet.class)` over setter, otherwise no value
|
||||
|x-tags|Specify multiple swagger tags for operation|OPERATION|null
|
||||
|x-accepts|Specify custom value for 'Accept' header for operation|OPERATION|null
|
||||
|x-content-type|Specify custom value for 'Content-Type' header for operation|OPERATION|null
|
||||
|x-class-extra-annotation|List of custom annotations to be added to model|MODEL|null
|
||||
|x-field-extra-annotation|List of custom annotations to be added to property|FIELD|null
|
||||
|
||||
|
||||
## 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
|
||||
|
||||
<ul class="column-ul">
|
||||
<li>Boolean</li>
|
||||
<li>Double</li>
|
||||
<li>Float</li>
|
||||
<li>Integer</li>
|
||||
<li>Long</li>
|
||||
<li>Object</li>
|
||||
<li>String</li>
|
||||
<li>boolean</li>
|
||||
<li>byte[]</li>
|
||||
</ul>
|
||||
|
||||
## RESERVED WORDS
|
||||
|
||||
<ul class="column-ul">
|
||||
<li>abstract</li>
|
||||
<li>apiclient</li>
|
||||
<li>apiexception</li>
|
||||
<li>apiresponse</li>
|
||||
<li>assert</li>
|
||||
<li>boolean</li>
|
||||
<li>break</li>
|
||||
<li>byte</li>
|
||||
<li>case</li>
|
||||
<li>catch</li>
|
||||
<li>char</li>
|
||||
<li>class</li>
|
||||
<li>configuration</li>
|
||||
<li>const</li>
|
||||
<li>continue</li>
|
||||
<li>default</li>
|
||||
<li>do</li>
|
||||
<li>double</li>
|
||||
<li>else</li>
|
||||
<li>enum</li>
|
||||
<li>extends</li>
|
||||
<li>file</li>
|
||||
<li>final</li>
|
||||
<li>finally</li>
|
||||
<li>float</li>
|
||||
<li>for</li>
|
||||
<li>goto</li>
|
||||
<li>if</li>
|
||||
<li>implements</li>
|
||||
<li>import</li>
|
||||
<li>instanceof</li>
|
||||
<li>int</li>
|
||||
<li>interface</li>
|
||||
<li>list</li>
|
||||
<li>localreturntype</li>
|
||||
<li>localvaraccept</li>
|
||||
<li>localvaraccepts</li>
|
||||
<li>localvarauthnames</li>
|
||||
<li>localvarcollectionqueryparams</li>
|
||||
<li>localvarcontenttype</li>
|
||||
<li>localvarcontenttypes</li>
|
||||
<li>localvarcookieparams</li>
|
||||
<li>localvarformparams</li>
|
||||
<li>localvarheaderparams</li>
|
||||
<li>localvarpath</li>
|
||||
<li>localvarpostbody</li>
|
||||
<li>localvarqueryparams</li>
|
||||
<li>long</li>
|
||||
<li>native</li>
|
||||
<li>new</li>
|
||||
<li>null</li>
|
||||
<li>object</li>
|
||||
<li>package</li>
|
||||
<li>private</li>
|
||||
<li>protected</li>
|
||||
<li>public</li>
|
||||
<li>return</li>
|
||||
<li>short</li>
|
||||
<li>static</li>
|
||||
<li>strictfp</li>
|
||||
<li>stringutil</li>
|
||||
<li>super</li>
|
||||
<li>switch</li>
|
||||
<li>synchronized</li>
|
||||
<li>this</li>
|
||||
<li>throw</li>
|
||||
<li>throws</li>
|
||||
<li>transient</li>
|
||||
<li>try</li>
|
||||
<li>void</li>
|
||||
<li>volatile</li>
|
||||
<li>while</li>
|
||||
</ul>
|
||||
|
||||
## 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
|
||||
|Uuid|✗|
|
||||
|Array|✓|OAS2,OAS3
|
||||
|Null|✗|OAS3
|
||||
|AnyType|✗|OAS2,OAS3
|
||||
|Object|✓|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
|
||||
|allOf|✗|OAS2,OAS3
|
||||
|anyOf|✗|OAS3
|
||||
|oneOf|✗|OAS3
|
||||
|not|✗|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
|
@ -0,0 +1,530 @@
|
||||
/*
|
||||
* Copyright 2022 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022 Oracle and/or its affiliates
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.Function;
|
||||
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenParameter;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.CodegenResponse;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.VendorExtension;
|
||||
import org.openapitools.codegen.meta.GeneratorMetadata;
|
||||
import org.openapitools.codegen.meta.Stability;
|
||||
import org.openapitools.codegen.meta.features.DocumentationFeature;
|
||||
import org.openapitools.codegen.meta.features.GlobalFeature;
|
||||
import org.openapitools.codegen.model.ModelMap;
|
||||
import org.openapitools.codegen.model.ModelsMap;
|
||||
import org.openapitools.codegen.model.OperationsMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.SERIALIZATION_LIBRARY;
|
||||
|
||||
public class JavaHelidonClientCodegen extends JavaHelidonCommonCodegen {
|
||||
|
||||
private final Logger LOGGER = LoggerFactory.getLogger(JavaHelidonClientCodegen.class);
|
||||
|
||||
private static final String X_HELIDON_REQUIRED_IMPL_IMPORTS = "x-helidon-requiredImplImports";
|
||||
private static final String X_HELIDON_IMPL_IMPORTS = "x-helidon-implImports";
|
||||
public static final String CONFIG_KEY = "configKey";
|
||||
|
||||
protected String configKey = null;
|
||||
protected boolean useBeanValidation = false;
|
||||
protected boolean performBeanValidation = false;
|
||||
protected boolean useGzipFeature = false;
|
||||
protected boolean caseInsensitiveResponseHeaders = false;
|
||||
protected Path invokerFolder;
|
||||
protected Path apiFolder;
|
||||
protected String serializationLibrary = null;
|
||||
|
||||
/**
|
||||
* Constructor for this generator. Uses the embedded template dir to find common templates
|
||||
* shared between Helidon client and server generators.
|
||||
*
|
||||
* @see org.openapitools.codegen.templating.GeneratorTemplateContentLocator#getFullTemplatePath
|
||||
*/
|
||||
public JavaHelidonClientCodegen() {
|
||||
// beta for now
|
||||
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
|
||||
.stability(Stability.BETA)
|
||||
.build();
|
||||
// TODO: Move GlobalFeature.ParameterizedServer to library: jersey after moving featureSet to generatorMetadata
|
||||
modifyFeatureSet(features -> features
|
||||
.includeDocumentationFeatures(DocumentationFeature.Readme)
|
||||
.includeGlobalFeatures(GlobalFeature.ParameterizedServer)
|
||||
);
|
||||
|
||||
outputFolder = "generated-code" + File.separator + "java";
|
||||
embeddedTemplateDir = "java-helidon" + File.separator + "common"; // use embedded for common
|
||||
templateDir = "java-helidon" + File.separator + "client";
|
||||
invokerPackage = "org.openapitools.client";
|
||||
artifactId = "openapi-java-client";
|
||||
apiPackage = invokerPackage + ".api";
|
||||
modelPackage = invokerPackage + ".model";
|
||||
|
||||
updateOption(CodegenConstants.INVOKER_PACKAGE, getInvokerPackage());
|
||||
updateOption(CodegenConstants.ARTIFACT_ID, getArtifactId());
|
||||
updateOption(CodegenConstants.API_PACKAGE, apiPackage);
|
||||
updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage);
|
||||
|
||||
modelTestTemplateFiles.put("model_test.mustache", ".java");
|
||||
|
||||
cliOptions.add(CliOption.newString(CONFIG_KEY, "Config key in @RegisterRestClient. Default to none."));
|
||||
|
||||
supportedLibraries.put(HELIDON_MP, "Helidon MP Client");
|
||||
supportedLibraries.put(HELIDON_SE, "Helidon SE Client");
|
||||
|
||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY,
|
||||
"library template (sub-template) to use");
|
||||
libraryOption.setEnum(supportedLibraries);
|
||||
libraryOption.setDefault(HELIDON_MP);
|
||||
cliOptions.add(libraryOption);
|
||||
setLibrary(HELIDON_MP); // default
|
||||
|
||||
CliOption serializationLibrary = new CliOption(SERIALIZATION_LIBRARY,
|
||||
"Serialization library, defaults to Jackson");
|
||||
Map<String, String> serializationOptions = new HashMap<>();
|
||||
serializationOptions.put(SERIALIZATION_LIBRARY_JACKSON, "Use Jackson as serialization library");
|
||||
serializationOptions.put(SERIALIZATION_LIBRARY_JSONB, "Use JSON-B as serialization library");
|
||||
serializationLibrary.setEnum(serializationOptions);
|
||||
cliOptions.add(serializationLibrary);
|
||||
setSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON); // default
|
||||
|
||||
removeUnusedOptions();
|
||||
|
||||
// Ensure the OAS 3.x discriminator mappings include 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.
|
||||
this.setLegacyDiscriminatorBehavior(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "java-helidon-client";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Helidon MP or SE client";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co,
|
||||
Map<String, List<CodegenOperation>> operations) {
|
||||
super.addOperationToGroup(tag, resourcePath, operation, co, operations);
|
||||
if (HELIDON_MP.equals(getLibrary())) {
|
||||
co.subresourceOperation = !co.path.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
if (templateName.contains("_impl")) {
|
||||
String suffix = apiTemplateFiles().get(templateName);
|
||||
return apiFileFolder() + File.separator + toApiFilename(tag) + "Impl" + suffix;
|
||||
}
|
||||
return super.apiFilename(templateName, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(SERIALIZATION_LIBRARY)) {
|
||||
setSerializationLibrary(additionalProperties.get(SERIALIZATION_LIBRARY).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CONFIG_KEY)) {
|
||||
setConfigKey(additionalProperties.get(CONFIG_KEY).toString());
|
||||
}
|
||||
|
||||
String invokerPath = invokerPackage.replace('.', File.separatorChar);
|
||||
invokerFolder = Paths.get(sourceFolder, invokerPath);
|
||||
apiFolder = Paths.get(outputFolder).relativize(Paths.get(apiFileFolder()));
|
||||
|
||||
if (isLibrary(HELIDON_MP)) {
|
||||
String apiExceptionFolder = Paths.get(sourceFolder,
|
||||
apiPackage().replace('.', File.separatorChar)).toString();
|
||||
|
||||
List<SupportingFile> modifiable = new ArrayList<>();
|
||||
modifiable.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
modifiable.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
List<SupportingFile> unmodifiable = new ArrayList<>();
|
||||
unmodifiable.add(new SupportingFile("api_exception.mustache", apiExceptionFolder, "ApiException.java"));
|
||||
unmodifiable.add(new SupportingFile("api_exception_mapper.mustache", apiExceptionFolder, "ApiExceptionMapper.java"));
|
||||
if (additionalProperties.containsKey("jsr310")) {
|
||||
unmodifiable.add(new SupportingFile("JavaTimeFormatter.mustache",
|
||||
invokerFolder.toString(), "JavaTimeFormatter.java"));
|
||||
}
|
||||
processSupportingFiles(modifiable, unmodifiable);
|
||||
} else if (isLibrary(HELIDON_SE)) {
|
||||
apiTemplateFiles.put("api_impl.mustache", ".java");
|
||||
importMapping.put("StringJoiner", "java.util.StringJoiner");
|
||||
importMapping.put("WebClientRequestHeaders", "io.helidon.webclient.WebClientRequestHeaders");
|
||||
importMapping.put("Pair", invokerPackage + ".Pair");
|
||||
|
||||
|
||||
List<SupportingFile> modifiable = new ArrayList<>();
|
||||
modifiable.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
modifiable.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
List<SupportingFile> unmodifiable = new ArrayList<>();
|
||||
unmodifiable.add(new SupportingFile("ApiResponse.mustache", invokerFolder.toString(), "ApiResponse.java"));
|
||||
unmodifiable.add(new SupportingFile("ApiResponseBase.mustache", invokerFolder.toString(), "ApiResponseBase.java"));
|
||||
unmodifiable.add(new SupportingFile("ApiClient.mustache", invokerFolder.toString(), "ApiClient.java"));
|
||||
unmodifiable.add(new SupportingFile("Pair.mustache", invokerFolder.toString(), "Pair.java"));
|
||||
unmodifiable.add(new SupportingFile("ResponseType.mustache", apiFolder.toString(), "ResponseType.java"));
|
||||
|
||||
processSupportingFiles(modifiable, unmodifiable);
|
||||
}
|
||||
else {
|
||||
LOGGER.error("Unknown library option (-l/--library): {}", getLibrary());
|
||||
}
|
||||
|
||||
if (getSerializationLibrary() == null) {
|
||||
LOGGER.info("No serializationLibrary configured, using '{}' as fallback", SERIALIZATION_LIBRARY_JACKSON);
|
||||
setSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON);
|
||||
}
|
||||
switch (getSerializationLibrary()) {
|
||||
case SERIALIZATION_LIBRARY_JACKSON:
|
||||
additionalProperties.put(SERIALIZATION_LIBRARY_JACKSON, "true");
|
||||
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
|
||||
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache", invokerFolder.toString(), "RFC3339DateFormat.java"));
|
||||
break;
|
||||
case SERIALIZATION_LIBRARY_JSONB:
|
||||
openApiNullable = false; // for Jackson only
|
||||
additionalProperties.put(SERIALIZATION_LIBRARY_JSONB, "true");
|
||||
additionalProperties.remove(SERIALIZATION_LIBRARY_JACKSON);
|
||||
break;
|
||||
default:
|
||||
additionalProperties.remove(SERIALIZATION_LIBRARY_JACKSON);
|
||||
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
|
||||
LOGGER.error("Unknown serialization library option");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if pom file and src directory already exist.
|
||||
*
|
||||
* @return outcome of test
|
||||
*/
|
||||
@Override
|
||||
protected boolean projectFilesExist() {
|
||||
Path projectFolder = Paths.get(getOutputTestFolder());
|
||||
Path pom = projectFolder.resolve("pom.xml");
|
||||
Path src = projectFolder.resolve(invokerFolder);
|
||||
return pom.toFile().exists() && src.toFile().exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
|
||||
if (isLibrary(HELIDON_MP)) {
|
||||
super.postProcessOperationsWithModels(objs, allModels);
|
||||
return AbstractJavaJAXRSServerCodegen.jaxrsPostProcessOperations(objs);
|
||||
} else {
|
||||
// Compute the imports to declare in the generated API impl class.
|
||||
List<Map<String, String>> imports = objs.getImports();
|
||||
List<Map<String, String>> implImports = new ArrayList<>(imports);
|
||||
|
||||
Set<String> requiredImplImportClassNames = new HashSet<>();
|
||||
for (CodegenOperation op : objs.getOperations().getOperation()) {
|
||||
requiredImplImportClassNames.addAll((Set) op.vendorExtensions.get(X_HELIDON_REQUIRED_IMPL_IMPORTS));
|
||||
}
|
||||
|
||||
Set<String> missingImportClassNames = new TreeSet<>(requiredImplImportClassNames);
|
||||
imports.stream()
|
||||
.map(m -> m.get("classname"))
|
||||
.forEach(missingImportClassNames::remove);
|
||||
|
||||
missingImportClassNames.forEach(c -> {
|
||||
Map<String, String> singleImportMap = new HashMap<>();
|
||||
singleImportMap.put("classname", c);
|
||||
singleImportMap.put("import", Objects.requireNonNull(importMapping.get(c), "no mapping for " + c));
|
||||
implImports.add(singleImportMap);
|
||||
});
|
||||
|
||||
objs.put(X_HELIDON_IMPL_IMPORTS, implImports);
|
||||
return objs;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
// We use two templates, one for the API interface and one for the impl class.
|
||||
// Add to the normal imports for this operation only those imports used in both
|
||||
// the API and the impl. Create a vendor extension on the operation to record the
|
||||
// additional imports needed for the implementation class.
|
||||
Set<String> requiredImplImports = new TreeSet<>();
|
||||
if (op.isArray) {
|
||||
op.imports.add("List");
|
||||
}
|
||||
if (op.isMap) {
|
||||
op.imports.add("Map");
|
||||
}
|
||||
if (op.getHasQueryParams()) {
|
||||
requiredImplImports.add("List");
|
||||
requiredImplImports.add("ArrayList");
|
||||
requiredImplImports.add("Pair");
|
||||
}
|
||||
if (op.getHasHeaderParams()) {
|
||||
requiredImplImports.add("WebClientRequestHeaders");
|
||||
}
|
||||
if (op.getHasFormParams()) {
|
||||
requiredImplImports.add("StringJoiner");
|
||||
}
|
||||
if (op.getHasCookieParams()) {
|
||||
requiredImplImports.add("StringJoiner");
|
||||
}
|
||||
if (op.bodyParams.stream().anyMatch(JavaHelidonClientCodegen::checkIsArray)
|
||||
|| op.allParams.stream().anyMatch(JavaHelidonClientCodegen::checkIsArray)
|
||||
|| op.responses.stream().anyMatch(CodegenResponse::getIsArray)) {
|
||||
requiredImplImports.add("List");
|
||||
op.imports.add("List");
|
||||
}
|
||||
if (op.bodyParams.stream().anyMatch(JavaHelidonClientCodegen::checkIsMap)
|
||||
|| op.allParams.stream().anyMatch(JavaHelidonClientCodegen::checkIsMap)
|
||||
|| op.responses.stream().anyMatch(CodegenResponse::getIsMap)) {
|
||||
requiredImplImports.add("Map");
|
||||
op.imports.add("Map");
|
||||
}
|
||||
|
||||
op.vendorExtensions.put(X_HELIDON_REQUIRED_IMPL_IMPORTS, requiredImplImports);
|
||||
return op;
|
||||
}
|
||||
|
||||
private static boolean checkIsArray(CodegenParameter p) {
|
||||
return p.isArray || !(p.getSchema() != null && p.getSchema().getIsArray());
|
||||
}
|
||||
|
||||
private static boolean checkIsMap(CodegenParameter p) {
|
||||
return p.isMap || !(p.getSchema() != null && p.getSchema().getIsMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
super.postProcessModelProperty(model, property);
|
||||
|
||||
if (!BooleanUtils.toBoolean(model.isEnum)
|
||||
&& additionalProperties.containsKey(SERIALIZATION_LIBRARY_JACKSON)) {
|
||||
model.imports.add("JsonProperty");
|
||||
model.imports.add("JsonValue");
|
||||
model.imports.add("JsonInclude");
|
||||
model.imports.add("JsonTypeName");
|
||||
} else if (additionalProperties.containsKey(SERIALIZATION_LIBRARY_JACKSON)) {
|
||||
model.imports.add("JsonValue");
|
||||
model.imports.add("JsonCreator");
|
||||
}
|
||||
|
||||
if (HELIDON_MP.equals(getLibrary())) {
|
||||
model.imports.remove("ApiModelProperty");
|
||||
model.imports.remove("ApiModel");
|
||||
model.imports.remove("JsonSerialize");
|
||||
model.imports.remove("ToStringSerializer");
|
||||
} else if (HELIDON_SE.equals(getLibrary())) {
|
||||
// TODO check for SE-specifics
|
||||
model.imports.remove("ApiModelProperty");
|
||||
model.imports.remove("ApiModel");
|
||||
model.imports.remove("JsonSerialize");
|
||||
model.imports.remove("ToStringSerializer");
|
||||
}
|
||||
|
||||
if ("set".equals(property.containerType) && !JACKSON.equals(serializationLibrary)) {
|
||||
// clean-up
|
||||
model.imports.remove("JsonDeserialize");
|
||||
property.vendorExtensions.remove("x-setter-extra-annotation");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Schema model) {
|
||||
CodegenModel codegenModel = super.fromModel(name, model);
|
||||
if (isLibrary(HELIDON_MP)) {
|
||||
if (codegenModel.imports.contains("ApiModel")) {
|
||||
// Remove io.swagger.annotations.ApiModel import
|
||||
codegenModel.imports.remove("ApiModel");
|
||||
}
|
||||
} else if (isLibrary(HELIDON_SE)) {
|
||||
if (codegenModel.imports.contains("ApiModel")) {
|
||||
// Remove io.swagger.annotations.ApiModel import
|
||||
codegenModel.imports.remove("ApiModel");
|
||||
}
|
||||
}
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ModelsMap postProcessModels(ModelsMap objs) {
|
||||
objs = super.postProcessModels(objs);
|
||||
List<ModelMap> models = objs.getModels();
|
||||
|
||||
if (additionalProperties.containsKey(SERIALIZATION_LIBRARY_JACKSON)) {
|
||||
List<Map<String, String>> imports = objs.getImports();
|
||||
for (ModelMap mo : models) {
|
||||
CodegenModel cm = mo.getModel();
|
||||
boolean addImports = false;
|
||||
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
if (this.openApiNullable) {
|
||||
boolean isOptionalNullable = Boolean.FALSE.equals(var.required) && Boolean.TRUE.equals(var.isNullable);
|
||||
// only add JsonNullable and related imports to optional and nullable values
|
||||
addImports |= isOptionalNullable;
|
||||
var.getVendorExtensions().put("x-is-jackson-optional-nullable", isOptionalNullable);
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(var.getVendorExtensions().get("x-enum-as-string"))) {
|
||||
// treat enum string as just string
|
||||
var.datatypeWithEnum = var.dataType;
|
||||
|
||||
if (StringUtils.isNotEmpty(var.defaultValue)) { // has default value
|
||||
String defaultValue = var.defaultValue.substring(var.defaultValue.lastIndexOf('.') + 1);
|
||||
for (Map<String, Object> enumVars : (List<Map<String, Object>>) var.getAllowableValues().get("enumVars")) {
|
||||
if (defaultValue.equals(enumVars.get("name"))) {
|
||||
// update default to use the string directly instead of enum string
|
||||
var.defaultValue = (String) enumVars.get("value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add import for Set, HashSet
|
||||
cm.imports.add("Set");
|
||||
Map<String, String> importsSet = new HashMap<>();
|
||||
importsSet.put("import", "java.util.Set");
|
||||
imports.add(importsSet);
|
||||
Map<String, String> importsHashSet = new HashMap<>();
|
||||
importsHashSet.put("import", "java.util.HashSet");
|
||||
imports.add(importsHashSet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (addImports) {
|
||||
Map<String, String> imports2Classnames = new HashMap<>();
|
||||
imports2Classnames.put("JsonNullable", "org.openapitools.jackson.nullable.JsonNullable");
|
||||
imports2Classnames.put("NoSuchElementException", "java.util.NoSuchElementException");
|
||||
imports2Classnames.put("JsonIgnore", "com.fasterxml.jackson.annotation.JsonIgnore");
|
||||
for (Map.Entry<String, String> entry : imports2Classnames.entrySet()) {
|
||||
cm.imports.add(entry.getKey());
|
||||
Map<String, String> importsItem = new HashMap<>();
|
||||
importsItem.put("import", entry.getValue());
|
||||
imports.add(importsItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
public void setConfigKey(String configKey) {
|
||||
this.configKey = configKey;
|
||||
}
|
||||
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
public void setPerformBeanValidation(boolean performBeanValidation) {
|
||||
this.performBeanValidation = performBeanValidation;
|
||||
}
|
||||
|
||||
public void setUseGzipFeature(boolean useGzipFeature) {
|
||||
this.useGzipFeature = useGzipFeature;
|
||||
}
|
||||
|
||||
public void setCaseInsensitiveResponseHeaders(final Boolean caseInsensitiveResponseHeaders) {
|
||||
this.caseInsensitiveResponseHeaders = caseInsensitiveResponseHeaders;
|
||||
}
|
||||
|
||||
public String getSerializationLibrary() {
|
||||
return serializationLibrary;
|
||||
}
|
||||
|
||||
public void setSerializationLibrary(String serializationLibrary) {
|
||||
if (SERIALIZATION_LIBRARY_JACKSON.equalsIgnoreCase(serializationLibrary)) {
|
||||
this.serializationLibrary = SERIALIZATION_LIBRARY_JACKSON;
|
||||
} else if (SERIALIZATION_LIBRARY_JSONB.equalsIgnoreCase(serializationLibrary)) {
|
||||
this.serializationLibrary = SERIALIZATION_LIBRARY_JSONB;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected serializationLibrary value: " + serializationLibrary);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
generateYAMLSpecFile(objs);
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiVarName(String name) {
|
||||
String apiVarName = super.toApiVarName(name);
|
||||
if (reservedWords.contains(apiVarName)) {
|
||||
apiVarName = escapeReservedWord(apiVarName);
|
||||
}
|
||||
return apiVarName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {
|
||||
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo", "JsonIgnoreProperties")) {
|
||||
Map<String, String> oneImport = new HashMap<>();
|
||||
oneImport.put("import", importMapping.get(i));
|
||||
if (!imports.contains(oneImport)) {
|
||||
imports.add(oneImport);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VendorExtension> getSupportedVendorExtensions() {
|
||||
List<VendorExtension> extensions = super.getSupportedVendorExtensions();
|
||||
extensions.add(VendorExtension.X_WEBCLIENT_BLOCKING);
|
||||
return extensions;
|
||||
}
|
||||
}
|
@ -0,0 +1,326 @@
|
||||
/*
|
||||
* Copyright 2022 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022 Oracle and/or its affiliates
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
|
||||
import org.openapitools.codegen.languages.features.PerformBeanValidationFeatures;
|
||||
|
||||
import static org.openapitools.codegen.CodegenConstants.DEVELOPER_EMAIL;
|
||||
import static org.openapitools.codegen.CodegenConstants.DEVELOPER_NAME;
|
||||
import static org.openapitools.codegen.CodegenConstants.DEVELOPER_ORGANIZATION;
|
||||
import static org.openapitools.codegen.CodegenConstants.DEVELOPER_ORGANIZATION_URL;
|
||||
import static org.openapitools.codegen.CodegenConstants.PARENT_ARTIFACT_ID;
|
||||
import static org.openapitools.codegen.CodegenConstants.PARENT_GROUP_ID;
|
||||
import static org.openapitools.codegen.CodegenConstants.PARENT_VERSION;
|
||||
import static org.openapitools.codegen.CodegenConstants.SCM_CONNECTION;
|
||||
import static org.openapitools.codegen.CodegenConstants.SCM_DEVELOPER_CONNECTION;
|
||||
import static org.openapitools.codegen.CodegenConstants.SCM_URL;
|
||||
|
||||
public abstract class JavaHelidonCommonCodegen extends AbstractJavaCodegen
|
||||
implements BeanValidationFeatures, PerformBeanValidationFeatures {
|
||||
|
||||
static final String HELIDON_MP = "mp";
|
||||
static final String HELIDON_SE = "se";
|
||||
|
||||
static final String HELIDON_NIMA = "nima";
|
||||
static final String HELIDON_NIMA_ANNOTATIONS = "nima-annotations";
|
||||
|
||||
static final String MICROPROFILE_ROOT_PACKAGE = "rootJavaEEPackage";
|
||||
static final String MICROPROFILE_ROOT_DEP_PREFIX = "x-helidon-rootJavaEEDepPrefix";
|
||||
static final String X_HAS_RETURN_TYPE = "x-helidon-hasReturnType";
|
||||
static final String X_RETURN_TYPE_EXAMPLE_VALUE = "x-helidon-exampleReturnTypeValue";
|
||||
static final String MICROPROFILE_ROOT_PACKAGE_DESC = "Root package name for Java EE";
|
||||
static final String MICROPROFILE_ROOT_PACKAGE_JAVAX = "javax";
|
||||
static final String MICROPROFILE_ROOT_PACKAGE_JAKARTA = "jakarta";
|
||||
private static final String VALIDATION_ARTIFACT_PREFIX_KEY = "x-helidon-validationArtifactPrefix";
|
||||
private static final String VALIDATION_ARTIFACT_PREFIX_JAVAX = "";
|
||||
private static final String VALIDATION_ARTIFACT_PREFIX_JAKARTA = MICROPROFILE_ROOT_PACKAGE_JAKARTA + ".";
|
||||
|
||||
private static final Map<String, String> EXAMPLE_RETURN_VALUES = new HashMap<String, String>() {
|
||||
{
|
||||
put("set", "Set");
|
||||
put("array", "List");
|
||||
put("map", "Map");
|
||||
}
|
||||
};
|
||||
|
||||
// for generated doc
|
||||
static final String MICROPROFILE_ROOT_PACKAGE_DEFAULT =
|
||||
"Helidon 2.x and earlier: " + MICROPROFILE_ROOT_PACKAGE_JAVAX
|
||||
+ "; Helidon 3.x and later: " + MICROPROFILE_ROOT_PACKAGE_JAKARTA;
|
||||
|
||||
static final String SERIALIZATION_LIBRARY_JACKSON = "jackson";
|
||||
static final String SERIALIZATION_LIBRARY_JSONB = "jsonb";
|
||||
|
||||
public static final String HELIDON_VERSION = "helidonVersion";
|
||||
public static final String DEFAULT_HELIDON_VERSION = "3.0.1";
|
||||
static final String HELIDON_VERSION_DESC = "Helidon version for generated code";
|
||||
|
||||
static final String FULL_PROJECT = "fullProject";
|
||||
static final String FULL_PROJECT_DESC = "If set to true, it will generate all files; if set to false, " +
|
||||
"it will only generate API files. If unspecified, the behavior depends on whether a project " +
|
||||
"exists or not: if it does not, same as true; if it does, same as false. Note that test files " +
|
||||
"are never overwritten.";
|
||||
|
||||
private String helidonVersion;
|
||||
private String rootJavaEEPackage;
|
||||
private String rootJavaEEDepPrefix;
|
||||
|
||||
public JavaHelidonCommonCodegen() {
|
||||
super();
|
||||
cliOptions.add(new CliOption(HELIDON_VERSION, HELIDON_VERSION_DESC)
|
||||
.defaultValue(DEFAULT_HELIDON_VERSION));
|
||||
cliOptions.add(new CliOption(MICROPROFILE_ROOT_PACKAGE, MICROPROFILE_ROOT_PACKAGE_DESC)
|
||||
.defaultValue(MICROPROFILE_ROOT_PACKAGE_DEFAULT));
|
||||
cliOptions.add(new CliOption(FULL_PROJECT, FULL_PROJECT_DESC)
|
||||
.defaultValue("")); // depends on project state
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
String userHelidonVersion = "";
|
||||
String userParentVersion = "";
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PARENT_VERSION)) {
|
||||
userParentVersion = additionalProperties.get(CodegenConstants.PARENT_VERSION).toString();
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(HELIDON_VERSION)) {
|
||||
userHelidonVersion = additionalProperties.get(HELIDON_VERSION).toString();
|
||||
}
|
||||
|
||||
if (!userHelidonVersion.isEmpty()) {
|
||||
if (!userParentVersion.isEmpty() && !userHelidonVersion.equals(userParentVersion)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(Locale.ROOT,
|
||||
"Both %s and %s properties were set with different value.",
|
||||
CodegenConstants.PARENT_VERSION,
|
||||
HELIDON_VERSION));
|
||||
}
|
||||
setHelidonVersion(userHelidonVersion);
|
||||
} else if (!userParentVersion.isEmpty()) {
|
||||
setHelidonVersion(userParentVersion);
|
||||
} else {
|
||||
setHelidonVersion(DEFAULT_HELIDON_VERSION);
|
||||
}
|
||||
|
||||
additionalProperties.put(HELIDON_VERSION, helidonVersion);
|
||||
setEEPackageAndDependencies(helidonVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
op.vendorExtensions.put(X_HAS_RETURN_TYPE, op.returnType != null && !op.returnType.equals("void"));
|
||||
op.vendorExtensions.put(X_RETURN_TYPE_EXAMPLE_VALUE, chooseExampleReturnTypeValue(op));
|
||||
return op;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove set of options not currently used by any Helidon generator. Should be
|
||||
* called during construction but only on leaf classes.
|
||||
*/
|
||||
protected void removeUnusedOptions() {
|
||||
removeCliOptions(SCM_CONNECTION,
|
||||
SCM_DEVELOPER_CONNECTION,
|
||||
SCM_URL,
|
||||
DEVELOPER_NAME,
|
||||
DEVELOPER_ORGANIZATION,
|
||||
DEVELOPER_ORGANIZATION_URL,
|
||||
DEVELOPER_EMAIL,
|
||||
PARENT_ARTIFACT_ID,
|
||||
PARENT_VERSION,
|
||||
PARENT_GROUP_ID,
|
||||
DISABLE_HTML_ESCAPING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether to generate or overwrite files depending on fullProject property.
|
||||
* If property is unspecified, then check if sources are already there and avoid overwriting
|
||||
* modifiable files.
|
||||
*
|
||||
* @param modifiable list of modifiable files to be processed
|
||||
* @param unmodifiable list of unmodifiable files to be processed
|
||||
*/
|
||||
protected void processSupportingFiles(List<SupportingFile> modifiable, List<SupportingFile> unmodifiable) {
|
||||
Boolean fullProject = !additionalProperties.containsKey(FULL_PROJECT) ? null :
|
||||
Boolean.parseBoolean(additionalProperties.get(FULL_PROJECT).toString());
|
||||
|
||||
if (fullProject == null && !projectFilesExist()) { // not explicitly set
|
||||
supportingFiles.addAll(modifiable);
|
||||
} else if (Boolean.TRUE.equals(fullProject)) { // explicitly set to true
|
||||
supportingFiles.addAll(modifiable);
|
||||
}
|
||||
supportingFiles.addAll(unmodifiable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if project is already generated to determine default for the fullProject
|
||||
* flag. Can be overridden in subclasses to strengthen test condition.
|
||||
*
|
||||
* @return outcome of test
|
||||
*/
|
||||
protected boolean projectFilesExist() {
|
||||
return Paths.get(getOutputTestFolder()).toFile().exists();
|
||||
}
|
||||
|
||||
protected String rootJavaEEPackage() {
|
||||
return rootJavaEEPackage;
|
||||
}
|
||||
|
||||
private void setHelidonVersion(String version) {
|
||||
helidonVersion = version;
|
||||
setParentVersion(version);
|
||||
}
|
||||
|
||||
private void setEEPackageAndDependencies(String version) {
|
||||
|
||||
rootJavaEEPackage = checkAndSelectRootEEPackage(version);
|
||||
additionalProperties.put(MICROPROFILE_ROOT_PACKAGE, rootJavaEEPackage);
|
||||
|
||||
rootJavaEEDepPrefix = checkAndSelectRootEEDepPrefix(version);
|
||||
additionalProperties.put(MICROPROFILE_ROOT_DEP_PREFIX, rootJavaEEDepPrefix);
|
||||
|
||||
additionalProperties.put(VALIDATION_ARTIFACT_PREFIX_KEY,
|
||||
rootJavaEEDepPrefix.equals(MICROPROFILE_ROOT_PACKAGE_JAVAX)
|
||||
? VALIDATION_ARTIFACT_PREFIX_JAVAX
|
||||
: VALIDATION_ARTIFACT_PREFIX_JAKARTA);
|
||||
}
|
||||
|
||||
private String checkAndSelectRootEEPackage(String version) {
|
||||
String packagePrefixImpliedByVersion = usesJakartaPackages(version)
|
||||
? MICROPROFILE_ROOT_PACKAGE_JAKARTA
|
||||
: MICROPROFILE_ROOT_PACKAGE_JAVAX;
|
||||
|
||||
// Make sure any user-specified root EE package is correct for the chosen Helidon version.
|
||||
if (additionalProperties.containsKey(MICROPROFILE_ROOT_PACKAGE)) {
|
||||
String userRootEEPackage = additionalProperties.get(MICROPROFILE_ROOT_PACKAGE).toString();
|
||||
if (!packagePrefixImpliedByVersion.equals(userRootEEPackage)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(Locale.ROOT,
|
||||
"Helidon version %s uses the %s namespace but options specified '%s'",
|
||||
version,
|
||||
packagePrefixImpliedByVersion,
|
||||
userRootEEPackage));
|
||||
}
|
||||
return userRootEEPackage;
|
||||
}
|
||||
|
||||
// No explicit setting for the root EE package.
|
||||
return packagePrefixImpliedByVersion;
|
||||
}
|
||||
|
||||
private String checkAndSelectRootEEDepPrefix(String version) {
|
||||
String mavenDepPrefixImpliedByVersion = usesJakartaPrefix(version)
|
||||
? MICROPROFILE_ROOT_PACKAGE_JAKARTA
|
||||
: MICROPROFILE_ROOT_PACKAGE_JAVAX;
|
||||
|
||||
// Make sure any user-specified prefix is correct for the chosen Helidon version.
|
||||
if (additionalProperties.containsKey(MICROPROFILE_ROOT_DEP_PREFIX)) {
|
||||
String userMavenDepPrefix = additionalProperties.get(MICROPROFILE_ROOT_DEP_PREFIX).toString();
|
||||
if (!mavenDepPrefixImpliedByVersion.equals(userMavenDepPrefix)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(Locale.ROOT,
|
||||
"Helidon version %s uses the %s prefix for EE dependencies but options specified '%s'",
|
||||
version,
|
||||
mavenDepPrefixImpliedByVersion,
|
||||
userMavenDepPrefix));
|
||||
}
|
||||
return userMavenDepPrefix;
|
||||
}
|
||||
|
||||
// No explicit setting for the dependency prefix.
|
||||
return mavenDepPrefixImpliedByVersion;
|
||||
}
|
||||
|
||||
private boolean usesJakartaPackages(String version) {
|
||||
return !version.startsWith("2.") && !version.startsWith("1.");
|
||||
}
|
||||
|
||||
private boolean usesJakartaPrefix(String version) {
|
||||
return !version.startsWith("1.");
|
||||
}
|
||||
|
||||
protected void removeCliOptions(String... opt) {
|
||||
List<String> opts = Arrays.asList(opt);
|
||||
Set<CliOption> forRemoval = cliOptions.stream()
|
||||
.filter(cliOption -> opts.contains(cliOption.getOpt()))
|
||||
.collect(Collectors.toSet());
|
||||
forRemoval.forEach(cliOptions::remove);
|
||||
}
|
||||
|
||||
private String chooseExampleReturnTypeValue(CodegenOperation op) {
|
||||
|
||||
|
||||
// See DefaultCodegen#handleMethodResponse to see how the various op fields related to the return type are set.
|
||||
if (op.returnType == null) {
|
||||
return ""; // won't be used anyway in the templates
|
||||
}
|
||||
if (op.returnContainer != null) {
|
||||
return "java.util.Collections.empty" + EXAMPLE_RETURN_VALUES.get(op.returnContainer) + "()";
|
||||
}
|
||||
switch (op.returnType) {
|
||||
case "Integer":
|
||||
return "new Integer(0)";
|
||||
|
||||
case "byte[]":
|
||||
return "new byte[0]";
|
||||
|
||||
case "Float":
|
||||
return "new Float(0.0f)";
|
||||
|
||||
case "boolean":
|
||||
return "false";
|
||||
|
||||
case "Long":
|
||||
return "new Long(0L)";
|
||||
|
||||
case "Object":
|
||||
return "new Object()";
|
||||
|
||||
case "String":
|
||||
return "\"\"";
|
||||
|
||||
case "Boolean":
|
||||
return "new Boolean(false)";
|
||||
|
||||
case "Double":
|
||||
return "new Double(0.0d)";
|
||||
|
||||
default:
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,420 @@
|
||||
/*
|
||||
* Copyright 2022 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright (c) 2022 Oracle and/or its affiliates
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.CodegenType;
|
||||
import org.openapitools.codegen.SupportingFile;
|
||||
import org.openapitools.codegen.meta.GeneratorMetadata;
|
||||
import org.openapitools.codegen.meta.Stability;
|
||||
import org.openapitools.codegen.meta.features.DocumentationFeature;
|
||||
import org.openapitools.codegen.model.ModelMap;
|
||||
import org.openapitools.codegen.model.OperationMap;
|
||||
import org.openapitools.codegen.model.OperationsMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class JavaHelidonServerCodegen extends JavaHelidonCommonCodegen {
|
||||
|
||||
private final Logger LOGGER = LoggerFactory.getLogger(JavaHelidonServerCodegen.class);
|
||||
|
||||
public static final String USE_ABSTRACT_CLASS = "useAbstractClass";
|
||||
public static final String GRADLE_PROJECT = "gradleProject";
|
||||
|
||||
protected boolean useBeanValidation = true;
|
||||
protected String implFolder = "src/main/java";
|
||||
protected String serializationLibrary = null;
|
||||
|
||||
private boolean useAbstractClass = false;
|
||||
private boolean gradleProject = false;
|
||||
|
||||
public JavaHelidonServerCodegen() {
|
||||
super();
|
||||
// beta for now
|
||||
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
|
||||
.stability(Stability.BETA)
|
||||
.build();
|
||||
|
||||
modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme));
|
||||
|
||||
outputFolder = "generated-code" + File.separator + "java";
|
||||
embeddedTemplateDir = templateDir = "java-helidon" + File.separator + "server";
|
||||
invokerPackage = "org.openapitools.server";
|
||||
artifactId = "openapi-java-server";
|
||||
apiPackage = invokerPackage + ".api";
|
||||
modelPackage = invokerPackage + ".model";
|
||||
sourceFolder = "src" + File.separator + "main" + File.separator + "java";
|
||||
|
||||
// clioOptions default redefinition need to be updated
|
||||
updateOption(CodegenConstants.INVOKER_PACKAGE, this.getInvokerPackage());
|
||||
updateOption(CodegenConstants.ARTIFACT_ID, this.getArtifactId());
|
||||
updateOption(CodegenConstants.API_PACKAGE, apiPackage);
|
||||
updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage);
|
||||
|
||||
modelTestTemplateFiles.put("model_test.mustache", ".java");
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use Bean Validation"));
|
||||
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Perform BeanValidation"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_ABSTRACT_CLASS,
|
||||
"Whether to generate abstract classes for REST API instead of interfaces.", useAbstractClass));
|
||||
cliOptions.add(CliOption.newBoolean(GRADLE_PROJECT,
|
||||
"Whether to generate gradle project instead of maven.", gradleProject));
|
||||
|
||||
// clear model and api doc template as this codegen
|
||||
// does not support auto-generated markdown doc at the moment
|
||||
modelDocTemplateFiles.remove("model_doc.mustache");
|
||||
apiDocTemplateFiles.remove("api_doc.mustache");
|
||||
|
||||
// clear test templates
|
||||
// as this codegen does not support api tests at the moment
|
||||
apiTestTemplateFiles.clear();
|
||||
|
||||
supportedLibraries.put(HELIDON_MP, "Helidon MP Server");
|
||||
supportedLibraries.put(HELIDON_SE, "Helidon SE Server");
|
||||
supportedLibraries.put(HELIDON_NIMA, "Helidon NIMA Server");
|
||||
supportedLibraries.put(HELIDON_NIMA_ANNOTATIONS, "Helidon NIMA Annotations Server");
|
||||
|
||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
libraryOption.setEnum(supportedLibraries);
|
||||
libraryOption.setDefault(HELIDON_SE);
|
||||
cliOptions.add(libraryOption);
|
||||
setLibrary(HELIDON_SE);
|
||||
|
||||
CliOption serializationLibrary = new CliOption(CodegenConstants.SERIALIZATION_LIBRARY,
|
||||
"Serialization library, defaults to Jackson");
|
||||
Map<String, String> serializationOptions = new HashMap<>();
|
||||
serializationOptions.put(SERIALIZATION_LIBRARY_JACKSON, "Use Jackson as serialization library");
|
||||
serializationOptions.put(SERIALIZATION_LIBRARY_JSONB, "Use JSON-B as serialization library");
|
||||
serializationLibrary.setEnum(serializationOptions);
|
||||
cliOptions.add(serializationLibrary);
|
||||
setSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON);
|
||||
|
||||
removeUnusedOptions();
|
||||
|
||||
this.setLegacyDiscriminatorBehavior(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
supportingFiles.clear();
|
||||
dateLibrary = "java8";
|
||||
|
||||
addApiTemplateFiles();
|
||||
SupportingFile pomFile = new SupportingFile("pom.mustache", "", "pom.xml");
|
||||
SupportingFile readmeFile = new SupportingFile("README.mustache", "", "README.md");
|
||||
SupportingFile openApiFile = new SupportingFile("openapi.mustache",
|
||||
("src/main/resources/META-INF").replace("/", File.separator), "openapi.yml");
|
||||
SupportingFile logFile = new SupportingFile("logging.mustache",
|
||||
("src.main.resources").replace(".", File.separator), "logging.properties");
|
||||
SupportingFile packageInfoFile = new SupportingFile("package-info.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator),
|
||||
"package-info.java");
|
||||
List<SupportingFile> modifiable = new ArrayList<>();
|
||||
modifiable.add(pomFile);
|
||||
modifiable.add(readmeFile);
|
||||
modifiable.add(logFile);
|
||||
modifiable.add(packageInfoFile);
|
||||
List<SupportingFile> unmodifiable = new ArrayList<>();
|
||||
unmodifiable.add(openApiFile);
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
|
||||
}
|
||||
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
|
||||
|
||||
importMapping.put("ObjectMapper", "com.fasterxml.jackson.databind.ObjectMapper");
|
||||
importMapping.put("Jsonb", rootJavaEEPackage() + ".json.bind.Jsonb");
|
||||
importMapping.put("JsonbBuilder", rootJavaEEPackage() + ".json.bind.JsonbBuilder");
|
||||
|
||||
if (additionalProperties.containsKey(USE_ABSTRACT_CLASS)) {
|
||||
useAbstractClass = Boolean.parseBoolean(additionalProperties.get(USE_ABSTRACT_CLASS).toString());
|
||||
}
|
||||
if (!useAbstractClass) {
|
||||
additionalProperties.remove(USE_ABSTRACT_CLASS);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GRADLE_PROJECT)) {
|
||||
gradleProject = Boolean.parseBoolean(additionalProperties.get(GRADLE_PROJECT).toString());
|
||||
}
|
||||
if (!gradleProject) {
|
||||
additionalProperties.remove(GRADLE_PROJECT);
|
||||
} else {
|
||||
modifiable.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
|
||||
modifiable.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
modifiable.remove(pomFile);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY)) {
|
||||
setSerializationLibrary(additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY).toString());
|
||||
}
|
||||
|
||||
String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
||||
|
||||
if (additionalProperties.containsKey("jsr310") && isLibrary(HELIDON_MP)) {
|
||||
supportingFiles.add(new SupportingFile("JavaTimeFormatter.mustache", invokerFolder, "JavaTimeFormatter.java"));
|
||||
}
|
||||
|
||||
if (isLibrary(HELIDON_MP)) {
|
||||
String resourceFolder = "src" + File.separator + "main" + File.separator + "resources";
|
||||
String metaInfFolder = resourceFolder + File.separator + "META-INF";
|
||||
supportingFiles.add(new SupportingFile("RestApplication.mustache", invokerFolder, "RestApplication.java"));
|
||||
supportingFiles.add(new SupportingFile("microprofile-config.properties.mustache", metaInfFolder, "microprofile" +
|
||||
"-config.properties"));
|
||||
supportingFiles.add(new SupportingFile("beans.xml.mustache", metaInfFolder, "beans.xml"));
|
||||
processSupportingFiles(modifiable, unmodifiable);
|
||||
} else if (isLibrary(HELIDON_SE)) {
|
||||
artifactId = "openapi-helidon-se-server";
|
||||
|
||||
modifiable.add(new SupportingFile("application.mustache",
|
||||
("src.main.resources").replace(".", java.io.File.separator), "application.yaml"));
|
||||
modifiable.add(new SupportingFile("mainTest.mustache",
|
||||
(testFolder + File.separator + invokerPackage).replace(".", java.io.File.separator),
|
||||
"MainTest.java"));
|
||||
modifiable.add(new SupportingFile("main.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator),
|
||||
"Main.java"));
|
||||
unmodifiable.add(new SupportingFile("validatorUtils.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator),
|
||||
"ValidatorUtils.java"));
|
||||
if (useAbstractClass) {
|
||||
importMapping.put("Map", "java.util.Map");
|
||||
importMapping.put("HashMap", "java.util.HashMap");
|
||||
importMapping.put("InputStream", "java.io.InputStream");
|
||||
importMapping.put("ReadableBodyPart", "io.helidon.media.multipart.ReadableBodyPart");
|
||||
importMapping.put("ArrayList", "java.util.ArrayList");
|
||||
importMapping.put("ByteArrayOutputStream", "java.io.ByteArrayOutputStream");
|
||||
importMapping.put("DataChunk", "io.helidon.common.http.DataChunk");
|
||||
importMapping.put("UncheckedIOException", "java.io.UncheckedIOException");
|
||||
importMapping.put("IOException", "java.io.IOException");
|
||||
importMapping.put("ByteArrayInputStream", "java.io.ByteArrayInputStream");
|
||||
}
|
||||
importMapping.put("Handler", "io.helidon.webserver.Handler");
|
||||
processSupportingFiles(modifiable, unmodifiable);
|
||||
} else if (isLibrary(HELIDON_NIMA)) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
} else if (isLibrary(HELIDON_NIMA_ANNOTATIONS)) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
} else {
|
||||
LOGGER.error("Unknown library option (-l/--library): {}", getLibrary());
|
||||
throw new IllegalArgumentException(
|
||||
String.format(Locale.ROOT,
|
||||
"Unknown library option %s for Helidon Server",
|
||||
getLibrary()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (getSerializationLibrary() == null) {
|
||||
LOGGER.info("No serializationLibrary configured, using '{}' as fallback", SERIALIZATION_LIBRARY_JACKSON);
|
||||
setSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON);
|
||||
}
|
||||
switch (getSerializationLibrary()) {
|
||||
case SERIALIZATION_LIBRARY_JACKSON:
|
||||
additionalProperties.put(SERIALIZATION_LIBRARY_JACKSON, "true");
|
||||
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
|
||||
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache", invokerFolder, "RFC3339DateFormat.java"));
|
||||
if (isLibrary(HELIDON_SE)) {
|
||||
supportingFiles.add(new SupportingFile("jsonProvider.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator),
|
||||
"JsonProvider.java"));
|
||||
}
|
||||
break;
|
||||
case SERIALIZATION_LIBRARY_JSONB:
|
||||
additionalProperties.put(SERIALIZATION_LIBRARY_JSONB, "true");
|
||||
additionalProperties.remove(SERIALIZATION_LIBRARY_JACKSON);
|
||||
break;
|
||||
default:
|
||||
additionalProperties.remove(SERIALIZATION_LIBRARY_JACKSON);
|
||||
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
|
||||
LOGGER.error("Unknown serialization library option");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void addApiTemplateFiles() {
|
||||
Boolean fullProject = !additionalProperties.containsKey(FULL_PROJECT) ? null :
|
||||
Boolean.parseBoolean(additionalProperties.get(FULL_PROJECT).toString());
|
||||
if (fullProject == null && !projectFilesExist()) {
|
||||
apiTemplateFiles.put("apiImpl.mustache", "Impl.java");
|
||||
} else if (Boolean.TRUE.equals(fullProject)) {
|
||||
apiTemplateFiles.put("apiImpl.mustache", "Impl.java");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation codegenOperation = super.fromOperation(path, httpMethod, operation, servers);
|
||||
if (HELIDON_SE.equals(getLibrary())) {
|
||||
if (additionalProperties.containsKey(JACKSON)) {
|
||||
codegenOperation.imports.add("ObjectMapper");
|
||||
}
|
||||
if (additionalProperties.containsKey(SERIALIZATION_LIBRARY_JSONB)) {
|
||||
codegenOperation.imports.add("Jsonb");
|
||||
codegenOperation.imports.add("JsonbBuilder");
|
||||
}
|
||||
if (codegenOperation.bodyParam != null) {
|
||||
codegenOperation.imports.add("Handler");
|
||||
}
|
||||
if (codegenOperation.queryParams.size() > 0 && useAbstractClass) {
|
||||
codegenOperation.imports.add("List");
|
||||
}
|
||||
if (codegenOperation.formParams.size() > 0 && useAbstractClass) {
|
||||
codegenOperation.imports.add("Map");
|
||||
codegenOperation.imports.add("HashMap");
|
||||
codegenOperation.imports.add("InputStream");
|
||||
codegenOperation.imports.add("ReadableBodyPart");
|
||||
codegenOperation.imports.add("ArrayList");
|
||||
codegenOperation.imports.add("DataChunk");
|
||||
codegenOperation.imports.add("ByteArrayOutputStream");
|
||||
codegenOperation.imports.add("IOException");
|
||||
codegenOperation.imports.add("UncheckedIOException");
|
||||
codegenOperation.imports.add("ByteArrayInputStream");
|
||||
}
|
||||
}
|
||||
return codegenOperation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
generateYAMLSpecFile(objs);
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultService";
|
||||
}
|
||||
name = sanitizeName(name);
|
||||
return camelize(name) + "Service";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Schema model) {
|
||||
CodegenModel codegenModel = super.fromModel(name, model);
|
||||
// remove swagger imports
|
||||
codegenModel.imports.remove("ApiModelProperty");
|
||||
codegenModel.imports.remove("ApiModel");
|
||||
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
|
||||
OperationMap operations = objs.getOperations();
|
||||
if (HELIDON_MP.equals(getLibrary())) {
|
||||
return AbstractJavaJAXRSServerCodegen.jaxrsPostProcessOperations(objs);
|
||||
}
|
||||
if (operations != null && HELIDON_SE.equals(getLibrary())) {
|
||||
List<CodegenOperation> ops = operations.getOperation();
|
||||
for (CodegenOperation operation : ops) {
|
||||
if (operation.formParams.size() > 0) {
|
||||
objs.put("isFormParamsFunctions", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
super.postProcessModelProperty(model, property);
|
||||
|
||||
if (Boolean.TRUE.equals(model.hasEnums)) {
|
||||
// Add imports for Jackson
|
||||
if (additionalProperties.containsKey(JACKSON)) {
|
||||
model.imports.add("JsonValue");
|
||||
model.imports.add("JsonCreator");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "java-helidon-server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Java Helidon Server application.";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPerformBeanValidation(boolean performBeanValidation) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
public String getSerializationLibrary() {
|
||||
return serializationLibrary;
|
||||
}
|
||||
|
||||
public void setSerializationLibrary(String serializationLibrary) {
|
||||
if (SERIALIZATION_LIBRARY_JACKSON.equalsIgnoreCase(serializationLibrary)) {
|
||||
this.serializationLibrary = SERIALIZATION_LIBRARY_JACKSON;
|
||||
} else if (SERIALIZATION_LIBRARY_JSONB.equalsIgnoreCase(serializationLibrary)) {
|
||||
this.serializationLibrary = SERIALIZATION_LIBRARY_JSONB;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected serializationLibrary value: " + serializationLibrary);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if pom file and src directory already exist.
|
||||
*
|
||||
* @return outcome of test
|
||||
*/
|
||||
@Override
|
||||
protected boolean projectFilesExist() {
|
||||
Path projectFolder = Paths.get(getOutputTestFolder());
|
||||
Path pom = projectFolder.resolve("pom.xml");
|
||||
Path buildGradle = projectFolder.resolve("build.gradle");
|
||||
Path src = projectFolder.resolve(Paths.get(sourceFolder, invokerPackage.replace('.', File.separatorChar)));
|
||||
return (pom.toFile().exists() || buildGradle.toFile().exists()) && src.toFile().exists();
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,8 @@ org.openapitools.codegen.languages.HaskellServantCodegen
|
||||
org.openapitools.codegen.languages.HaskellYesodServerCodegen
|
||||
org.openapitools.codegen.languages.JavaClientCodegen
|
||||
org.openapitools.codegen.languages.JavaCXFClientCodegen
|
||||
org.openapitools.codegen.languages.JavaHelidonClientCodegen
|
||||
org.openapitools.codegen.languages.JavaHelidonServerCodegen
|
||||
org.openapitools.codegen.languages.JavaInflectorServerCodegen
|
||||
org.openapitools.codegen.languages.JavaMicronautClientCodegen
|
||||
org.openapitools.codegen.languages.JavaMicronautServerCodegen
|
||||
|
@ -0,0 +1,53 @@
|
||||
{{>licenseInfo}}
|
||||
package {{invokerPackage}};
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
|
||||
/**
|
||||
* Class that add parsing/formatting support for Java 8+ {@code OffsetDateTime} class.
|
||||
* It's generated for java clients when {@code AbstractJavaCodegen#dateLibrary} specified as {@code java8}.
|
||||
*/
|
||||
{{>generatedAnnotation}}
|
||||
public class JavaTimeFormatter {
|
||||
|
||||
private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||
|
||||
/**
|
||||
* Get the date format used to parse/format {@code OffsetDateTime} parameters.
|
||||
* @return DateTimeFormatter
|
||||
*/
|
||||
public DateTimeFormatter getOffsetDateTimeFormatter() {
|
||||
return offsetDateTimeFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the date format used to parse/format {@code OffsetDateTime} parameters.
|
||||
* @param offsetDateTimeFormatter {@code DateTimeFormatter}
|
||||
*/
|
||||
public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) {
|
||||
this.offsetDateTimeFormatter = offsetDateTimeFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given string into {@code OffsetDateTime} object.
|
||||
* @param str String
|
||||
* @return {@code OffsetDateTime}
|
||||
*/
|
||||
public OffsetDateTime parseOffsetDateTime(String str) {
|
||||
try {
|
||||
return OffsetDateTime.parse(str, offsetDateTimeFormatter);
|
||||
} catch (DateTimeParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Format the given {@code OffsetDateTime} object into string.
|
||||
* @param offsetDateTime {@code OffsetDateTime}
|
||||
* @return {@code OffsetDateTime} in string format
|
||||
*/
|
||||
public String formatOffsetDateTime(OffsetDateTime offsetDateTime) {
|
||||
return offsetDateTimeFormatter.format(offsetDateTime);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
{{>licenseInfo}}
|
||||
package {{invokerPackage}};
|
||||
|
||||
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.text.DecimalFormat;
|
||||
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();
|
||||
this.numberFormat = new DecimalFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date parse(String source) {
|
||||
return parse(source, new ParsePosition(0));
|
||||
}
|
||||
|
||||
@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 super.clone();
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{invokerPackage}};
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class StringUtil {
|
||||
/**
|
||||
* Check if the given array contains the given value (with case-insensitive comparison).
|
||||
*
|
||||
* @param array The array
|
||||
* @param value The value to search
|
||||
* @return true if the array contains the value
|
||||
*/
|
||||
public static boolean containsIgnoreCase(String[] array, String value) {
|
||||
for (String str : array) {
|
||||
if (value == null && str == null) {
|
||||
return true;
|
||||
}
|
||||
if (value != null && value.equalsIgnoreCase(str)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join an array of strings with the given separator.
|
||||
* <p>
|
||||
* Note: This might be replaced by utility method from commons-lang or guava someday
|
||||
* if one of those libraries is added as dependency.
|
||||
* </p>
|
||||
*
|
||||
* @param array The array of strings
|
||||
* @param separator The separator
|
||||
* @return the resulting string
|
||||
*/
|
||||
public static String join(String[] array, String separator) {
|
||||
int len = array.length;
|
||||
if (len == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
out.append(array[0]);
|
||||
for (int i = 1; i < len; i++) {
|
||||
out.append(separator).append(array[i]);
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Join a list of strings with the given separator.
|
||||
*
|
||||
* @param list The list of strings
|
||||
* @param separator The separator
|
||||
* @return the resulting string
|
||||
*/
|
||||
public static String join(Collection<String> list, String separator) {
|
||||
Iterator<String> iterator = list.iterator();
|
||||
StringBuilder out = new StringBuilder();
|
||||
if (iterator.hasNext()) {
|
||||
out.append(iterator.next());
|
||||
}
|
||||
while (iterator.hasNext()) {
|
||||
out.append(separator).append(iterator.next());
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
{{#additionalEnumTypeAnnotations}}{{{.}}}
|
||||
{{/additionalEnumTypeAnnotations}}
|
@ -0,0 +1,2 @@
|
||||
{{#additionalModelTypeAnnotations}}{{{.}}}
|
||||
{{/additionalModelTypeAnnotations}}
|
61
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/api.mustache
vendored
Normal file
61
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/api.mustache
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
{{>licenseInfo}}
|
||||
package {{package}};
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import {{rootJavaEEPackage}}.ws.rs.*;
|
||||
import {{rootJavaEEPackage}}.ws.rs.core.Response;
|
||||
import {{rootJavaEEPackage}}.ws.rs.core.MediaType;
|
||||
|
||||
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider;
|
||||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
{{#appName}}
|
||||
/**
|
||||
* {{{appName}}}
|
||||
*
|
||||
{{#appDescription}}
|
||||
* <p>{{{.}}}
|
||||
{{/appDescription}}
|
||||
*/
|
||||
{{/appName}}
|
||||
@RegisterRestClient{{#configKey}}(configKey="{{configKey}}"){{/configKey}}
|
||||
@RegisterProvider(ApiExceptionMapper.class)
|
||||
@Path("{{#useAnnotatedBasePath}}{{contextPath}}{{/useAnnotatedBasePath}}{{commonPath}}")
|
||||
public interface {{classname}} {
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
|
||||
{{#summary}}
|
||||
/**
|
||||
* {{summary}}
|
||||
{{#notes}}
|
||||
* {{.}}
|
||||
{{/notes}}
|
||||
{{#isDeprecated}}
|
||||
* @deprecated
|
||||
{{/isDeprecated}}
|
||||
*/
|
||||
{{/summary}}
|
||||
{{#isDeprecated}}
|
||||
@Deprecated
|
||||
{{/isDeprecated}}
|
||||
@{{httpMethod}}
|
||||
{{#subresourceOperation}}@Path("{{{path}}}"){{/subresourceOperation}}
|
||||
{{#hasConsumes}}
|
||||
@Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} })
|
||||
{{/hasConsumes}}
|
||||
{{#hasProduces}}
|
||||
@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} })
|
||||
{{/hasProduces}}
|
||||
{{{returnType}}}{{^returnType}}void{{/returnType}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}) throws ApiException, ProcessingException;
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
@ -0,0 +1,28 @@
|
||||
{{>licenseInfo}}
|
||||
package {{invokerPackage}};
|
||||
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
|
||||
public class ApiOperation {
|
||||
private final String path;
|
||||
private final String method;
|
||||
private final Operation operation;
|
||||
|
||||
public ApiOperation(String path, String method, Operation operation) {
|
||||
this.path = path;
|
||||
this.method = method;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public Operation getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
}
|
55
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/api_doc.mustache
vendored
Normal file
55
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/api_doc.mustache
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
# {{classname}}{{#description}}
|
||||
|
||||
{{.}}{{/description}}
|
||||
|
||||
All URIs are relative to *{{basePath}}*
|
||||
|
||||
| Method | HTTP request | Description |
|
||||
|------------- | ------------- | -------------|
|
||||
{{#operations}}{{#operation}}| [**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{commonPath}}{{path}} | {{summary}} |
|
||||
{{/operation}}{{/operations}}
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
|
||||
## {{operationId}}
|
||||
|
||||
> {{#returnType}}{{.}} {{/returnType}}{{operationId}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
|
||||
{{summary}}{{#notes}}
|
||||
|
||||
{{.}}{{/notes}}
|
||||
|
||||
### Parameters
|
||||
|
||||
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
|
||||
| Name | Type | Description | Notes |
|
||||
|------------- | ------------- | ------------- | -------------|{{/-last}}{{/allParams}}
|
||||
{{#allParams}}| **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} |{{^required}} [optional]{{/required}}{{^isContainer}}{{#defaultValue}} [default to {{.}}]{{/defaultValue}}{{/isContainer}}{{#allowableValues}} [enum: {{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}]{{/allowableValues}} |
|
||||
{{/allParams}}
|
||||
|
||||
### Return type
|
||||
|
||||
{{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}null (empty response body){{/returnType}}
|
||||
|
||||
### Authorization
|
||||
|
||||
{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}}
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: {{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
|
||||
- **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}}
|
||||
|
||||
{{#responses.0}}
|
||||
|
||||
### HTTP response details
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
{{#responses}}
|
||||
| **{{code}}** | {{message}} | {{#headers}} * {{baseName}} - {{description}} <br> {{/headers}}{{^headers.0}} - {{/headers.0}} |
|
||||
{{/responses}}
|
||||
{{/responses.0}}
|
||||
|
||||
{{/operation}}
|
||||
{{/operations}}
|
@ -0,0 +1,19 @@
|
||||
{{>licenseInfo}}
|
||||
package {{apiPackage}};
|
||||
|
||||
import {{rootJavaEEPackage}}.ws.rs.core.Response;
|
||||
|
||||
public class ApiException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Response response;
|
||||
|
||||
public ApiException(Response response) {
|
||||
super("Api response has status code " + response.getStatus());
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public Response getResponse() {
|
||||
return this.response;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
{{>licenseInfo}}
|
||||
package {{apiPackage}};
|
||||
|
||||
import {{rootJavaEEPackage}}.ws.rs.core.MultivaluedMap;
|
||||
import {{rootJavaEEPackage}}.ws.rs.core.Response;
|
||||
import {{rootJavaEEPackage}}.ws.rs.ext.Provider;
|
||||
|
||||
import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper;
|
||||
|
||||
@Provider
|
||||
public class ApiExceptionMapper implements ResponseExceptionMapper<ApiException> {
|
||||
|
||||
@Override
|
||||
public boolean handles(int status, MultivaluedMap<String, Object> headers) {
|
||||
return status >= 400;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiException toThrowable(Response response) {
|
||||
return new ApiException(response);
|
||||
}
|
||||
}
|
64
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/api_test.mustache
vendored
Normal file
64
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/api_test.mustache
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.eclipse.microprofile.rest.client.RestClientBuilder;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.MalformedURLException;
|
||||
{{^fullJavaUtil}}
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
{{/fullJavaUtil}}
|
||||
|
||||
/**
|
||||
{{#appName}}
|
||||
* {{{.}}} Test
|
||||
*
|
||||
{{/appName}}
|
||||
* API tests for {{classname}}
|
||||
*/
|
||||
public class {{classname}}Test {
|
||||
|
||||
private static {{classname}} client;
|
||||
private static final String baseUrl = "http://localhost:8080";
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() throws MalformedURLException {
|
||||
client = RestClientBuilder.newBuilder()
|
||||
.baseUrl(new URL(baseUrl))
|
||||
.register(ApiException.class)
|
||||
.build({{classname}}.class);
|
||||
}
|
||||
|
||||
{{#operations}}{{#operation}}
|
||||
/**
|
||||
{{#summary}}
|
||||
* {{summary}}
|
||||
*
|
||||
{{#notes}}
|
||||
* {{.}}
|
||||
*
|
||||
{{/notes}}
|
||||
{{/summary}}
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
public void {{operationId}}Test() throws Exception {
|
||||
{{#allParams}}
|
||||
{{/allParams}}
|
||||
//{{#returnType}}{{{.}}} response = {{/returnType}}client.{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
//{{#returnType}}assertNotNull(response);{{/returnType}}
|
||||
}
|
||||
{{/operation}}{{/operations}}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiKeyAuth implements Authentication {
|
||||
private final String location;
|
||||
private final String paramName;
|
||||
|
||||
private String apiKey;
|
||||
private String apiKeyPrefix;
|
||||
|
||||
public ApiKeyAuth(String location, String paramName) {
|
||||
this.location = location;
|
||||
this.paramName = paramName;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public String getParamName() {
|
||||
return paramName;
|
||||
}
|
||||
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
public void setApiKey(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public String getApiKeyPrefix() {
|
||||
return apiKeyPrefix;
|
||||
}
|
||||
|
||||
public void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
this.apiKeyPrefix = apiKeyPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
|
||||
if (apiKey == null) {
|
||||
return;
|
||||
}
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = apiKeyPrefix + " " + apiKey;
|
||||
} else {
|
||||
value = apiKey;
|
||||
}
|
||||
if ("query".equals(location)) {
|
||||
queryParams.add(new Pair(paramName, value));
|
||||
} else if ("header".equals(location)) {
|
||||
headerParams.put(paramName, value);
|
||||
} else if ("cookie".equals(location)) {
|
||||
cookieParams.put(paramName, value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class HttpBasicAuth implements Authentication {
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
|
||||
if (username == null && password == null) {
|
||||
return;
|
||||
}
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
headerParams.put("Authorization", "Basic " + Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class HttpBearerAuth implements Authentication {
|
||||
private final String scheme;
|
||||
private String bearerToken;
|
||||
|
||||
public HttpBearerAuth(String scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the token, which together with the scheme, will be sent as the value of the Authorization header.
|
||||
*
|
||||
* @return The bearer token
|
||||
*/
|
||||
public String getBearerToken() {
|
||||
return bearerToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the token, which together with the scheme, will be sent as the value of the Authorization header.
|
||||
*
|
||||
* @param bearerToken The bearer token to send in the Authorization header
|
||||
*/
|
||||
public void setBearerToken(String bearerToken) {
|
||||
this.bearerToken = bearerToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
|
||||
if(bearerToken == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
headerParams.put("Authorization", (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken);
|
||||
}
|
||||
|
||||
private static String upperCaseBearer(String scheme) {
|
||||
return ("bearer".equalsIgnoreCase(scheme)) ? "Bearer" : scheme;
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
{{#isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}}
|
@ -0,0 +1 @@
|
||||
{{#isCookieParam}}@CookieParam("{{baseName}}"){{^isContainer}}{{#defaultValue}} @DefaultValue("{{{.}}}"){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{{dataType}}} {{paramName}}{{/isCookieParam}}
|
46
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/enumClass.mustache
vendored
Normal file
46
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/enumClass.mustache
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
{{#jsonb}}
|
||||
@JsonbTypeSerializer({{datatypeWithEnum}}.Serializer.class)
|
||||
@JsonbTypeDeserializer({{datatypeWithEnum}}.Deserializer.class)
|
||||
{{/jsonb}}
|
||||
{{>additionalEnumTypeAnnotations}}public enum {{datatypeWithEnum}} {
|
||||
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}{{name}}({{dataType}}.valueOf({{{value}}})){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
|
||||
{{dataType}} value;
|
||||
|
||||
{{datatypeWithEnum}} ({{dataType}} v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public {{dataType}} value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
{{#jsonb}}
|
||||
public static final class Deserializer implements JsonbDeserializer<{{datatypeWithEnum}}> {
|
||||
@Override
|
||||
public {{datatypeWithEnum}} deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
|
||||
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
if (String.valueOf(b.value).equals(parser.getString())) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + parser.getString() + "'");{{/useNullForUnknownEnumValue}}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Serializer implements JsonbSerializer<{{datatypeWithEnum}}> {
|
||||
@Override
|
||||
public void serialize({{datatypeWithEnum}} obj, JsonGenerator generator, SerializationContext ctx) {
|
||||
generator.write(obj.value);
|
||||
}
|
||||
}
|
||||
{{/jsonb}}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
{{#jackson}}
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
{{/jackson}}
|
||||
|
||||
/**
|
||||
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
|
||||
*/
|
||||
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
|
||||
private {{{dataType}}} value;
|
||||
|
||||
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
{{#jackson}}
|
||||
@JsonValue
|
||||
{{/jackson}}
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
{{#jackson}}
|
||||
@JsonCreator
|
||||
{{/jackson}}
|
||||
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue(String text) {
|
||||
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
if (String.valueOf(b.value).equals(text)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
# {{classname}}
|
||||
|
||||
## Enum
|
||||
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
* `{{name}}` (value: `{{{value}}}`)
|
||||
{{/enumVars}}{{/allowableValues}}
|
@ -0,0 +1 @@
|
||||
{{#isFormParam}}@FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isFormParam}}
|
@ -0,0 +1 @@
|
||||
@{{rootJavaEEPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}})
|
@ -0,0 +1 @@
|
||||
{{#isHeaderParam}}@HeaderParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isHeaderParam}}
|
@ -0,0 +1,19 @@
|
||||
{{!
|
||||
If this is map and items are nullable, make sure that nulls are included.
|
||||
To determine what JsonInclude.Include method to use, consider the following:
|
||||
* If the field is required, always include it, even if it is null.
|
||||
* Else use custom behaviour, IOW use whatever is defined on the object mapper
|
||||
}}
|
||||
@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}})
|
||||
@JsonInclude({{#isMap}}{{#items.isNullable}}content = JsonInclude.Include.ALWAYS, {{/items.isNullable}}{{/isMap}}value = JsonInclude.Include.{{#required}}ALWAYS{{/required}}{{^required}}USE_DEFAULTS{{/required}})
|
||||
{{#withXml}}
|
||||
{{^isContainer}}
|
||||
@JacksonXmlProperty({{#isXmlAttribute}}isAttribute = true, {{/isXmlAttribute}}{{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#isXmlWrapped}}
|
||||
// items.xmlName={{items.xmlName}}
|
||||
@JacksonXmlElementWrapper(useWrapping = {{isXmlWrapped}}, {{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}localName = "{{#items.xmlName}}{{items.xmlName}}{{/items.xmlName}}{{^items.xmlName}}{{items.baseName}}{{/items.xmlName}}")
|
||||
{{/isXmlWrapped}}
|
||||
{{/isContainer}}
|
||||
{{/withXml}}
|
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* {{{appName}}}
|
||||
* {{{appDescription}}}
|
||||
*
|
||||
* {{#version}}The version of the OpenAPI document: {{{.}}}{{/version}}
|
||||
* {{#infoEmail}}Contact: {{{.}}}{{/infoEmail}}
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
19
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/model.mustache
vendored
Normal file
19
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/model.mustache
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
{{>licenseInfo}}
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
{{#serializableModel}}
|
||||
import java.io.Serializable;
|
||||
{{/serializableModel}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#isEnum}}
|
||||
{{>enumOuterClass}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{>pojo}}
|
||||
{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
@ -0,0 +1,95 @@
|
||||
/**
|
||||
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
|
||||
*/
|
||||
{{#gson}}
|
||||
@JsonAdapter({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.Adapter.class)
|
||||
{{/gson}}
|
||||
{{#jsonb}}
|
||||
@JsonbTypeSerializer({{datatypeWithEnum}}.Serializer.class)
|
||||
@JsonbTypeDeserializer({{datatypeWithEnum}}.Deserializer.class)
|
||||
{{/jsonb}}
|
||||
{{#withXml}}
|
||||
@XmlType(name="{{datatypeWithEnum}}")
|
||||
@XmlEnum({{dataType}}.class)
|
||||
{{/withXml}}
|
||||
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{#enumDescription}}
|
||||
/**
|
||||
* {{.}}
|
||||
*/
|
||||
{{/enumDescription}}
|
||||
{{#withXml}}
|
||||
@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
||||
{{/withXml}}
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
|
||||
private {{{dataType}}} value;
|
||||
|
||||
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{{dataType}}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
{{#jackson}}
|
||||
@JsonValue
|
||||
{{/jackson}}
|
||||
public {{{dataType}}} getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
{{#jackson}}
|
||||
@JsonCreator
|
||||
{{/jackson}}
|
||||
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
|
||||
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
if (b.value.equals(value)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||
}
|
||||
{{#gson}}
|
||||
|
||||
public static class Adapter extends TypeAdapter<{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}> {
|
||||
@Override
|
||||
public void write(final JsonWriter jsonWriter, final {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} enumeration) throws IOException {
|
||||
jsonWriter.value(enumeration.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
|
||||
{{^isNumber}}{{{dataType}}}{{/isNumber}}{{#isNumber}}String{{/isNumber}} value = {{#isFloat}}(float){{/isFloat}} jsonReader.{{#isNumber}}nextString(){{/isNumber}}{{#isInteger}}nextInt(){{/isInteger}}{{^isNumber}}{{^isInteger}}{{#isFloat}}nextDouble{{/isFloat}}{{^isFloat}}next{{{dataType}}}{{/isFloat}}(){{/isInteger}}{{/isNumber}};
|
||||
return {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.fromValue({{#isNumber}}new BigDecimal({{/isNumber}}value{{#isNumber}}){{/isNumber}});
|
||||
}
|
||||
}
|
||||
{{/gson}}
|
||||
{{#jsonb}}
|
||||
public static final class Deserializer implements JsonbDeserializer<{{datatypeWithEnum}}> {
|
||||
@Override
|
||||
public {{datatypeWithEnum}} deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
|
||||
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
if (String.valueOf(b.value).equals(parser.getString())) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + parser.getString() + "'");{{/useNullForUnknownEnumValue}}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Serializer implements JsonbSerializer<{{datatypeWithEnum}}> {
|
||||
@Override
|
||||
public void serialize({{datatypeWithEnum}} obj, JsonGenerator generator, SerializationContext ctx) {
|
||||
generator.write(obj.value);
|
||||
}
|
||||
}
|
||||
{{/jsonb}}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{{#models}}{{#model}}
|
||||
|
||||
{{#isEnum}}{{>enum_outer_doc}}{{/isEnum}}{{^isEnum}}{{>pojo_doc}}{{/isEnum}}
|
||||
{{/model}}{{/models}}
|
@ -0,0 +1,49 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
{{#fullJavaUtil}}
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
{{/fullJavaUtil}}
|
||||
|
||||
/**
|
||||
* Model tests for {{classname}}
|
||||
*/
|
||||
public class {{classname}}Test {
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{^vendorExtensions.x-is-one-of-interface}}
|
||||
{{^isEnum}}
|
||||
private final {{classname}} model = new {{classname}}();
|
||||
|
||||
{{/isEnum}}
|
||||
/**
|
||||
* Model tests for {{classname}}
|
||||
*/
|
||||
@Test
|
||||
public void test{{classname}}() {
|
||||
// TODO: test {{classname}}
|
||||
}
|
||||
|
||||
{{#allVars}}
|
||||
/**
|
||||
* Test the property '{{name}}'
|
||||
*/
|
||||
@Test
|
||||
public void {{name}}Test() {
|
||||
// TODO: test {{name}}
|
||||
}
|
||||
|
||||
{{/allVars}}
|
||||
{{/vendorExtensions.x-is-one-of-interface}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{>typeInfoAnnotation}}{{>xmlAnnotation}}
|
||||
public interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
|
||||
{{#discriminator}}
|
||||
public {{propertyType}} {{propertyGetter}}();
|
||||
{{/discriminator}}
|
||||
}
|
@ -0,0 +1 @@
|
||||
{{{openapi-yaml}}}
|
@ -0,0 +1 @@
|
||||
{{#isPathParam}}@PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isPathParam}}
|
155
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/pojo.mustache
vendored
Normal file
155
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/pojo.mustache
vendored
Normal file
@ -0,0 +1,155 @@
|
||||
|
||||
{{#jsonb}}
|
||||
import java.lang.reflect.Type;
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbTypeDeserializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbTypeSerializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.DeserializationContext;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.JsonbDeserializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.JsonbSerializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.SerializationContext;
|
||||
import {{rootJavaEEPackage}}.json.stream.JsonGenerator;
|
||||
import {{rootJavaEEPackage}}.json.stream.JsonParser;
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbProperty;
|
||||
{{#vendorExtensions.x-has-readonly-properties}}
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbCreator;
|
||||
{{/vendorExtensions.x-has-readonly-properties}}
|
||||
{{/jsonb}}
|
||||
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{.}}}
|
||||
**/
|
||||
{{/description}}
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensions.x-implements}}{{#-first}} implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
|
||||
{{#vars}}{{#isEnum}}{{^isContainer}}
|
||||
{{>enumClass}}{{/isContainer}}{{#isContainer}}{{#mostInnerItems}}
|
||||
{{>enumClass}}{{/mostInnerItems}}{{/isContainer}}{{/isEnum}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{.}}}
|
||||
**/
|
||||
{{/description}}
|
||||
{{#vendorExtensions.x-field-extra-annotation}}
|
||||
{{{vendorExtensions.x-field-extra-annotation}}}
|
||||
{{/vendorExtensions.x-field-extra-annotation}}
|
||||
{{#isContainer}}
|
||||
private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}};
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
{{#vendorExtensions.x-has-readonly-properties}}{{#jsonb}}
|
||||
public {{classname}}() {
|
||||
}
|
||||
|
||||
@JsonbCreator
|
||||
public {{classname}}(
|
||||
{{#readOnlyVars}}
|
||||
@JsonbProperty("{{baseName}}") {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
|
||||
{{/readOnlyVars}}
|
||||
) {
|
||||
{{#readOnlyVars}}
|
||||
this.{{name}} = {{name}};
|
||||
{{/readOnlyVars}}
|
||||
}
|
||||
{{/jsonb}}{{/vendorExtensions.x-has-readonly-properties}}
|
||||
{{#vars}}
|
||||
/**
|
||||
{{#description}}
|
||||
* {{.}}
|
||||
{{/description}}
|
||||
{{^description}}
|
||||
* Get {{name}}
|
||||
{{/description}}
|
||||
{{#minimum}}
|
||||
* minimum: {{.}}
|
||||
{{/minimum}}
|
||||
{{#maximum}}
|
||||
* maximum: {{.}}
|
||||
{{/maximum}}
|
||||
* @return {{name}}
|
||||
{{#deprecated}}
|
||||
* @deprecated
|
||||
{{/deprecated}}
|
||||
**/
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{#vendorExtensions.x-extra-annotation}}
|
||||
{{{vendorExtensions.x-extra-annotation}}}
|
||||
{{/vendorExtensions.x-extra-annotation}}
|
||||
{{#withXml}}{{#isEnum}}{{^isArray}}{{^isMap}}public {{dataType}} {{getter}}() {
|
||||
if ({{name}} == null) {
|
||||
return null;
|
||||
}
|
||||
return {{name}}.value();
|
||||
}{{/isMap}}{{/isArray}}{{/isEnum}}{{/withXml}}{{^withXml}}{{#isEnum}}{{^isArray}}{{^isMap}}public {{datatypeWithEnum}} {{getter}}() {
|
||||
return {{name}};
|
||||
}{{/isMap}}{{/isArray}}{{/isEnum}}{{/withXml}}{{#isEnum}}{{#isArray}}public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}{{/isArray}}{{/isEnum}}{{#isEnum}}{{#isMap}}public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}{{/isMap}}{{/isEnum}}{{^isEnum}}public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}{{/isEnum}}
|
||||
|
||||
{{^isReadOnly}}
|
||||
/**
|
||||
* Set {{name}}
|
||||
**/
|
||||
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
return this;
|
||||
}
|
||||
{{#isArray}}
|
||||
|
||||
public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
this.{{name}}.add({{name}}Item);
|
||||
return this;
|
||||
}
|
||||
{{/isArray}}
|
||||
{{#isMap}}
|
||||
|
||||
public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
this.{{name}}.put(key, {{name}}Item);
|
||||
return this;
|
||||
}
|
||||
{{/isMap}}
|
||||
{{/isReadOnly}}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
/**
|
||||
* Create a string representation of this pojo.
|
||||
**/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
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("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private static String toIndentedString(Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
37
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/pojo_doc.mustache
vendored
Normal file
37
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/pojo_doc.mustache
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
# {{#vendorExtensions.x-is-one-of-interface}}Interface {{/vendorExtensions.x-is-one-of-interface}}{{classname}}
|
||||
|
||||
{{#description}}{{&description}}
|
||||
{{/description}}
|
||||
{{^vendorExtensions.x-is-one-of-interface}}
|
||||
|
||||
## Properties
|
||||
|
||||
| Name | Type | Description | Notes |
|
||||
|------------ | ------------- | ------------- | -------------|
|
||||
{{#vars}}|**{{name}}** | {{#isEnum}}[**{{datatypeWithEnum}}**](#{{datatypeWithEnum}}){{/isEnum}}{{^isEnum}}{{#isContainer}}{{#isArray}}{{#items}}{{#isModel}}[{{/isModel}}{{/items}}**{{baseType}}{{#items}}<{{dataType}}>**{{#isModel}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isModel}}{{/items}}{{/isArray}}{{#isMap}}{{#items}}{{#isModel}}[{{/isModel}}**Map<String, {{dataType}}>**{{#isModel}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isModel}}{{/items}}{{/isMap}}{{/isContainer}}{{^isContainer}}{{#isModel}}[{{/isModel}}**{{dataType}}**{{#isModel}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isModel}}{{/isContainer}}{{/isEnum}} | {{description}} | {{^required}} [optional]{{/required}}{{#isReadOnly}} [readonly]{{/isReadOnly}} |
|
||||
{{/vars}}
|
||||
{{#vars}}{{#isEnum}}
|
||||
|
||||
|
||||
## Enum: {{datatypeWithEnum}}
|
||||
|
||||
| Name | Value |
|
||||
|---- | -----|{{#allowableValues}}{{#enumVars}}
|
||||
| {{name}} | {{value}} |{{/enumVars}}{{/allowableValues}}
|
||||
{{/isEnum}}{{/vars}}
|
||||
{{#vendorExtensions.x-implements.0}}
|
||||
|
||||
## Implemented Interfaces
|
||||
|
||||
{{#vendorExtensions.x-implements}}
|
||||
* {{{.}}}
|
||||
{{/vendorExtensions.x-implements}}
|
||||
{{/vendorExtensions.x-implements.0}}
|
||||
{{/vendorExtensions.x-is-one-of-interface}}
|
||||
{{#vendorExtensions.x-is-one-of-interface}}
|
||||
## Implementing Classes
|
||||
|
||||
{{#oneOf}}
|
||||
* {{{.}}}
|
||||
{{/oneOf}}
|
||||
{{/vendorExtensions.x-is-one-of-interface}}
|
90
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/pom.mustache
vendored
Normal file
90
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/mp/pom.mustache
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<parent>
|
||||
<groupId>io.helidon.applications</groupId>
|
||||
<artifactId>helidon-mp</artifactId>
|
||||
<version>{{helidonVersion}}</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<url>{{artifactUrl}}</url>
|
||||
<description>{{artifactDescription}}</description>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.helidon.microprofile.rest-client</groupId>
|
||||
<artifactId>helidon-microprofile-rest-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.helidon.microprofile.config</groupId>
|
||||
<artifactId>helidon-microprofile-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.ext.cdi</groupId>
|
||||
<artifactId>jersey-cdi1x</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>{{x-helidon-rootJavaEEDepPrefix}}.enterprise</groupId>
|
||||
<artifactId>{{x-helidon-rootJavaEEDepPrefix}}.enterprise.cdi-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>{{x-helidon-rootJavaEEDepPrefix}}.json</groupId>
|
||||
<artifactId>{{x-helidon-rootJavaEEDepPrefix}}.json-api</artifactId>
|
||||
</dependency>
|
||||
{{#jackson}}
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>jackson-databind-nullable</artifactId>
|
||||
<version>0.2.2</version>
|
||||
</dependency>
|
||||
{{/jackson}}
|
||||
{{#jsonb}}
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-binding</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>{{x-helidon-rootJavaEEDepPrefix}}.json.bind</groupId>
|
||||
<artifactId>{{x-helidon-rootJavaEEDepPrefix}}.json.bind-api</artifactId>
|
||||
</dependency>
|
||||
{{/jsonb}}
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-libs</id>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jboss.jandex</groupId>
|
||||
<artifactId>jandex-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-index</id>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
{{#isQueryParam}}@QueryParam("{{baseName}}") {{^isContainer}}{{#defaultValue}}@DefaultValue("{{{.}}}") {{/defaultValue}}{{/isContainer}}{{{dataType}}} {{paramName}}{{/isQueryParam}}
|
@ -0,0 +1,4 @@
|
||||
{{#useGenericResponse}}Response{{/useGenericResponse}}{{! non-generic response:
|
||||
}}{{^useGenericResponse}}{{!
|
||||
}}{{{returnType}}}{{!
|
||||
}}{{/useGenericResponse}}
|
@ -0,0 +1,17 @@
|
||||
{{#jackson}}
|
||||
|
||||
@JsonIgnoreProperties(
|
||||
value = "{{{discriminator.propertyBaseName}}}", // ignore manually set {{{discriminator.propertyBaseName}}}, it will be automatically generated by Jackson during serialization
|
||||
allowSetters = true // allows the {{{discriminator.propertyBaseName}}} to be set during deserialization
|
||||
)
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminator.propertyBaseName}}}", visible = true)
|
||||
{{#discriminator.mappedModels}}
|
||||
{{#-first}}
|
||||
@JsonSubTypes({
|
||||
{{/-first}}
|
||||
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
|
||||
{{#-last}}
|
||||
})
|
||||
{{/-last}}
|
||||
{{/discriminator.mappedModels}}
|
||||
{{/jackson}}
|
276
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/ApiClient.mustache
vendored
Normal file
276
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/ApiClient.mustache
vendored
Normal file
@ -0,0 +1,276 @@
|
||||
{{>licenseInfo}}
|
||||
package {{invokerPackage}};
|
||||
|
||||
{{#jsonb}}import {{rootJavaEEPackage}}.json.bind.JsonbBuilder;
|
||||
import {{rootJavaEEPackage}}.json.bind.JsonbConfig;
|
||||
{{/jsonb}}
|
||||
{{#jackson}}import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
{{/jackson}}
|
||||
{{#openApiNullable}}
|
||||
{{#jackson}}
|
||||
import org.openapitools.jackson.nullable.JsonNullableModule;
|
||||
{{/jackson}}
|
||||
{{/openApiNullable}}
|
||||
|
||||
import io.helidon.config.Config;
|
||||
{{#jsonb}}
|
||||
import io.helidon.media.jsonb.JsonbSupport;
|
||||
{{/jsonb}}
|
||||
{{#jackson}}
|
||||
import io.helidon.media.jackson.JacksonSupport;
|
||||
{{/jackson}}
|
||||
import io.helidon.webclient.WebClient;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.time.Duration;
|
||||
{{#java8}}
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
{{/java8}}
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
{{#jsonb}}
|
||||
import java.util.Map;
|
||||
{{/jsonb}}
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* Configuration and utility class for API clients.
|
||||
* <p>
|
||||
* Use the {@link ApiClient.Builder} class to prepare and ultimately create the {@code ApiClient} instance.
|
||||
* </p>
|
||||
*/
|
||||
public class ApiClient {
|
||||
|
||||
private final WebClient webClient;
|
||||
|
||||
/**
|
||||
* @return a {@code Builder} for an {@code ApiClient}
|
||||
*/
|
||||
public static ApiClient.Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* URL encode a string in the UTF-8 encoding.
|
||||
*
|
||||
* @param s String to encode.
|
||||
* @return URL-encoded representation of the input string.
|
||||
*/
|
||||
public static String urlEncode(String s) {
|
||||
return URLEncoder.encode(s, UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a URL query name/value parameter to a list of encoded {@link Pair}
|
||||
* objects.
|
||||
*
|
||||
* <p>The value can be null, in which case an empty list is returned.</p>
|
||||
*
|
||||
* @param name The query name parameter.
|
||||
* @param value The query value, which may not be a collection but may be
|
||||
* null.
|
||||
* @return A singleton list of the {@link Pair} objects representing the input
|
||||
* parameters, which is encoded for use in a URL. If the value is null, an
|
||||
* empty list is returned.
|
||||
*/
|
||||
public static List<Pair> parameterToPairs(String name, Object value) {
|
||||
if (name == null || name.isEmpty() || value == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(new Pair(urlEncode(name), urlEncode(valueToString(value))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a URL query name/collection parameter to a list of encoded
|
||||
* {@link Pair} objects.
|
||||
*
|
||||
* @param collectionFormat The swagger collectionFormat string (csv, tsv, etc).
|
||||
* @param name The query name parameter.
|
||||
* @param values A collection of values for the given query name, which may be
|
||||
* null.
|
||||
* @return A list of {@link Pair} objects representing the input parameters,
|
||||
* which is encoded for use in a URL. If the values collection is null, an
|
||||
* empty list is returned.
|
||||
*/
|
||||
public static List<Pair> parameterToPairs(
|
||||
String collectionFormat, String name, Collection<?> values) {
|
||||
if (name == null || name.isEmpty() || values == null || values.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// get the collection format (default: csv)
|
||||
String format = collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat;
|
||||
|
||||
// create the params based on the collection format
|
||||
if ("multi".equals(format)) {
|
||||
return values.stream()
|
||||
.map(value -> new Pair(urlEncode(name), urlEncode(valueToString(value))))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
String delimiter;
|
||||
switch(format) {
|
||||
case "csv":
|
||||
delimiter = urlEncode(",");
|
||||
break;
|
||||
case "ssv":
|
||||
delimiter = urlEncode(" ");
|
||||
break;
|
||||
case "tsv":
|
||||
delimiter = urlEncode("\t");
|
||||
break;
|
||||
case "pipes":
|
||||
delimiter = urlEncode("|");
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal collection format: " + collectionFormat);
|
||||
}
|
||||
|
||||
StringJoiner joiner = new StringJoiner(delimiter);
|
||||
for (Object value : values) {
|
||||
joiner.add(urlEncode(valueToString(value)));
|
||||
}
|
||||
|
||||
return Collections.singletonList(new Pair(urlEncode(name), joiner.toString()));
|
||||
}
|
||||
|
||||
private ApiClient(Builder builder) {
|
||||
webClient = builder.webClientBuilder().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link WebClient} prepared by the builder of this {@code ApiClient}.
|
||||
*
|
||||
* @return the WebClient
|
||||
*/
|
||||
public WebClient webClient() {
|
||||
return webClient;
|
||||
}
|
||||
|
||||
private static String valueToString(Object value) {
|
||||
if (value == null) {
|
||||
return "";
|
||||
}
|
||||
{{#java8}}
|
||||
if (value instanceof OffsetDateTime) {
|
||||
return ((OffsetDateTime) value).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
}
|
||||
{{/java8}}
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for creating a new {@code ApiClient} instance.
|
||||
*
|
||||
* <p>
|
||||
* The builder accepts a {@link WebClient.Builder} via the {@code webClientBuilder} method but will provide a default one
|
||||
* using available configuration (the {@code client} node) and the base URI set in the OpenAPI document.
|
||||
* </p>
|
||||
*/
|
||||
public static class Builder {
|
||||
|
||||
private WebClient.Builder webClientBuilder;
|
||||
private Config clientConfig;
|
||||
{{#jsonb}}
|
||||
private JsonbConfig jsonbConfig;
|
||||
{{/jsonb}}
|
||||
{{#jackson}}
|
||||
private ObjectMapper objectMapper;
|
||||
{{/jackson}}
|
||||
|
||||
public ApiClient build() {
|
||||
return new ApiClient(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@code WebClient.Builder} which the {@code ApiClient.Builder} uses. Any previous setting is discarded.
|
||||
*
|
||||
* @param webClientBuilder the {@code WebClient.Builder} to be used going forward
|
||||
* @return the updated builder
|
||||
*/
|
||||
public Builder webClientBuilder(WebClient.Builder webClientBuilder) {
|
||||
this.webClientBuilder = webClientBuilder;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the client {@code Config} which the {@code ApiClient.Builder} uses in preparing a default {@code WebClient.Builder}.
|
||||
* The builder ignores this setting if you provide your own {@code WebClient.Builder} by invoking the
|
||||
* {@code webClientBuilder} method.
|
||||
*
|
||||
* @param clientConfig the {@code Config} node containing client settings
|
||||
* @return the updated builder
|
||||
*/
|
||||
public Builder clientConfig(Config clientConfig) {
|
||||
this.clientConfig = clientConfig;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the previously-stored web client builder or, if none, a default one using the provided or defaulted
|
||||
* client configuration
|
||||
*/
|
||||
public WebClient.Builder webClientBuilder() {
|
||||
if (webClientBuilder == null) {
|
||||
webClientBuilder = defaultWebClientBuilder();
|
||||
}
|
||||
return webClientBuilder;
|
||||
}
|
||||
|
||||
{{#jsonb}}
|
||||
/**
|
||||
* Stores the JSON-B configuration the builder uses in preparing the {@code WebClient}.
|
||||
*
|
||||
* @param jsonbConfig the JSON-B config to use in all API invocations via the built {@code ApiClient}
|
||||
* @return the updated builder
|
||||
*/
|
||||
public Builder jsonbConfig(JsonbConfig jsonbConfig) {
|
||||
this.jsonbConfig = jsonbConfig;
|
||||
return this;
|
||||
}
|
||||
{{/jsonb}}
|
||||
{{#jackson}}
|
||||
/**
|
||||
* Stores the Jackson {@code ObjectMapper} the builder uses in preparing the {@code WebClient}.
|
||||
*
|
||||
* @param objectMapper the Jackson object mapper to use in all API invocations via the built {@code ApiClient}
|
||||
* @return the updated builder
|
||||
*/
|
||||
public Builder objectMapper(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
return this;
|
||||
}
|
||||
{{/jackson}}
|
||||
|
||||
private WebClient.Builder defaultWebClientBuilder() {
|
||||
WebClient.Builder defaultWebClientBuilder = WebClient.builder()
|
||||
.baseUri("{{basePath}}")
|
||||
.config(clientConfig());
|
||||
{{#jsonb}}
|
||||
defaultWebClientBuilder.addMediaSupport(jsonbConfig == null
|
||||
? JsonbSupport.create()
|
||||
: JsonbSupport.create(jsonbConfig));
|
||||
{{/jsonb}}
|
||||
{{#jackson}}
|
||||
defaultWebClientBuilder.addMediaSupport(objectMapper == null
|
||||
? JacksonSupport.create()
|
||||
: JacksonSupport.create(objectMapper));
|
||||
{{/jackson}}
|
||||
return defaultWebClientBuilder;
|
||||
}
|
||||
|
||||
private Config clientConfig() {
|
||||
if (clientConfig == null) {
|
||||
clientConfig = Config.create().get("client");
|
||||
}
|
||||
return clientConfig;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
{{>licenseInfo}}
|
||||
package {{invokerPackage}};
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import io.helidon.common.GenericType;
|
||||
import io.helidon.common.reactive.Single;
|
||||
import io.helidon.webclient.WebClientResponse;
|
||||
|
||||
{{#appName}}
|
||||
/**
|
||||
* Generic-typed response.
|
||||
*
|
||||
* Return type for generated API methods.
|
||||
*
|
||||
* @param <T> type of the return value from the generated API method
|
||||
*/
|
||||
{{/appName}}
|
||||
public interface ApiResponse<T> {
|
||||
|
||||
static <T> ApiResponse<T> create(GenericType<T> responseType, Single<WebClientResponse> webClientResponse) {
|
||||
return new ApiResponseBase<>(responseType, webClientResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns reactive access to the {@link WebClientResponse} describing the response from the server
|
||||
*/
|
||||
Single<WebClientResponse> webClientResponse();
|
||||
|
||||
/**
|
||||
* @return reactive access to the value returned in the response from the server
|
||||
*/
|
||||
Single<T> result() throws ExecutionException, InterruptedException;
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
{{>licenseInfo}}
|
||||
package {{invokerPackage}};
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import io.helidon.common.GenericType;
|
||||
import io.helidon.common.reactive.Single;
|
||||
import io.helidon.webclient.WebClientResponse;
|
||||
|
||||
{{#appName}}
|
||||
/**
|
||||
* Implementation of a generic-typed response.
|
||||
*
|
||||
* @param <T> type of the return value from the generated API method
|
||||
*/
|
||||
{{/appName}}
|
||||
class ApiResponseBase<T> implements ApiResponse<T> {
|
||||
|
||||
private final Single<WebClientResponse> webClientResponse;
|
||||
private final GenericType<T> responseType;
|
||||
|
||||
protected ApiResponseBase(GenericType<T> responseType, Single<WebClientResponse> webClientResponse) {
|
||||
this.webClientResponse = webClientResponse;
|
||||
this.responseType = responseType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<WebClientResponse> webClientResponse() {
|
||||
return webClientResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<T> result() throws ExecutionException, InterruptedException {
|
||||
return webClientResponse.get().content().as(responseType);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
{{>licenseInfo}}
|
||||
package {{invokerPackage}};
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
|
||||
/**
|
||||
* Class that add parsing/formatting support for Java 8+ {@code OffsetDateTime} class.
|
||||
* It's generated for java clients when {@code AbstractJavaCodegen#dateLibrary} specified as {@code java8}.
|
||||
*/
|
||||
{{>generatedAnnotation}}
|
||||
public class JavaTimeFormatter {
|
||||
|
||||
private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||
|
||||
/**
|
||||
* Get the date format used to parse/format {@code OffsetDateTime} parameters.
|
||||
* @return DateTimeFormatter
|
||||
*/
|
||||
public DateTimeFormatter getOffsetDateTimeFormatter() {
|
||||
return offsetDateTimeFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the date format used to parse/format {@code OffsetDateTime} parameters.
|
||||
* @param offsetDateTimeFormatter {@code DateTimeFormatter}
|
||||
*/
|
||||
public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) {
|
||||
this.offsetDateTimeFormatter = offsetDateTimeFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given string into {@code OffsetDateTime} object.
|
||||
* @param str String
|
||||
* @return {@code OffsetDateTime}
|
||||
*/
|
||||
public OffsetDateTime parseOffsetDateTime(String str) {
|
||||
try {
|
||||
return OffsetDateTime.parse(str, offsetDateTimeFormatter);
|
||||
} catch (DateTimeParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Format the given {@code OffsetDateTime} object into string.
|
||||
* @param offsetDateTime {@code OffsetDateTime}
|
||||
* @return {@code OffsetDateTime} in string format
|
||||
*/
|
||||
public String formatOffsetDateTime(OffsetDateTime offsetDateTime) {
|
||||
return offsetDateTimeFormatter.format(offsetDateTime);
|
||||
}
|
||||
}
|
45
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/Pair.mustache
vendored
Normal file
45
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/Pair.mustache
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{invokerPackage}};
|
||||
|
||||
public class Pair {
|
||||
private String name = "";
|
||||
private String value = "";
|
||||
|
||||
public Pair (String name, String value) {
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
private void setName(String name) {
|
||||
if (!isValidString(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private void setValue(String value) {
|
||||
if (!isValidString(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
private boolean isValidString(String arg) {
|
||||
if (arg == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
26
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/README.mustache
vendored
Normal file
26
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/README.mustache
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
# {{appName}}
|
||||
|
||||
{{#appDescriptionWithNewLines}}
|
||||
{{{.}}}
|
||||
|
||||
{{/appDescriptionWithNewLines}}
|
||||
|
||||
## Overview
|
||||
This project was generated using the Helidon OpenAPI Generator.
|
||||
|
||||
The generated classes use the programming model from the Helidon WebClient implementation, primarily the `WebClient` interface and its
|
||||
`WebClient.Builder` class. Refer to the Helidon WebClient documentation for complete information about them.
|
||||
|
||||
## Using the Generated Classes and Interfaces
|
||||
The generated `ApiClient` class wraps a `WebClient` instance. Similarly, the `ApiClient.Builder` class wraps the `WebClient.Builder` class.
|
||||
|
||||
The generated `xxxApi` interfaces and `xxxApiImpl` classes make it very simple for your code to send requests (with input parameters) to the remote service which the OpenAPI document describes and to process the response (with output values) from the remote service.
|
||||
|
||||
To use the generated API, your code performs the following steps.
|
||||
|
||||
1. Create an instance of the `ApiClient` using its `Builder`.
|
||||
2. Create an instance of a `xxxApi` it wants to access, typically by invoking `xxxApiImpl.create(ApiClient)` and passing the `ApiClient` instance just created.
|
||||
3. Invoke any of the `public` methods on the `xxxApi` instance, passing the input parameters and saving the returned `Single<WebClientResponse>` object.
|
||||
4. Invoke methods on the returned `Single<WebClientResponse>` to process the response and any output from it.
|
||||
|
||||
Browse the methods and JavaDoc on the generated classes for more information.
|
@ -0,0 +1,46 @@
|
||||
{{>licenseInfo}}
|
||||
package {{invokerPackage}};
|
||||
|
||||
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.text.DecimalFormat;
|
||||
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();
|
||||
this.numberFormat = new DecimalFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date parse(String source) {
|
||||
return parse(source, new ParsePosition(0));
|
||||
}
|
||||
|
||||
@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 super.clone();
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
{{>licenseInfo}}
|
||||
package {{apiPackage}};
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import io.helidon.common.GenericType;
|
||||
|
||||
class ResponseType<T> {
|
||||
|
||||
static <T> GenericType<T> create(Type rawType, Type... typeParams) {
|
||||
return typeParams.length == 0
|
||||
? GenericType.create(rawType)
|
||||
: GenericType.create(new ParameterizedType() {
|
||||
|
||||
@Override
|
||||
public Type[] getActualTypeArguments() {
|
||||
return typeParams;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getRawType() {
|
||||
return rawType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getOwnerType() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{invokerPackage}};
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class StringUtil {
|
||||
/**
|
||||
* Check if the given array contains the given value (with case-insensitive comparison).
|
||||
*
|
||||
* @param array The array
|
||||
* @param value The value to search
|
||||
* @return true if the array contains the value
|
||||
*/
|
||||
public static boolean containsIgnoreCase(String[] array, String value) {
|
||||
for (String str : array) {
|
||||
if (value == null && str == null) {
|
||||
return true;
|
||||
}
|
||||
if (value != null && value.equalsIgnoreCase(str)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join an array of strings with the given separator.
|
||||
* <p>
|
||||
* Note: This might be replaced by utility method from commons-lang or guava someday
|
||||
* if one of those libraries is added as dependency.
|
||||
* </p>
|
||||
*
|
||||
* @param array The array of strings
|
||||
* @param separator The separator
|
||||
* @return the resulting string
|
||||
*/
|
||||
public static String join(String[] array, String separator) {
|
||||
int len = array.length;
|
||||
if (len == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
out.append(array[0]);
|
||||
for (int i = 1; i < len; i++) {
|
||||
out.append(separator).append(array[i]);
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Join a list of strings with the given separator.
|
||||
*
|
||||
* @param list The list of strings
|
||||
* @param separator The separator
|
||||
* @return the resulting string
|
||||
*/
|
||||
public static String join(Collection<String> list, String separator) {
|
||||
Iterator<String> iterator = list.iterator();
|
||||
StringBuilder out = new StringBuilder();
|
||||
if (iterator.hasNext()) {
|
||||
out.append(iterator.next());
|
||||
}
|
||||
while (iterator.hasNext()) {
|
||||
out.append(separator).append(iterator.next());
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
{{#additionalEnumTypeAnnotations}}{{{.}}}
|
||||
{{/additionalEnumTypeAnnotations}}
|
@ -0,0 +1,2 @@
|
||||
{{#additionalModelTypeAnnotations}}{{{.}}}
|
||||
{{/additionalModelTypeAnnotations}}
|
43
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/api.mustache
vendored
Normal file
43
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/api.mustache
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
{{>licenseInfo}}
|
||||
package {{package}};
|
||||
|
||||
import {{invokerPackage}}.ApiResponse;
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
{{#appName}}
|
||||
/**
|
||||
* {{{appName}}}
|
||||
*
|
||||
{{#appDescription}}
|
||||
* <p>{{{.}}}
|
||||
{{/appDescription}}
|
||||
*/
|
||||
{{/appName}}
|
||||
public interface {{classname}} {
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
{{#summary}}
|
||||
/**
|
||||
* {{summary}}
|
||||
{{#notes}}
|
||||
* {{.}}
|
||||
{{/notes}}
|
||||
{{#allParams}}
|
||||
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/isContainer}}{{/required}}
|
||||
{{/allParams}}
|
||||
* @return {@code {{>operationResponseSig}}}
|
||||
{{#isDeprecated}}
|
||||
* @deprecated
|
||||
{{/isDeprecated}}
|
||||
*/
|
||||
{{/summary}}
|
||||
{{#isDeprecated}}
|
||||
@Deprecated
|
||||
{{/isDeprecated}}
|
||||
{{>operationResponseSig}} {{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
{{>licenseInfo}}
|
||||
package {{invokerPackage}};
|
||||
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
|
||||
public class ApiOperation {
|
||||
private final String path;
|
||||
private final String method;
|
||||
private final Operation operation;
|
||||
|
||||
public ApiOperation(String path, String method, Operation operation) {
|
||||
this.path = path;
|
||||
this.method = method;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public Operation getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
}
|
108
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/api_doc.mustache
vendored
Normal file
108
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/api_doc.mustache
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
# {{classname}}{{#description}}
|
||||
|
||||
{{.}}{{/description}}
|
||||
|
||||
All URIs are relative to *{{basePath}}*
|
||||
|
||||
| Method | HTTP request | Description |
|
||||
|------------- | ------------- | -------------|
|
||||
{{#operations}}{{#operation}}| [**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{commonPath}}{{path}} | {{summary}} |
|
||||
{{/operation}}{{/operations}}
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
|
||||
## {{operationId}}
|
||||
|
||||
> {{#returnType}}{{.}} {{/returnType}}{{operationId}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
|
||||
{{summary}}{{#notes}}
|
||||
|
||||
{{.}}{{/notes}}
|
||||
|
||||
### Example
|
||||
|
||||
```java
|
||||
// Import classes:
|
||||
import {{{invokerPackage}}}.ApiClient;
|
||||
import {{{invokerPackage}}}.ApiException;
|
||||
import {{{invokerPackage}}}.Configuration;{{#hasAuthMethods}}
|
||||
import {{{invokerPackage}}}.auth.*;{{/hasAuthMethods}}
|
||||
import {{{invokerPackage}}}.models.*;
|
||||
import {{{package}}}.{{{classname}}};
|
||||
|
||||
public class Example {
|
||||
public static void main(String[] args) {
|
||||
ApiClient defaultClient = Configuration.getDefaultApiClient();
|
||||
defaultClient.setBasePath("{{{basePath}}}");
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
|
||||
// Configure HTTP basic authorization: {{{name}}}
|
||||
HttpBasicAuth {{{name}}} = (HttpBasicAuth) defaultClient.getAuthentication("{{{name}}}");
|
||||
{{{name}}}.setUsername("YOUR USERNAME");
|
||||
{{{name}}}.setPassword("YOUR PASSWORD");{{/isBasicBasic}}{{#isBasicBearer}}
|
||||
// Configure HTTP bearer authorization: {{{name}}}
|
||||
HttpBearerAuth {{{name}}} = (HttpBearerAuth) defaultClient.getAuthentication("{{{name}}}");
|
||||
{{{name}}}.setBearerToken("BEARER TOKEN");{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
|
||||
// Configure API key authorization: {{{name}}}
|
||||
ApiKeyAuth {{{name}}} = (ApiKeyAuth) defaultClient.getAuthentication("{{{name}}}");
|
||||
{{{name}}}.setApiKey("YOUR API KEY");
|
||||
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
|
||||
//{{{name}}}.setApiKeyPrefix("Token");{{/isApiKey}}{{#isOAuth}}
|
||||
// Configure OAuth2 access token for authorization: {{{name}}}
|
||||
OAuth {{{name}}} = (OAuth) defaultClient.getAuthentication("{{{name}}}");
|
||||
{{{name}}}.setAccessToken("YOUR ACCESS TOKEN");{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
{{/hasAuthMethods}}
|
||||
|
||||
{{{classname}}} apiInstance = new {{{classname}}}(defaultClient);
|
||||
{{#allParams}}
|
||||
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
|
||||
{{/allParams}}
|
||||
try {
|
||||
{{#returnType}}{{{.}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});{{#returnType}}
|
||||
System.out.println(result);{{/returnType}}
|
||||
} catch (ApiException e) {
|
||||
System.err.println("Exception when calling {{{classname}}}#{{{operationId}}}");
|
||||
System.err.println("Status code: " + e.getCode());
|
||||
System.err.println("Reason: " + e.getResponseBody());
|
||||
System.err.println("Response headers: " + e.getResponseHeaders());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
|
||||
| Name | Type | Description | Notes |
|
||||
|------------- | ------------- | ------------- | -------------|{{/-last}}{{/allParams}}
|
||||
{{#allParams}}| **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} |{{^required}} [optional]{{/required}}{{^isContainer}}{{#defaultValue}} [default to {{.}}]{{/defaultValue}}{{/isContainer}}{{#allowableValues}} [enum: {{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}]{{/allowableValues}} |
|
||||
{{/allParams}}
|
||||
|
||||
### Return type
|
||||
|
||||
{{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}null (empty response body){{/returnType}}
|
||||
|
||||
### Authorization
|
||||
|
||||
{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}}
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: {{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
|
||||
- **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}}
|
||||
|
||||
{{#responses.0}}
|
||||
|
||||
### HTTP response details
|
||||
| Status code | Description | Response headers |
|
||||
|-------------|-------------|------------------|
|
||||
{{#responses}}
|
||||
| **{{code}}** | {{message}} | {{#headers}} * {{baseName}} - {{description}} <br> {{/headers}}{{^headers.0}} - {{/headers.0}} |
|
||||
{{/responses}}
|
||||
{{/responses.0}}
|
||||
|
||||
{{/operation}}
|
||||
{{/operations}}
|
182
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/api_impl.mustache
vendored
Normal file
182
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/api_impl.mustache
vendored
Normal file
@ -0,0 +1,182 @@
|
||||
{{>licenseInfo}}
|
||||
package {{package}};
|
||||
|
||||
import java.util.Objects;
|
||||
import {{invokerPackage}}.ApiResponse;
|
||||
|
||||
{{#jsonb}}
|
||||
import {{rootJavaEEPackage}}.json.bind.JsonbBuilder;
|
||||
{{/jsonb}}
|
||||
{{#jackson}}
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
{{/jackson}}
|
||||
|
||||
import io.helidon.common.GenericType;
|
||||
import io.helidon.common.http.MediaType;
|
||||
import io.helidon.common.reactive.Single;
|
||||
import io.helidon.config.Config;
|
||||
import io.helidon.media.common.MediaSupport;
|
||||
{{#jsonb}}import io.helidon.media.jsonb.JsonbSupport;{{/jsonb}}
|
||||
{{#jackson}}import io.helidon.media.jackson.JacksonSupport;{{/jackson}}
|
||||
import io.helidon.webclient.WebClientRequestBuilder;
|
||||
import io.helidon.webclient.WebClientResponse;
|
||||
|
||||
import {{invokerPackage}}.ApiClient;
|
||||
|
||||
{{#x-helidon-implImports}}import {{import}};
|
||||
{{/x-helidon-implImports}}
|
||||
|
||||
{{#appName}}
|
||||
/**
|
||||
* {{{appName}}}
|
||||
*
|
||||
{{#appDescription}}
|
||||
* <p>{{{.}}}
|
||||
{{/appDescription}}
|
||||
*/
|
||||
{{/appName}}
|
||||
public class {{classname}}Impl implements {{classname}} {
|
||||
|
||||
private final ApiClient apiClient;
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
protected static final GenericType<{{>operationResponseTypeDecl}}> RESPONSE_TYPE_{{operationId}} = ResponseType.create({{#isArray}}List.class, {{/isArray}}{{#isMap}}Map.class, String.class, {{/isMap}}{{#returnBaseType}}{{returnBaseType}}{{/returnBaseType}}{{^returnBaseType}}Void{{/returnBaseType}}.class);
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
|
||||
/**
|
||||
* Creates a new instance of {{classname}}Impl initialized with the specified {@link ApiClient}.
|
||||
*
|
||||
*/
|
||||
public static {{classname}}Impl create(ApiClient apiClient) {
|
||||
return new {{classname}}Impl(apiClient);
|
||||
}
|
||||
|
||||
protected {{classname}}Impl(ApiClient apiClient) {
|
||||
this.apiClient = apiClient;
|
||||
}
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
{{#isDeprecated}}
|
||||
@Deprecated
|
||||
{{/isDeprecated}}
|
||||
@Override
|
||||
public {{>operationResponseSig}} {{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) {
|
||||
{{#requiredParams}}
|
||||
Objects.requireNonNull({{paramName}}, "Required parameter '{{paramName}}' not specified");
|
||||
{{/requiredParams}}
|
||||
WebClientRequestBuilder webClientRequestBuilder = {{operationId}}RequestBuilder({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
return {{operationId}}Submit(webClientRequestBuilder{{#allParams}}, {{paramName}}{{/allParams}});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code WebClientRequestBuilder} for the {{operationId}} operation.
|
||||
* Optional customization point for subclasses.
|
||||
*
|
||||
{{#allParams}}
|
||||
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/isContainer}}{{/required}}
|
||||
{{/allParams}}
|
||||
* @return WebClientRequestBuilder for {{operationId}}
|
||||
*/
|
||||
protected WebClientRequestBuilder {{operationId}}RequestBuilder({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) {
|
||||
WebClientRequestBuilder webClientRequestBuilder = apiClient.webClient()
|
||||
.method("{{httpMethod}}");
|
||||
|
||||
{{#hasQueryParams}}
|
||||
{{javaUtilPrefix}}List<Pair> queryParams = new {{javaUtilPrefix}}ArrayList<>();
|
||||
{{#queryParams}}
|
||||
{{#collectionFormat}}
|
||||
queryParams.addAll(ApiClient.parameterToPairs("{{{collectionFormat}}}", "{{baseName}}", {{paramName}}));
|
||||
{{/collectionFormat}}
|
||||
{{^collectionFormat}}
|
||||
{{#isDeepObject}}
|
||||
if ({{paramName}} != null) {
|
||||
{{#items.vars}}
|
||||
queryParams.addAll(ApiClient.parameterToPairs({{#isArray}}"csv", {{/isArray}}"{{baseName}}", {{paramName}}.{{getter}}()));
|
||||
{{/items.vars}}
|
||||
}
|
||||
{{/isDeepObject}}
|
||||
{{^isDeepObject}}
|
||||
{{#isExplode}}
|
||||
{{#hasVars}}
|
||||
{{#vars}}
|
||||
queryParams.addAll(ApiClent.parameterToPairs("{{baseName}}", {{paramName}}.{{getter}}()));
|
||||
{{/vars}}
|
||||
{{/hasVars}}
|
||||
{{^hasVars}}
|
||||
queryParams.addAll(ApiClient.parameterToPairs("{{baseName}}", {{paramName}}));
|
||||
{{/hasVars}}
|
||||
{{/isExplode}}
|
||||
{{^isExplode}}
|
||||
queryParams.addAll(ApiClient.parameterToPairs("{{baseName}}", {{paramName}}));
|
||||
{{/isExplode}}
|
||||
{{/isDeepObject}}
|
||||
{{/collectionFormat}}
|
||||
{{/queryParams}}
|
||||
queryParams.forEach(p -> webClientRequestBuilder.queryParam(p.getName(), p.getValue()));
|
||||
|
||||
{{/hasQueryParams}}
|
||||
{{#hasHeaderParams}}
|
||||
WebClientRequestHeaders headers = webClientRequestBuilder.headers();
|
||||
{{#headerParams}}
|
||||
if ({{paramName}} != null) {
|
||||
headers.put("{{baseName}}", {{paramName}}{{^isString}}.toString(){{/isString}});
|
||||
}
|
||||
{{/headerParams}}
|
||||
|
||||
{{/hasHeaderParams}}
|
||||
{{#hasCookieParams}}
|
||||
String cookies = new StringJoiner("; ")
|
||||
{{#cookieParams}}
|
||||
.add("{{{baseName}}}=" + {{{paramName}}})
|
||||
{{/cookieParams}}
|
||||
.toString();
|
||||
webClientRequestBuilder.headers().add("Cookie", cookies);
|
||||
|
||||
{{/hasCookieParams}}
|
||||
{{#hasPathParams}}
|
||||
String path = "{{{path}}}"
|
||||
{{! Switch delimiters from double braces to <% and %> for baseName so we can use curly braces in the string as literals and not have mustache
|
||||
interpret them, then switch back. }}
|
||||
{{#pathParams}}
|
||||
.replace({{=<% %>=}}"{<%baseName%>}"<%={{ }}=%>, ApiClient.urlEncode({{{paramName}}}{{^isString}}.toString(){{/isString}})){{/pathParams}};
|
||||
{{/hasPathParams}}
|
||||
webClientRequestBuilder.path({{#hasPathParams}}path{{/hasPathParams}}{{^hasPathParams}}"{{{path}}}"{{/hasPathParams}});
|
||||
{{#bodyParam}}
|
||||
webClientRequestBuilder.contentType(MediaType.APPLICATION_JSON);
|
||||
{{/bodyParam}}
|
||||
{{#hasFormParams}}
|
||||
webClientRequestBuilder.contentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
{{/hasFormParams}}
|
||||
webClientRequestBuilder.accept(MediaType.APPLICATION_JSON);
|
||||
|
||||
return webClientRequestBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates the request for the {{operationId}} operation.
|
||||
* Optional customization point for subclasses.
|
||||
*
|
||||
* @param webClientRequestBuilder the request builder to use for submitting the request
|
||||
{{#allParams}}
|
||||
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/isContainer}}{{/required}}
|
||||
{{/allParams}}
|
||||
* @return {@code {{>operationResponseSig}}} for the submitted request
|
||||
*/
|
||||
protected {{>operationResponseSig}} {{operationId}}Submit(WebClientRequestBuilder webClientRequestBuilder{{#allParams}}, {{{dataType}}} {{paramName}}{{/allParams}}) {
|
||||
{{#hasFormParams}}
|
||||
String formParams = new StringJoiner("&")
|
||||
{{#formParams}}
|
||||
.add("{{{baseName}}}=" + {{paramName}})
|
||||
{{/formParams}}
|
||||
.toString();
|
||||
{{/hasFormParams}}
|
||||
Single<WebClientResponse> webClientResponse = webClientRequestBuilder.submit({{#bodyParam}}{{paramName}}{{/bodyParam}}{{#hasFormParams}}formParams{{/hasFormParams}});
|
||||
return ApiResponse.create(RESPONSE_TYPE_{{operationId}}, webClientResponse);
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
}
|
72
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/api_test.mustache
vendored
Normal file
72
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/api_test.mustache
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import {{invokerPackage}}.ApiClient;
|
||||
import {{invokerPackage}}.ApiResponse;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
{{^fullJavaUtil}}
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
{{/fullJavaUtil}}
|
||||
|
||||
import io.helidon.common.reactive.Single;
|
||||
import io.helidon.webclient.WebClientResponse;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
/**
|
||||
* {{#appName}}
|
||||
* {{{.}}} Test
|
||||
*
|
||||
* {{/appName}}
|
||||
* API tests for {{classname}}
|
||||
*/
|
||||
public class {{classname}}Test {
|
||||
|
||||
private static ApiClient apiClient;
|
||||
private static {{classname}} api;
|
||||
private static final String baseUrl = "http://localhost:8080";
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
apiClient = ApiClient.builder().build();
|
||||
api = {{classname}}Impl.create(apiClient);
|
||||
}
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{summary}}
|
||||
{{#notes}}
|
||||
* {{.}}
|
||||
{{/notes}}
|
||||
*/
|
||||
@Test
|
||||
public void {{operationId}}Test() {
|
||||
{{#allParams}}
|
||||
// TODO - assign values to the input arguments.
|
||||
{{{dataType}}} {{paramName}} = null;
|
||||
{{/allParams}}
|
||||
|
||||
// TODO - uncomment the following two lines to invoke the service with valid parameters.
|
||||
//ApiResponse<{{>operationResponseTypeDecl}}> response = api.{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
//response.webClientResponse().await();
|
||||
// TODO - check for appropriate return status
|
||||
// assertThat("Return status", response.get().status().code(), is(expectedStatus));
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
}
|
@ -0,0 +1 @@
|
||||
{{#isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}}
|
@ -0,0 +1 @@
|
||||
{{#isCookieParam}}@CookieParam("{{baseName}}"){{^isContainer}}{{#defaultValue}} @DefaultValue("{{{.}}}"){{/defaultValue}}{{/isContainer}} {{#useSwaggerAnnotations}}{{#description}} @ApiParam("{{.}}"){{/description}}{{/useSwaggerAnnotations}} {{{dataType}}} {{paramName}}{{/isCookieParam}}
|
46
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/enumClass.mustache
vendored
Normal file
46
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/enumClass.mustache
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
{{#jsonb}}
|
||||
@JsonbTypeSerializer({{datatypeWithEnum}}.Serializer.class)
|
||||
@JsonbTypeDeserializer({{datatypeWithEnum}}.Deserializer.class)
|
||||
{{/jsonb}}
|
||||
{{>additionalEnumTypeAnnotations}}public enum {{datatypeWithEnum}} {
|
||||
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}{{name}}({{dataType}}.valueOf({{{value}}})){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
|
||||
{{dataType}} value;
|
||||
|
||||
{{datatypeWithEnum}} ({{dataType}} v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public {{dataType}} value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
{{#jsonb}}
|
||||
public static final class Deserializer implements JsonbDeserializer<{{datatypeWithEnum}}> {
|
||||
@Override
|
||||
public {{datatypeWithEnum}} deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
|
||||
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
if (String.valueOf(b.value).equals(parser.getString())) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + parser.getString() + "'");{{/useNullForUnknownEnumValue}}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Serializer implements JsonbSerializer<{{datatypeWithEnum}}> {
|
||||
@Override
|
||||
public void serialize({{datatypeWithEnum}} obj, JsonGenerator generator, SerializationContext ctx) {
|
||||
generator.write(obj.value);
|
||||
}
|
||||
}
|
||||
{{/jsonb}}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
{{#jackson}}
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
{{/jackson}}
|
||||
|
||||
/**
|
||||
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
|
||||
*/
|
||||
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
|
||||
private {{{dataType}}} value;
|
||||
|
||||
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
{{#jackson}}
|
||||
@JsonValue
|
||||
{{/jackson}}
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
{{#jackson}}
|
||||
@JsonCreator
|
||||
{{/jackson}}
|
||||
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue(String text) {
|
||||
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
if (String.valueOf(b.value).equals(text)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
# {{classname}}
|
||||
|
||||
## Enum
|
||||
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
* `{{name}}` (value: `{{{value}}}`)
|
||||
{{/enumVars}}{{/allowableValues}}
|
@ -0,0 +1 @@
|
||||
{{#isFormParam}}@FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isFormParam}}
|
@ -0,0 +1 @@
|
||||
@{{rootJavaEEPackage}}.annotation.Generated(value = "{{generatorClass}}"{{^hideGenerationTimestamp}}, date = "{{generatedDate}}"{{/hideGenerationTimestamp}})
|
@ -0,0 +1 @@
|
||||
{{#isHeaderParam}}@HeaderParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isHeaderParam}}
|
@ -0,0 +1,19 @@
|
||||
{{!
|
||||
If this is map and items are nullable, make sure that nulls are included.
|
||||
To determine what JsonInclude.Include method to use, consider the following:
|
||||
* If the field is required, always include it, even if it is null.
|
||||
* Else use custom behaviour, IOW use whatever is defined on the object mapper
|
||||
}}
|
||||
@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}})
|
||||
@JsonInclude({{#isMap}}{{#items.isNullable}}content = JsonInclude.Include.ALWAYS, {{/items.isNullable}}{{/isMap}}value = JsonInclude.Include.{{#required}}ALWAYS{{/required}}{{^required}}USE_DEFAULTS{{/required}})
|
||||
{{#withXml}}
|
||||
{{^isContainer}}
|
||||
@JacksonXmlProperty({{#isXmlAttribute}}isAttribute = true, {{/isXmlAttribute}}{{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}")
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#isXmlWrapped}}
|
||||
// items.xmlName={{items.xmlName}}
|
||||
@JacksonXmlElementWrapper(useWrapping = {{isXmlWrapped}}, {{#xmlNamespace}}namespace="{{.}}", {{/xmlNamespace}}localName = "{{#items.xmlName}}{{items.xmlName}}{{/items.xmlName}}{{^items.xmlName}}{{items.baseName}}{{/items.xmlName}}")
|
||||
{{/isXmlWrapped}}
|
||||
{{/isContainer}}
|
||||
{{/withXml}}
|
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* {{{appName}}}
|
||||
* {{{appDescription}}}
|
||||
*
|
||||
* {{#version}}The version of the OpenAPI document: {{{.}}}{{/version}}
|
||||
* {{#infoEmail}}Contact: {{{.}}}{{/infoEmail}}
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
@ -0,0 +1,3 @@
|
||||
<manifest package="{{invokerPackage}}" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application />
|
||||
</manifest>
|
31
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/maven.yml.mustache
vendored
Normal file
31
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/maven.yml.mustache
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
#
|
||||
# This file is auto-generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
name: Java CI with Maven
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, master ]
|
||||
pull_request:
|
||||
branches: [ main, master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build {{{appName}}}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
java: [ '8' ]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
{{=< >=}}
|
||||
java-version: ${{ matrix.java }}
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --no-transfer-progress --file pom.xml
|
19
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/model.mustache
vendored
Normal file
19
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/model.mustache
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
{{>licenseInfo}}
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
{{#serializableModel}}
|
||||
import java.io.Serializable;
|
||||
{{/serializableModel}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#isEnum}}
|
||||
{{>enumOuterClass}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{>pojo}}
|
||||
{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
@ -0,0 +1,95 @@
|
||||
/**
|
||||
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
|
||||
*/
|
||||
{{#gson}}
|
||||
@JsonAdapter({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.Adapter.class)
|
||||
{{/gson}}
|
||||
{{#jsonb}}
|
||||
@JsonbTypeSerializer({{datatypeWithEnum}}.Serializer.class)
|
||||
@JsonbTypeDeserializer({{datatypeWithEnum}}.Deserializer.class)
|
||||
{{/jsonb}}
|
||||
{{#withXml}}
|
||||
@XmlType(name="{{datatypeWithEnum}}")
|
||||
@XmlEnum({{dataType}}.class)
|
||||
{{/withXml}}
|
||||
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{#enumDescription}}
|
||||
/**
|
||||
* {{.}}
|
||||
*/
|
||||
{{/enumDescription}}
|
||||
{{#withXml}}
|
||||
@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
|
||||
{{/withXml}}
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
{{/-last}}{{#-last}};{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
|
||||
private {{{dataType}}} value;
|
||||
|
||||
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{{dataType}}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
{{#jackson}}
|
||||
@JsonValue
|
||||
{{/jackson}}
|
||||
public {{{dataType}}} getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
{{#jackson}}
|
||||
@JsonCreator
|
||||
{{/jackson}}
|
||||
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
|
||||
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
if (b.value.equals(value)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||
}
|
||||
{{#gson}}
|
||||
|
||||
public static class Adapter extends TypeAdapter<{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}> {
|
||||
@Override
|
||||
public void write(final JsonWriter jsonWriter, final {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} enumeration) throws IOException {
|
||||
jsonWriter.value(enumeration.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} read(final JsonReader jsonReader) throws IOException {
|
||||
{{^isNumber}}{{{dataType}}}{{/isNumber}}{{#isNumber}}String{{/isNumber}} value = {{#isFloat}}(float){{/isFloat}} jsonReader.{{#isNumber}}nextString(){{/isNumber}}{{#isInteger}}nextInt(){{/isInteger}}{{^isNumber}}{{^isInteger}}{{#isFloat}}nextDouble{{/isFloat}}{{^isFloat}}next{{{dataType}}}{{/isFloat}}(){{/isInteger}}{{/isNumber}};
|
||||
return {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.fromValue({{#isNumber}}new BigDecimal({{/isNumber}}value{{#isNumber}}){{/isNumber}});
|
||||
}
|
||||
}
|
||||
{{/gson}}
|
||||
{{#jsonb}}
|
||||
public static final class Deserializer implements JsonbDeserializer<{{datatypeWithEnum}}> {
|
||||
@Override
|
||||
public {{datatypeWithEnum}} deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
|
||||
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
|
||||
if (String.valueOf(b.value).equals(parser.getString())) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + parser.getString() + "'");{{/useNullForUnknownEnumValue}}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Serializer implements JsonbSerializer<{{datatypeWithEnum}}> {
|
||||
@Override
|
||||
public void serialize({{datatypeWithEnum}} obj, JsonGenerator generator, SerializationContext ctx) {
|
||||
generator.write(obj.value);
|
||||
}
|
||||
}
|
||||
{{/jsonb}}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{{#models}}{{#model}}
|
||||
|
||||
{{#isEnum}}{{>enum_outer_doc}}{{/isEnum}}{{^isEnum}}{{>pojo_doc}}{{/isEnum}}
|
||||
{{/model}}{{/models}}
|
@ -0,0 +1,49 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
{{#fullJavaUtil}}
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
{{/fullJavaUtil}}
|
||||
|
||||
/**
|
||||
* Model tests for {{classname}}
|
||||
*/
|
||||
public class {{classname}}Test {
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{^vendorExtensions.x-is-one-of-interface}}
|
||||
{{^isEnum}}
|
||||
private final {{classname}} model = new {{classname}}();
|
||||
|
||||
{{/isEnum}}
|
||||
/**
|
||||
* Model tests for {{classname}}
|
||||
*/
|
||||
@Test
|
||||
public void test{{classname}}() {
|
||||
// TODO: test {{classname}}
|
||||
}
|
||||
|
||||
{{#allVars}}
|
||||
/**
|
||||
* Test the property '{{name}}'
|
||||
*/
|
||||
@Test
|
||||
public void {{name}}Test() {
|
||||
// TODO: test {{name}}
|
||||
}
|
||||
|
||||
{{/allVars}}
|
||||
{{/vendorExtensions.x-is-one-of-interface}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{>typeInfoAnnotation}}{{>xmlAnnotation}}
|
||||
public interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
|
||||
{{#discriminator}}
|
||||
public {{propertyType}} {{propertyGetter}}();
|
||||
{{/discriminator}}
|
||||
}
|
@ -0,0 +1 @@
|
||||
{{{openapi-yaml}}}
|
@ -0,0 +1 @@
|
||||
ApiResponse<{{>operationResponseTypeDecl}}>
|
@ -0,0 +1 @@
|
||||
{{#returnType}}{{#isArray}}List<{{/isArray}}{{#isMap}}Map<String, {{/isMap}}{{returnBaseType}}{{#isArray}}>{{/isArray}}{{#isMap}}>{{/isMap}}{{/returnType}}{{^returnType}}Void{{/returnType}}
|
@ -0,0 +1 @@
|
||||
{{#isPathParam}}@PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isPathParam}}
|
155
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/pojo.mustache
vendored
Normal file
155
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/pojo.mustache
vendored
Normal file
@ -0,0 +1,155 @@
|
||||
|
||||
{{#jsonb}}
|
||||
import java.lang.reflect.Type;
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbTypeDeserializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbTypeSerializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.DeserializationContext;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.JsonbDeserializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.JsonbSerializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.SerializationContext;
|
||||
import {{rootJavaEEPackage}}.json.stream.JsonGenerator;
|
||||
import {{rootJavaEEPackage}}.json.stream.JsonParser;
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbProperty;
|
||||
{{#vendorExtensions.x-has-readonly-properties}}
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbCreator;
|
||||
{{/vendorExtensions.x-has-readonly-properties}}
|
||||
{{/jsonb}}
|
||||
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{.}}}
|
||||
**/
|
||||
{{/description}}
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{#vendorExtensions.x-class-extra-annotation}}
|
||||
{{{vendorExtensions.x-class-extra-annotation}}}
|
||||
{{/vendorExtensions.x-class-extra-annotation}}
|
||||
public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensions.x-implements}}{{#-first}} implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
|
||||
{{#vars}}{{#isEnum}}{{^isContainer}}
|
||||
{{>enumClass}}{{/isContainer}}{{#isContainer}}{{#mostInnerItems}}
|
||||
{{>enumClass}}{{/mostInnerItems}}{{/isContainer}}{{/isEnum}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{.}}}
|
||||
**/
|
||||
{{/description}}
|
||||
{{#vendorExtensions.x-field-extra-annotation}}
|
||||
{{{vendorExtensions.x-field-extra-annotation}}}
|
||||
{{/vendorExtensions.x-field-extra-annotation}}
|
||||
{{#isContainer}}
|
||||
private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}};
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
{{#vendorExtensions.x-has-readonly-properties}}{{#jsonb}}
|
||||
public {{classname}}() {
|
||||
}
|
||||
|
||||
@JsonbCreator
|
||||
public {{classname}}(
|
||||
{{#readOnlyVars}}
|
||||
@JsonbProperty("{{baseName}}") {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
|
||||
{{/readOnlyVars}}
|
||||
) {
|
||||
{{#readOnlyVars}}
|
||||
this.{{name}} = {{name}};
|
||||
{{/readOnlyVars}}
|
||||
}
|
||||
{{/jsonb}}{{/vendorExtensions.x-has-readonly-properties}}
|
||||
{{#vars}}
|
||||
/**
|
||||
{{#description}}
|
||||
* {{.}}
|
||||
{{/description}}
|
||||
{{^description}}
|
||||
* Get {{name}}
|
||||
{{/description}}
|
||||
{{#minimum}}
|
||||
* minimum: {{.}}
|
||||
{{/minimum}}
|
||||
{{#maximum}}
|
||||
* maximum: {{.}}
|
||||
{{/maximum}}
|
||||
* @return {{name}}
|
||||
{{#deprecated}}
|
||||
* @deprecated
|
||||
{{/deprecated}}
|
||||
**/
|
||||
{{#deprecated}}
|
||||
@Deprecated
|
||||
{{/deprecated}}
|
||||
{{#vendorExtensions.x-extra-annotation}}
|
||||
{{{vendorExtensions.x-extra-annotation}}}
|
||||
{{/vendorExtensions.x-extra-annotation}}
|
||||
{{#withXml}}{{#isEnum}}{{^isArray}}{{^isMap}}public {{dataType}} {{getter}}() {
|
||||
if ({{name}} == null) {
|
||||
return null;
|
||||
}
|
||||
return {{name}}.value();
|
||||
}{{/isMap}}{{/isArray}}{{/isEnum}}{{/withXml}}{{^withXml}}{{#isEnum}}{{^isArray}}{{^isMap}}public {{datatypeWithEnum}} {{getter}}() {
|
||||
return {{name}};
|
||||
}{{/isMap}}{{/isArray}}{{/isEnum}}{{/withXml}}{{#isEnum}}{{#isArray}}public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}{{/isArray}}{{/isEnum}}{{#isEnum}}{{#isMap}}public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}{{/isMap}}{{/isEnum}}{{^isEnum}}public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}{{/isEnum}}
|
||||
|
||||
{{^isReadOnly}}
|
||||
/**
|
||||
* Set {{name}}
|
||||
**/
|
||||
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}}
|
||||
{{/vendorExtensions.x-setter-extra-annotation}}public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
return this;
|
||||
}
|
||||
{{#isArray}}
|
||||
|
||||
public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
this.{{name}}.add({{name}}Item);
|
||||
return this;
|
||||
}
|
||||
{{/isArray}}
|
||||
{{#isMap}}
|
||||
|
||||
public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
|
||||
this.{{name}}.put(key, {{name}}Item);
|
||||
return this;
|
||||
}
|
||||
{{/isMap}}
|
||||
{{/isReadOnly}}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
/**
|
||||
* Create a string representation of this pojo.
|
||||
**/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
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("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private static String toIndentedString(Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
37
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/pojo_doc.mustache
vendored
Normal file
37
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/pojo_doc.mustache
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
# {{#vendorExtensions.x-is-one-of-interface}}Interface {{/vendorExtensions.x-is-one-of-interface}}{{classname}}
|
||||
|
||||
{{#description}}{{&description}}
|
||||
{{/description}}
|
||||
{{^vendorExtensions.x-is-one-of-interface}}
|
||||
|
||||
## Properties
|
||||
|
||||
| Name | Type | Description | Notes |
|
||||
|------------ | ------------- | ------------- | -------------|
|
||||
{{#vars}}|**{{name}}** | {{#isEnum}}[**{{datatypeWithEnum}}**](#{{datatypeWithEnum}}){{/isEnum}}{{^isEnum}}{{#isContainer}}{{#isArray}}{{#items}}{{#isModel}}[{{/isModel}}{{/items}}**{{baseType}}{{#items}}<{{dataType}}>**{{#isModel}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isModel}}{{/items}}{{/isArray}}{{#isMap}}{{#items}}{{#isModel}}[{{/isModel}}**Map<String, {{dataType}}>**{{#isModel}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isModel}}{{/items}}{{/isMap}}{{/isContainer}}{{^isContainer}}{{#isModel}}[{{/isModel}}**{{dataType}}**{{#isModel}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isModel}}{{/isContainer}}{{/isEnum}} | {{description}} | {{^required}} [optional]{{/required}}{{#isReadOnly}} [readonly]{{/isReadOnly}} |
|
||||
{{/vars}}
|
||||
{{#vars}}{{#isEnum}}
|
||||
|
||||
|
||||
## Enum: {{datatypeWithEnum}}
|
||||
|
||||
| Name | Value |
|
||||
|---- | -----|{{#allowableValues}}{{#enumVars}}
|
||||
| {{name}} | {{value}} |{{/enumVars}}{{/allowableValues}}
|
||||
{{/isEnum}}{{/vars}}
|
||||
{{#vendorExtensions.x-implements.0}}
|
||||
|
||||
## Implemented Interfaces
|
||||
|
||||
{{#vendorExtensions.x-implements}}
|
||||
* {{{.}}}
|
||||
{{/vendorExtensions.x-implements}}
|
||||
{{/vendorExtensions.x-implements.0}}
|
||||
{{/vendorExtensions.x-is-one-of-interface}}
|
||||
{{#vendorExtensions.x-is-one-of-interface}}
|
||||
## Implementing Classes
|
||||
|
||||
{{#oneOf}}
|
||||
* {{{.}}}
|
||||
{{/oneOf}}
|
||||
{{/vendorExtensions.x-is-one-of-interface}}
|
83
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/pom.mustache
vendored
Normal file
83
modules/openapi-generator/src/main/resources/java-helidon/client/libraries/se/pom.mustache
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<parent>
|
||||
<groupId>io.helidon.applications</groupId>
|
||||
<artifactId>helidon-se</artifactId>
|
||||
<version>{{helidonVersion}}</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<name>{{artifactId}}</name>
|
||||
{{#appDescription}}
|
||||
<description>{{.}}</description>
|
||||
{{/appDescription}}
|
||||
<version>{{artifactVersion}}</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.helidon.webclient</groupId>
|
||||
<artifactId>helidon-webclient</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.helidon.config</groupId>
|
||||
<artifactId>helidon-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>{{x-helidon-rootJavaEEDepPrefix}}.json</groupId>
|
||||
<artifactId>{{x-helidon-rootJavaEEDepPrefix}}.json-api</artifactId>
|
||||
</dependency>
|
||||
{{#jackson}}
|
||||
<dependency>
|
||||
<groupId>io.helidon.media</groupId>
|
||||
<artifactId>helidon-media-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>jackson-databind-nullable</artifactId>
|
||||
<version>0.2.2</version>
|
||||
</dependency>
|
||||
{{/jackson}}
|
||||
{{#jsonb}}
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-binding</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>{{x-helidon-rootJavaEEDepPrefix}}.json.bind</groupId>
|
||||
<artifactId>{{x-helidon-rootJavaEEDepPrefix}}.json.bind-api</artifactId>
|
||||
</dependency>
|
||||
{{/jsonb}}
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-libs</id>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
{{#isQueryParam}}@QueryParam("{{baseName}}") {{^isContainer}}{{#defaultValue}}@DefaultValue("{{{.}}}") {{/defaultValue}}{{/isContainer}}{{{dataType}}} {{paramName}}{{/isQueryParam}}
|
@ -0,0 +1,4 @@
|
||||
{{#useGenericResponse}}Response{{/useGenericResponse}}{{! non-generic response:
|
||||
}}{{^useGenericResponse}}{{!
|
||||
}}{{{returnType}}}{{!
|
||||
}}{{/useGenericResponse}}
|
@ -0,0 +1,17 @@
|
||||
{{#jackson}}
|
||||
|
||||
@JsonIgnoreProperties(
|
||||
value = "{{{discriminator.propertyBaseName}}}", // ignore manually set {{{discriminator.propertyBaseName}}}, it will be automatically generated by Jackson during serialization
|
||||
allowSetters = true // allows the {{{discriminator.propertyBaseName}}} to be set during deserialization
|
||||
)
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminator.propertyBaseName}}}", visible = true)
|
||||
{{#discriminator.mappedModels}}
|
||||
{{#-first}}
|
||||
@JsonSubTypes({
|
||||
{{/-first}}
|
||||
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
|
||||
{{#-last}}
|
||||
})
|
||||
{{/-last}}
|
||||
{{/discriminator.mappedModels}}
|
||||
{{/jackson}}
|
9
modules/openapi-generator/src/main/resources/java-helidon/common/README.mustache
vendored
Normal file
9
modules/openapi-generator/src/main/resources/java-helidon/common/README.mustache
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# {{appName}}
|
||||
|
||||
{{#appDescriptionWithNewLines}}
|
||||
{{{.}}}
|
||||
|
||||
{{/appDescriptionWithNewLines}}
|
||||
|
||||
## Overview
|
||||
This project was generated using the Helidon OpenAPI Generator.
|
21
modules/openapi-generator/src/main/resources/java-helidon/common/gitignore.mustache
vendored
Normal file
21
modules/openapi-generator/src/main/resources/java-helidon/common/gitignore.mustache
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
*.class
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
# exclude jar for gradle wrapper
|
||||
!gradle/wrapper/*.jar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
# build files
|
||||
**/target
|
||||
target
|
||||
.gradle
|
||||
build
|
11
modules/openapi-generator/src/main/resources/java-helidon/common/licenseInfo.mustache
vendored
Normal file
11
modules/openapi-generator/src/main/resources/java-helidon/common/licenseInfo.mustache
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* {{{appName}}}
|
||||
* {{{appDescription}}}
|
||||
*
|
||||
* {{#version}}The version of the OpenAPI document: {{{.}}}{{/version}}
|
||||
* {{#infoEmail}}Contact: {{{.}}}{{/infoEmail}}
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
23
modules/openapi-generator/src/main/resources/java-helidon/common/model.mustache
vendored
Normal file
23
modules/openapi-generator/src/main/resources/java-helidon/common/model.mustache
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
{{>licenseInfo}}
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
{{#serializableModel}}
|
||||
import java.io.Serializable;
|
||||
{{/serializableModel}}
|
||||
{{#useBeanValidation}}
|
||||
import {{rootJavaEEPackage}}.validation.constraints.*;
|
||||
import {{rootJavaEEPackage}}.validation.Valid;
|
||||
{{/useBeanValidation}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#isEnum}}
|
||||
{{>enumOuterClass}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{>pojo}}
|
||||
{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
121
modules/openapi-generator/src/main/resources/java-helidon/common/pojo.mustache
vendored
Normal file
121
modules/openapi-generator/src/main/resources/java-helidon/common/pojo.mustache
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
{{#jsonb}}
|
||||
import java.lang.reflect.Type;
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbTypeDeserializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbTypeSerializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.DeserializationContext;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.JsonbDeserializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.JsonbSerializer;
|
||||
import {{rootJavaEEPackage}}.json.bind.serializer.SerializationContext;
|
||||
import {{rootJavaEEPackage}}.json.stream.JsonGenerator;
|
||||
import {{rootJavaEEPackage}}.json.stream.JsonParser;
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbProperty;
|
||||
{{#vendorExtensions.x-has-readonly-properties}}
|
||||
import {{rootJavaEEPackage}}.json.bind.annotation.JsonbCreator;
|
||||
{{/vendorExtensions.x-has-readonly-properties}}
|
||||
{{/jsonb}}
|
||||
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{.}}}
|
||||
*/{{/description}}
|
||||
public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}} {{#vendorExtensions.x-implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
|
||||
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
|
||||
{{^isContainer}}
|
||||
{{>enumClass}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{#mostInnerItems}}
|
||||
{{>enumClass}}
|
||||
{{/mostInnerItems}}
|
||||
{{/isContainer}}
|
||||
|
||||
{{/isEnum}}
|
||||
private {{{datatypeWithEnum}}} {{{name}}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
|
||||
{{/vars}}
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public {{classname}}() {
|
||||
// JSON-B / Jackson
|
||||
}
|
||||
|
||||
/**
|
||||
* Create {{classname}}.
|
||||
*
|
||||
{{#vars}}
|
||||
* @param {{name}} {{description}}{{^description}}{{name}}{{/description}}
|
||||
{{/vars}}
|
||||
*/
|
||||
public {{classname}}(
|
||||
{{#vars}}
|
||||
{{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
|
||||
{{/vars}}
|
||||
) {
|
||||
{{#vars}}
|
||||
this.{{name}} = {{name}};
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{#vars}}{{#vendorExtensions.x-has-readonly-properties}}{{#jsonb}}
|
||||
@JsonbCreator
|
||||
public {{classname}}(
|
||||
{{#readOnlyVars}}
|
||||
@JsonbProperty("{{baseName}}") {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
|
||||
{{/readOnlyVars}}
|
||||
) {
|
||||
{{#readOnlyVars}}
|
||||
this.{{name}} = {{name}};
|
||||
{{/readOnlyVars}}
|
||||
}{{/jsonb}}{{/vendorExtensions.x-has-readonly-properties}}
|
||||
|
||||
/**
|
||||
{{#description}}
|
||||
* {{{.}}}
|
||||
{{/description}}
|
||||
{{^description}}
|
||||
* Get {{name}}
|
||||
{{/description}}
|
||||
{{#minimum}}
|
||||
* minimum: {{.}}
|
||||
{{/minimum}}
|
||||
{{#maximum}}
|
||||
* maximum: {{.}}
|
||||
{{/maximum}}
|
||||
* @return {{name}}
|
||||
*/
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}{{/vars}}
|
||||
|
||||
/**
|
||||
* Create a string representation of this pojo.
|
||||
**/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
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("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private static String toIndentedString(Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
}
|
34
modules/openapi-generator/src/main/resources/java-helidon/server/README.mustache
vendored
Normal file
34
modules/openapi-generator/src/main/resources/java-helidon/server/README.mustache
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
# Helidon Server with OpenAPI
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK11+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/{{{artifactId}}}.jar
|
||||
```
|
||||
|
||||
## Exercise the application
|
||||
|
||||
```
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}curl -X {{httpMethod}} {{{basePath}}}{{{path}}}
|
||||
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
|
||||
```
|
||||
|
||||
## Try health and metrics
|
||||
|
||||
```
|
||||
curl -s -X GET {{{basePath}}}/health
|
||||
{"outcome":"UP",...
|
||||
. . .
|
||||
|
||||
# Prometheus Format
|
||||
curl -s -X GET {{{basePath}}}/metrics
|
||||
# TYPE base:gc_g1_young_generation_count gauge
|
||||
. . .
|
||||
|
||||
# JSON Format
|
||||
curl -H 'Accept: application/json' -X GET {{{basePath}}}/metrics
|
||||
{"base":...
|
||||
. . .
|
||||
```
|
39
modules/openapi-generator/src/main/resources/java-helidon/server/RFC3339DateFormat.mustache
vendored
Normal file
39
modules/openapi-generator/src/main/resources/java-helidon/server/RFC3339DateFormat.mustache
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
{{>licenseInfo}}
|
||||
package {{invokerPackage}};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user