java-wiremock.wiremock.mustache Maven / Gradle / Ivy
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package {{package}};
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import com.github.tomakehurst.wiremock.client.MappingBuilder;
import com.github.tomakehurst.wiremock.http.Fault;
{{#operations}}
public class {{classname}}MockServer {
{{#operation}}
{{#responses}}
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
public static MappingBuilder stub{{#lambda.pascalcase}}{{operationId}}{{/lambda.pascalcase}}{{{code}}}({{#allParams}}{{#required}}{{#isNullable}}@{{javaxPackage}}.annotation.Nullable {{/isNullable}}{{^isNullable}}@{{javaxPackage}}.annotation.Nonnull {{/isNullable}}{{/required}}{{^required}}@{{javaxPackage}}.annotation.Nullable {{/required}}{{^isBodyParam}}String {{paramName}}{{/isBodyParam}}{{#isBodyParam}}String body{{/isBodyParam}}{{^-last}}, {{/-last}}{{#-last}}{{#headers.0}}, {{/headers.0}}{{^headers.0}}{{#returnType}}, {{/returnType}}{{/headers.0}}{{/-last}}{{/allParams}}{{#headers}}String response{{#lambda.pascalcase}}{{baseName}}{{/lambda.pascalcase}}{{^-last}}, {{/-last}}{{#-last}}{{#returnType}}, {{/returnType}}{{/-last}}{{/headers}}{{#returnType}}String response{{/returnType}}) {
MappingBuilder stub = {{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}({{^pathParams.0}}urlPathEqualTo{{/pathParams.0}}{{#pathParams.0}}urlPathTemplate{{/pathParams.0}}("{{{path}}}")){{#hasProduces}}
.withHeader("Accept", havingExactly({{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}})){{/hasProduces}}{{#hasAuthMethods}}{{#hasConsumes}}
.withHeader("Content-Type", havingExactly("{{#consumes.0}}{{{mediaType}}}{{/consumes.0}}")){{/hasConsumes}}
.withHeader("Authorization", matching(".*")){{/hasAuthMethods}}{{#cookieParams}}
.withCookie("{{baseName}}", havingExactly({{paramName}})){{/cookieParams}}{{#hasBodyParam}}
.withRequestBody(equalToJson(body)){{/hasBodyParam}}
.willReturn(aResponse()
.withStatus({{{code}}}){{#hasProduces}}
.withHeader("Content-Type", "{{#produces.0}}{{{mediaType}}}{{/produces.0}}"){{/hasProduces}}{{#headers}}
.withHeader("{{baseName}}", response{{#lambda.pascalcase}}{{baseName}}{{/lambda.pascalcase}}){{/headers}}{{#returnType}}
.withBody(response){{/returnType}}
);
{{#pathParams}}
{{#required}}
{{#isNullable}}
if({{paramName}} != null) {
stub = stub.withPathParam("{{paramName}}", equalTo({{paramName}}));
}
{{/isNullable}}
{{^isNullable}}
stub = stub.withPathParam("{{paramName}}", equalTo({{paramName}}));
{{/isNullable}}
{{/required}}
{{^required}}
if({{paramName}} != null) {
stub = stub.withPathParam("{{paramName}}", equalTo({{paramName}}));
}
{{/required}}
{{/pathParams}}
{{#queryParams}}
{{#required}}
{{#isNullable}}
if({{paramName}} != null) {
stub = stub.withQueryParam("{{paramName}}", equalTo({{paramName}}));
}
{{/isNullable}}
{{^isNullable}}
stub = stub.withQueryParam("{{paramName}}", equalTo({{paramName}}));
{{/isNullable}}
{{/required}}
{{^required}}
if({{paramName}} != null) {
stub = stub.withQueryParam("{{paramName}}", equalTo({{paramName}}));
}
{{/required}}
{{/queryParams}}
{{#formParams}}
{{#required}}
{{#isNullable}}
if({{paramName}} != null) {
stub = stub.withFormParam("{{baseName}}", havingExactly({{paramName}}));
}
{{/isNullable}}
{{^isNullable}}
stub = stub.withFormParam("{{baseName}}", havingExactly({{paramName}}));
{{/isNullable}}
{{/required}}
{{^required}}
if({{paramName}} != null) {
stub = stub.withFormParam("{{baseName}}", havingExactly({{paramName}}));
}
{{/required}}
{{/formParams}}
{{#headerParams}}
{{#required}}
{{#isNullable}}
if({{paramName}} != null) {
stub = stub.withHeader("{{baseName}}", havingExactly({{paramName}}));
}
{{/isNullable}}
{{^isNullable}}
stub = stub.withHeader("{{baseName}}", havingExactly({{paramName}}));
{{/isNullable}}
{{/required}}
{{^required}}
if({{paramName}} != null) {
stub = stub.withHeader("{{baseName}}", havingExactly({{paramName}}));
}
{{/required}}
{{/headerParams}}
return stub;
}
{{/responses}}
public static MappingBuilder stub{{#lambda.pascalcase}}{{operationId}}{{/lambda.pascalcase}}Fault({{#allParams}}{{#required}}{{#isNullable}}@{{javaxPackage}}.annotation.Nullable {{/isNullable}}{{^isNullable}}@{{javaxPackage}}.annotation.Nonnull {{/isNullable}}{{/required}}{{^required}}@{{javaxPackage}}.annotation.Nullable {{/required}}{{^isBodyParam}}String {{paramName}}{{/isBodyParam}}{{#isBodyParam}}String body{{/isBodyParam}}, {{/allParams}}Fault fault) {
MappingBuilder stub = {{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}({{^pathParams.0}}urlPathEqualTo{{/pathParams.0}}{{#pathParams.0}}urlPathTemplate{{/pathParams.0}}("{{{path}}}")){{#hasProduces}}
.withHeader("Accept", havingExactly({{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}})){{/hasProduces}}{{#hasAuthMethods}}{{#hasConsumes}}
.withHeader("Content-Type", havingExactly("{{#consumes.0}}{{{mediaType}}}{{/consumes.0}}")){{/hasConsumes}}
.withHeader("Authorization", matching(".*")){{/hasAuthMethods}}{{#cookieParams}}
.withCookie("{{baseName}}", havingExactly({{paramName}})){{/cookieParams}}{{#bodyParam}}
.withRequestBody(equalToJson(body)){{/bodyParam}}
.willReturn(aResponse()
.withFault(fault)
);
{{#pathParams}}
{{#required}}
{{#isNullable}}
if({{paramName}} != null) {
stub = stub.withPathParam("{{paramName}}", equalTo({{paramName}}));
}
{{/isNullable}}
{{^isNullable}}
stub = stub.withPathParam("{{paramName}}", equalTo({{paramName}}));
{{/isNullable}}
{{/required}}
{{^required}}
if({{paramName}} != null) {
stub = stub.withPathParam("{{paramName}}", equalTo({{paramName}}));
}
{{/required}}
{{/pathParams}}
{{#queryParams}}
{{#required}}
{{#isNullable}}
if({{paramName}} != null) {
stub = stub.withQueryParam("{{paramName}}", equalTo({{paramName}}));
}
{{/isNullable}}
{{^isNullable}}
stub = stub.withQueryParam("{{paramName}}", equalTo({{paramName}}));
{{/isNullable}}
{{/required}}
{{^required}}
if({{paramName}} != null) {
stub = stub.withQueryParam("{{paramName}}", equalTo({{paramName}}));
}
{{/required}}
{{/queryParams}}
{{#formParams}}
{{#required}}
{{#isNullable}}
if({{paramName}} != null) {
stub = stub.withFormParam("{{baseName}}", havingExactly({{paramName}}));
}
{{/isNullable}}
{{^isNullable}}
stub = stub.withFormParam("{{baseName}}", havingExactly({{paramName}}));
{{/isNullable}}
{{/required}}
{{^required}}
if({{paramName}} != null) {
stub = stub.withFormParam("{{baseName}}", havingExactly({{paramName}}));
}
{{/required}}
{{/formParams}}
{{#headerParams}}
{{#required}}
{{#isNullable}}
if({{paramName}} != null) {
stub = stub.withHeader("{{baseName}}", havingExactly({{paramName}}));
}
{{/isNullable}}
{{^isNullable}}
stub = stub.withHeader("{{baseName}}", havingExactly({{paramName}}));
{{/isNullable}}
{{/required}}
{{^required}}
if({{paramName}} != null) {
stub = stub.withHeader("{{baseName}}", havingExactly({{paramName}}));
}
{{/required}}
{{/headerParams}}
return stub;
}
{{#examples}}
public static String {{operationId}}{{statusCode}}ResponseSample{{-index}}() {
return {{>exampleString}};
}
{{/examples}}
{{#requestBodyExamples}}
public static String {{operationId}}RequestSample{{-index}}() {
return {{>exampleString}};
}
{{/requestBodyExamples}}
{{/operation}}
}
{{/operations}}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy