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

Update mustache style #90

Merged
merged 9 commits into from
Feb 5, 2020
Merged

Conversation

macisamuele
Copy link
Collaborator

The goal of this PR is to improve our mustache templates to allow generation of code that will pass untouched through our linters (ktlint will consider the code good-looking).

The PR introduces changes on:

  • generator code: to ensure that we're running actions (ie. version definition and stripping headers) in the shared codegen as it is not android specific and to ensure that we have the correct file imports (for android)
  • generator code constants: ie Map<K,V> should have a space in order to have ktlint happy with it
  • templates: to ensure that the correct new lines, spaces and similars are placed.

I do I know it works as we'd like to?
Changes into samples/* are essentially not present (if we exclude the removal of one indentation level of X-Operation-ID header).
Running

make regenerate-samples && pre-commit run --all-files && git status

returns an empty diff, so pre-commit considers the generated code "good-looking"

@macisamuele macisamuele self-assigned this Feb 4, 2020
@cortinico cortinico added this to the 1.4.0 milestone Feb 4, 2020
@cortinico cortinico added the enhancement New feature or request label Feb 4, 2020
Copy link
Collaborator

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good to me. I left a couple of comments

@@ -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) }
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Comment on lines +414 to +418
if (codegenParameter.isFile) {
codegenOperation.imports.add("okhttp3.RequestBody")
// The generated Retrofit APIs use RequestBody and not File objects
codegenOperation.imports.remove("File")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that you're wrapping the "okhttp3.RequestBody" here as otherwise you'll have a bunch of unused imports. On the other hand you're adding a new endpoint to junit-test that is not covered by a test. I'd suggest you add the new endpoint in a separate PR. Ideally we should tackle also the Multipart scenario that I'm pretty sure we don't cover.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

@macisamuele macisamuele merged commit d0aab68 into Yelp:master Feb 5, 2020
@macisamuele macisamuele deleted the maci-mustache-style branch February 5, 2020 16:35
@macisamuele macisamuele mentioned this pull request Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants