Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[JAVA] Implement #10176 (for 3.x) #667

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,9 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
if (foundSchemas.isEmpty()) {
operationParameters.addBodyParams(bodyParam.copy());
operationParameters.addAllParams(bodyParam);
if (body.getRequired() != null && body.getRequired()) {
operationParameters.addRequiredParam(bodyParam.copy());
}
} else {
boolean alreadyAdded = false;
for (Schema usedSchema : foundSchemas) {
Expand Down
73 changes: 73 additions & 0 deletions src/main/resources/handlebars/Java/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,79 @@ public class {{classname}} {

{{#operation}}
{{#contents}}
{{#hasOptionalParams}}
public static class {{operationIdCamelCase}}Optionals {
{{#allParams}}{{^required}}
public {{{dataType}}} {{paramName}}() {
return this.{{paramName}};
}

public {{operationIdCamelCase}}Optionals {{paramName}}({{{dataType}}} {{paramName}}) {
this.{{paramName}} = {{paramName}};
return this;
}

private {{{dataType}}} {{paramName}} = null;
{{/required}}{{/allParams}}
}
{{/hasOptionalParams}}

{{#hasOptionalParams}}
/**
* {{summary}}
* {{notes}}
{{#requiredParams}}
* @param {{paramName}} {{description}} (required)
{{/requiredParams}}
{{#returnType}}
* @return {{returnType}}
{{/returnType}}
* @throws ApiException if fails to make API call
{{#isDeprecated}}
* @deprecated
{{/isDeprecated}}
{{#externalDocs}}
* {{description}}
* @see <a href="{{url}}">{{summary}} Documentation</a>
{{/externalDocs}}
*/
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#requiredParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}) throws ApiException {
{{#returnType}}return {{/returnType}}{{operationId}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
}

/**
* {{summary}}
* {{notes}}
{{#requiredParams}}
* @param {{paramName}} {{description}} (required)
{{/requiredParams}}
* @param optionals An object containing the optional parameters for this API call.
{{#returnType}}
* @return {{returnType}}
{{/returnType}}
* @throws ApiException if fails to make API call
{{#isDeprecated}}
* @deprecated
{{/isDeprecated}}
{{#externalDocs}}
* {{description}}
* @see <a href="{{url}}">{{summary}} Documentation</a>
{{/externalDocs}}
*/
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}Opts({{#requiredParams}}{{{dataType}}} {{paramName}}, {{/requiredParams}}{{operationIdCamelCase}}Optionals optionals) throws ApiException {
if (optionals == null) {
optionals = new {{operationIdCamelCase}}Optionals();
}
{{#returnType}}return {{/returnType}}{{operationId}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}optionals.{{paramName}}(){{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
}
{{/hasOptionalParams}}

/**
* {{summary}}
* {{notes}}
Expand Down
73 changes: 73 additions & 0 deletions src/main/resources/handlebars/Java/libraries/jersey2/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,79 @@ public class {{classname}} {

{{#operation}}
{{#contents}}
{{#hasOptionalParams}}
public static class {{operationIdCamelCase}}Optionals {
{{#allParams}}{{^required}}
public {{{dataType}}} {{paramName}}() {
return this.{{paramName}};
}

public {{operationIdCamelCase}}Optionals {{paramName}}({{{dataType}}} {{paramName}}) {
this.{{paramName}} = {{paramName}};
return this;
}

private {{{dataType}}} {{paramName}} = null;
{{/required}}{{/allParams}}
}
{{/hasOptionalParams}}

{{#hasOptionalParams}}
/**
* {{summary}}
* {{notes}}
{{#requiredParams}}
* @param {{paramName}} {{description}} (required)
{{/requiredParams}}
{{#returnType}}
* @return {{returnType}}
{{/returnType}}
* @throws ApiException if fails to make API call
{{#isDeprecated}}
* @deprecated
{{/isDeprecated}}
{{#externalDocs}}
* {{description}}
* @see <a href="{{url}}">{{summary}} Documentation</a>
{{/externalDocs}}
*/
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#requiredParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}) throws ApiException {
{{#returnType}}return {{/returnType}}{{operationId}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
}

/**
* {{summary}}
* {{notes}}
{{#requiredParams}}
* @param {{paramName}} {{description}} (required)
{{/requiredParams}}
* @param optionals An object containing the optional parameters for this API call.
{{#returnType}}
* @return {{returnType}}
{{/returnType}}
* @throws ApiException if fails to make API call
{{#isDeprecated}}
* @deprecated
{{/isDeprecated}}
{{#externalDocs}}
* {{description}}
* @see <a href="{{url}}">{{summary}} Documentation</a>
{{/externalDocs}}
*/
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}Opts({{#requiredParams}}{{{dataType}}} {{paramName}}, {{/requiredParams}}{{operationIdCamelCase}}Optionals optionals) throws ApiException {
if (optionals == null) {
optionals = new {{operationIdCamelCase}}Optionals();
}
{{#returnType}}return {{/returnType}}{{operationId}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}optionals.{{paramName}}(){{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
}
{{/hasOptionalParams}}

/**
* {{summary}}
* {{notes}}
Expand Down
Loading