-
Notifications
You must be signed in to change notification settings - Fork 37
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
Update mustache style #90
Changes from all commits
485eb0c
8547f17
b8c2f4d
c6b4412
813ae93
3fa8f67
1953012
bf59529
90efa16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -402,14 +402,20 @@ open class KotlinGenerator : SharedCodegen() { | |
): CodegenOperation { | ||
val codegenOperation = super.fromOperation(path, httpMethod, operation, definitions, swagger) | ||
|
||
retrofitImport.get(codegenOperation.httpMethod)?.let { codegenOperation.imports.add(it) } | ||
retrofitImport[codegenOperation.httpMethod]?.let { codegenOperation.imports.add(it) } | ||
codegenOperation.allParams.forEach { codegenParameter: CodegenParameter -> | ||
codegenParameter.collectionFormat?.let { | ||
val importName = "$toolsPackage.${it.toUpperCase()}" | ||
if (importName !in codegenOperation.imports) { | ||
codegenOperation.imports.add(importName) | ||
} | ||
} | ||
|
||
if (codegenParameter.isFile) { | ||
codegenOperation.imports.add("okhttp3.RequestBody") | ||
// The generated Retrofit APIs use RequestBody and not File objects | ||
codegenOperation.imports.remove("File") | ||
} | ||
Comment on lines
+414
to
+418
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that you're wrapping the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather keep the already existing endpoint, I'll try to see how expensive would be creating a test for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Creating a realistic test for it seems going a bit beyond the scope of the PR, especially considering that I'm getting the feeling that files are not properly handled (#99 ) Going to offload the effort in a follow-up PR |
||
} | ||
|
||
codegenOperation.returnType = when { | ||
|
@@ -427,11 +433,6 @@ open class KotlinGenerator : SharedCodegen() { | |
|
||
codegenOperation.imports.add("retrofit2.http.Headers") | ||
|
||
codegenOperation.vendorExtensions[X_OPERATION_ID] = operation?.operationId | ||
getHeadersToIgnore().forEach { headerName -> | ||
ignoreHeaderParameter(headerName, codegenOperation) | ||
} | ||
|
||
// Let's remove the leading | ||
if (!basePath.isNullOrBlank()) { | ||
codegenOperation.path = codegenOperation.path.removePrefix("/") | ||
|
@@ -471,8 +472,6 @@ open class KotlinGenerator : SharedCodegen() { | |
override fun preprocessSwagger(swagger: Swagger) { | ||
super.preprocessSwagger(swagger) | ||
|
||
// Override the swagger version with the one provided from command line. | ||
swagger.info.version = additionalProperties[SPEC_VERSION] as String | ||
this.basePath = swagger.basePath | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
@Json(name = "{{{baseName}}}") @field:Json(name = "{{{baseName}}}") {{#vendorExtensions.x-nullable}}@XNullable {{/vendorExtensions.x-nullable}}var {{{name}}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}} = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}} | ||
@Json(name = "{{{baseName}}}") @field:Json(name = "{{{baseName}}}") {{#vendorExtensions.x-nullable}}@XNullable {{/vendorExtensions.x-nullable}}var {{{name}}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}} = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
@Json(name = "{{{baseName}}}") @field:Json(name = "{{{baseName}}}") var {{{name}}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}} | ||
@Json(name = "{{{baseName}}}") @field:Json(name = "{{{baseName}}}") var {{{name}}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
/** | ||
* {{{description}}} | ||
/**{{#description}} | ||
* {{{description}}}{{/description}} | ||
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
*/ | ||
@JsonClass(generateAdapter = false) | ||
enum class {{classname}}(val value: {{dataType}}){ | ||
{{#allowableValues}}{{#enumVars}} @Json(name = {{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}} | ||
{{/enumVars}}{{/allowableValues}}} | ||
enum class {{classname}}(val value: {{dataType}}) { | ||
{{#allowableValues}}{{#enumVars}} @Json(name = {{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{{newline}}}{{/enumVars}}{{/allowableValues}}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
{{>file_header}} | ||
package {{modelPackage}} | ||
|
||
{{#imports}}import {{import}} | ||
{{#imports}}{{#-first}} | ||
{{/-first}}import {{import}} | ||
{{/imports}} | ||
|
||
{{#models}} | ||
{{#model}} | ||
{{#isAlias}}{{>type_alias}}{{/isAlias}}{{^isAlias}}{{#isEnum}}{{>enum_class}}{{/isEnum}}{{^isEnum}}{{>data_class}}{{/isEnum}}{{/isAlias}} | ||
{{/model}} | ||
{{/models}} | ||
{{#models}}{{#model}} | ||
{{#isAlias}}{{>type_alias}}{{/isAlias}}{{^isAlias}}{{#isEnum}}{{>enum_class}}{{/isEnum}}{{^isEnum}}{{>data_class}}{{/isEnum}}{{/isAlias}}{{/model}}{{/models}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,43 @@ | ||
{{>file_header}} | ||
package {{package}} | ||
|
||
import okhttp3.RequestBody | ||
|
||
{{#imports}}import {{import}} | ||
{{/imports}} | ||
|
||
{{#operations}} | ||
@JvmSuppressWildcards | ||
interface {{classname}} { | ||
{{#operation}} | ||
/**{{#summary}} {{{newline}}} * {{{summary}}}{{/summary}}{{#notes}}{{{newline}}} * {{{<br/>}}}{{{notes}}}{{/notes}} | ||
* The endpoint is owned by {{{vendorExtensions.x-team-owners}}}{{^vendorExtensions.x-team-owners}}{{service_name}} service owner{{/vendorExtensions.x-team-owners}} | ||
/**{{#summary}}{{{newline}}} * {{{summary}}}{{/summary}}{{#notes}}{{{newline}}} * {{{<br/>}}}{{{notes}}}{{/notes}} | ||
* The endpoint is owned by {{{vendorExtensions.x-team-owners}}}{{^vendorExtensions.x-team-owners}}{{service_name}} service owner{{/vendorExtensions.x-team-owners}} | ||
{{#allParams}} | ||
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} | ||
* @param {{paramName}}{{#description}} {{description}}{{/description}} ({{#required}}required{{/required}}{{^required}}optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}{{/required}}) | ||
{{/allParams}} | ||
{{#externalDocs}} | ||
* {{description}} | ||
* @see [{{url}}"][{{summary}} Documentation] | ||
* {{description}} | ||
* @see [{{url}}"][{{summary}} Documentation] | ||
{{/externalDocs}} | ||
*/ | ||
*/ | ||
{{#formParams}} | ||
{{#-first}} | ||
{{#isMultipart}}@retrofit2.http.Multipart{{/isMultipart}}{{^isMultipart}}@retrofit2.http.FormUrlEncoded{{/isMultipart}} | ||
{{#isMultipart}}@retrofit2.http.Multipart{{/isMultipart}}{{^isMultipart}}@retrofit2.http.FormUrlEncoded{{/isMultipart}} | ||
{{/-first}} | ||
{{/formParams}} | ||
{{#vendorExtensions.hasOperationHeaders}} | ||
@Headers( | ||
{{#vendorExtensions.operationHeaders}}"{{first}}: {{second}}"{{^-last}}, | ||
{{/-last}}{{#-last}} | ||
){{/-last}}{{/vendorExtensions.operationHeaders}} | ||
{{/vendorExtensions.hasOperationHeaders}} | ||
@{{httpMethod}}("{{{path}}}"){{#vendorExtensions.x-unsafe-operation}}{{#isDeprecated}} | ||
@Deprecated(message = "Deprecated and unsafe to use"){{/isDeprecated}}{{^isDeprecated}} | ||
@Deprecated(message = "Unsafe to use"){{/isDeprecated}} | ||
@Headers( | ||
{{#vendorExtensions.operationHeaders}}"{{first}}: {{second}}"{{^-last}}, | ||
{{/-last}}{{#-last}} | ||
){{/-last}}{{/vendorExtensions.operationHeaders}} | ||
{{/vendorExtensions.hasOperationHeaders}} | ||
@{{httpMethod}}("{{{path}}}"){{#vendorExtensions.x-unsafe-operation}}{{#isDeprecated}} | ||
@Deprecated(message = "Deprecated and unsafe to use"){{/isDeprecated}}{{^isDeprecated}} | ||
@Deprecated(message = "Unsafe to use"){{/isDeprecated}} | ||
{{/vendorExtensions.x-unsafe-operation}}{{^vendorExtensions.x-unsafe-operation}}{{#isDeprecated}} | ||
@Deprecated(message = "Deprecated"){{/isDeprecated}} | ||
{{/vendorExtensions.x-unsafe-operation}} | ||
{{vendorExtensions.x-function-qualifiers}} fun {{operationId}}({{^allParams}}){{/allParams}} | ||
{{#allParams}}{{>retrofit2/queryParams}}{{>retrofit2/pathParams}}{{>retrofit2/headerParams}}{{>retrofit2/bodyParams}}{{>retrofit2/formParams}}{{#hasMore}}, | ||
{{/hasMore}}{{^hasMore}} | ||
){{/hasMore}}{{/allParams}}: {{{returnType}}} | ||
|
||
{{#vendorExtensions.x-function-qualifiers}}{{vendorExtensions.x-function-qualifiers}} {{/vendorExtensions.x-function-qualifiers}}fun {{operationId}}({{#hasParams}} | ||
{{#allParams}} {{>retrofit2/queryParams}}{{>retrofit2/pathParams}}{{>retrofit2/headerParams}}{{>retrofit2/bodyParams}}{{>retrofit2/formParams}}{{#hasMore}},{{{newline}}}{{/hasMore}}{{/allParams}} | ||
{{/hasParams}}): {{{returnType}}} | ||
{{/operation}} | ||
} | ||
{{/operations}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{#isBodyParam}}@retrofit2.http.Body {{paramName}}: {{{dataType}}}{{/isBodyParam}} | ||
{{#isBodyParam}}@retrofit2.http.Body {{paramName}}: {{{dataType}}}{{/isBodyParam}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{#isFormParam}}{{#notFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field{{/isMultipart}}("{{baseName}}") {{paramName}}: {{{dataType}}}{{/notFile}}{{#isFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field{{/isMultipart}}("{{baseName}}\"; filename=\"{{baseName}}") {{paramName}}: RequestBody{{^required}}?{{/required}} {{/isFile}}{{/isFormParam}} | ||
{{#isFormParam}}{{#notFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field{{/isMultipart}}("{{baseName}}") {{paramName}}: {{{dataType}}}{{/notFile}}{{#isFile}}{{#isMultipart}}@retrofit2.http.Part{{/isMultipart}}{{^isMultipart}}@retrofit2.http.Field{{/isMultipart}}("{{baseName}}\"; filename=\"{{baseName}}") {{paramName}}: RequestBody{{^required}}?{{/required}}{{/isFile}}{{/isFormParam}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of this syntax
[...]?.whatever
when the returned type is optional. I generally prefer having a chain of functions. Was this suggested by the IDE?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was on the "learn kotlin the Jetbrains way" 🤣
I just accepted the IDE suggestion.