Skip to content
flamangoes Generate and use variable name for setting discriminator
This fixes a bug with discriminators that are specified with underscores.

In v2.4.0 a change was made which automatically populated the discriminator variable
with the class name. However whilst the variable name was converted from the model to
a java friendly variable, for example object_type to objectType in the parent class
the set variable didn't translate accordingly and so leaves uncompilable code.

As a result the generated code produced was...

```
  public ParentObject() {
    this.object_type = this.getClass().getSimpleName();
  }
  public ParentObject objectType(String objectType) {
    this.objectType = objectType;
    return this;
  }
```
and not

```
    this.objectType = this.getClass().getSimpleName();
```
Latest commit 07c94ac Feb 22, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
auth Add java8 option 2.3.0 (#5955) Jul 1, 2017
libraries Merge pull request #8938 from swagger-api/fix-retrofit Nov 21, 2018
ApiClient.mustache
BeanValidationException.mustache add perform beanvalidation flag to ok-http-gson #2549 Nov 12, 2016
Configuration.mustache add license to Jun 9, 2016
CustomInstantDeserializer.mustache [Java] Threetenbp dates support (#4029) Nov 4, 2016
JSON.mustache
Pair.mustache
README.mustache
RFC3339DateFormat.mustache [Java/Jackson] use a jdk6 compatible DateFormat for java.util.Date (#… Oct 10, 2016
StringUtil.mustache
api.mustache
apiException.mustache
api_doc.mustache Replaced {{mediaType}} with {{{mediaType}} to keep the original media May 20, 2016
api_test.mustache
beanValidation.mustache add @Valid annotion for bean-validation (#5517) May 4, 2017
beanValidationCore.mustache [Spring][Java] fix support of long values for @max and @min annotatio… Jan 7, 2018
beanValidationQueryParams.mustache
build.gradle.mustache
build.sbt.mustache
enum_outer_doc.mustache
generatedAnnotation.mustache made timestamp generation enabled by default Apr 3, 2016
git_push.sh.mustache fix typo: crediential => credential Nov 13, 2017
gitignore.mustache
gradle-wrapper.jar
gradle-wrapper.properties.mustache gradle wrapper mustache for java api client; May 20, 2016
gradle.properties.mustache add gradle files with android support Oct 12, 2015
gradlew.bat.mustache
gradlew.mustache
licenseInfo.mustache Remove Apache license from API client generators (#4197) Nov 16, 2016
manifest.mustache
model.mustache [JAVA] equals and hashCode for models with byte[] and binary strings (#… Jan 14, 2018
modelEnum.mustache
modelInnerEnum.mustache use html-escaped description for C# (client, server), Java server (#6061 Jul 14, 2017
model_doc.mustache Revert "Revert "[Java] Add auto-generated documentation in Markdown t… Apr 22, 2016
pojo.mustache
pojo_doc.mustache
pom.mustache
settings.gradle.mustache
travis.mustache
typeInfoAnnotation.mustache
xmlAnnotation.mustache

README.mustache

# {{artifactId}}

{{appName}}
- API version: {{appVersion}}
{{^hideGenerationTimestamp}}
  - Build date: {{generatedDate}}
{{/hideGenerationTimestamp}}

{{#appDescription}}{{{appDescription}}}{{/appDescription}}

{{#infoUrl}}
  For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

*Automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen)*


## Requirements

Building the API client library requires:
1. Java 1.7+
2. Maven/Gradle

## Installation

To install the API client library to your local Maven repository, simply execute:

```shell
mvn clean install
```

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

```shell
mvn clean deploy
```

Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information.

### Maven users

Add this dependency to your project's POM:

```xml
<dependency>
  <groupId>{{{groupId}}}</groupId>
  <artifactId>{{{artifactId}}}</artifactId>
  <version>{{{artifactVersion}}}</version>
  <scope>compile</scope>
</dependency>
```

### Gradle users

Add this dependency to your project's build file:

```groovy
compile "{{{groupId}}}:{{{artifactId}}}:{{{artifactVersion}}}"
```

### Others

At first generate the JAR by executing:

```shell
mvn clean package
```

Then manually install the following JARs:

* `target/{{{artifactId}}}-{{{artifactVersion}}}.jar`
* `target/lib/*.jar`

## Getting Started

Please follow the [installation](#installation) instruction and execute the following Java code:

```java
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
import {{{invokerPackage}}}.*;
import {{{invokerPackage}}}.auth.*;
import {{{modelPackage}}}.*;
import {{{package}}}.{{{classname}}};

import java.io.File;
import java.util.*;

public class {{{classname}}}Example {

    public static void main(String[] args) {
        {{#hasAuthMethods}}ApiClient defaultClient = Configuration.getDefaultApiClient();
        {{#authMethods}}{{#isBasic}}
        // Configure HTTP basic authorization: {{{name}}}
        HttpBasicAuth {{{name}}} = (HttpBasicAuth) defaultClient.getAuthentication("{{{name}}}");
        {{{name}}}.setUsername("YOUR USERNAME");
        {{{name}}}.setPassword("YOUR PASSWORD");{{/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}}}();
        {{#allParams}}
        {{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
        {{/allParams}}
        try {
            {{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
            System.out.println(result);{{/returnType}}
        } catch (ApiException e) {
            System.err.println("Exception when calling {{{classname}}}#{{{operationId}}}");
            e.printStackTrace();
        }
    }
}
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
```

## Documentation for API Endpoints

All URIs are relative to *{{basePath}}*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}

## Documentation for Models

{{#models}}{{#model}} - [{{classname}}]({{modelDocPath}}{{classname}}.md)
{{/model}}{{/models}}

## Documentation for Authorization

{{^authMethods}}All endpoints do not require authorization.
{{/authMethods}}Authentication schemes defined for the API:
{{#authMethods}}### {{name}}

{{#isApiKey}}- **Type**: API key
- **API key parameter name**: {{keyParamName}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}- **Type**: HTTP basic authentication
{{/isBasic}}
{{#isOAuth}}- **Type**: OAuth
- **Flow**: {{flow}}
- **Authorization URL**: {{authorizationUrl}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}}  - {{scope}}: {{description}}
{{/scopes}}
{{/isOAuth}}

{{/authMethods}}

## Recommendation

It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.

## Author

{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}
{{/hasMore}}{{/apis}}{{/apiInfo}}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.