Skip to content

Add kotlin code snippets to spring-boot refdoc #18017

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

Closed
wants to merge 18 commits into from
Closed

Add kotlin code snippets to spring-boot refdoc #18017

wants to merge 18 commits into from

Conversation

IEnoobong
Copy link

Add kotlin code snippets to spring-boot refdoc

See gh-21778

@sdeleuze
Copy link
Contributor

FYI this PR is work in progress, more commits will come for other asciidoc files and I plan to review them.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 30, 2019
@wilkinsona
Copy link
Member

Thanks for the PR, @IEnoobong. Before too much more time is invested in this, I think we should pause and consider #6313. That issue is already quite a big job and inlining Kotlin snippets in the documentation will make it bigger.

@sdeleuze
Copy link
Contributor

sdeleuze commented Sep 2, 2019

Hey @wilkinsona, would you be ok if we provide Kotlin code samples as runnable code directly?

I think providing a consistent experience across Boot and Framework reference documentation would bring a lot of value to developers (see how it looks like on here where core, testing, WebFlux and WebMvc documentations are translated).

@wilkinsona
Copy link
Member

That sounds good to me, assuming that we don't run into Eclipse-related problems with the Kotlin source. We've been fine with the Kotlin code that we've got thus far so I don't anticipate any problems.

A nice side-effect would be that it might give us the necessary impetus to do the same for our Java examples.

@sdeleuze
Copy link
Contributor

@IEnoobong After a second thought, I think you should use a Kotlin specific package but same class names.

So instead of:

package org.springframework.boot.docs.service

@Service
class KotlinDatabaseAccountServiceWithoutAutowired(private val riskAssessor: RiskAssessor) : AccountService {
	//..
}

Something like:

package org.springframework.boot.docs.kotlin.service

@Service
class DatabaseAccountServiceWithoutAutowired(private val riskAssessor: RiskAssessor) : AccountService {
	//..
}

Could you please modify the PR accordingly?

@IEnoobong
Copy link
Author

@sdeleuze Alright, I’m thinking to prefer service/kotlin to kotlin/service. What do you think?

@sdeleuze
Copy link
Contributor

That's ok

@IEnoobong
Copy link
Author

Please use immutable classes with val properties since they are now supported by Spring Boot 2.2 like:

data class BlogProperties(val title: String, val banner: Banner) {
  data class Banner(val title: String?, val content: String)
}

Yes, there's an example on immutable binding on line 898

private final Security security;

public AcmeProperties(boolean enabled, InetAddress remoteAddress, Security security) {
public AcmeProperties(boolean enabled, InetAddress remoteAddress, int port, Security security) {
Copy link
Author

Choose a reason for hiding this comment

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

@IEnoobong
Copy link
Author

IEnoobong commented Sep 17, 2019

For configuration properties I make the objects val but the properties var

class ImmutableAcmeProperties(
	var enabled: Boolean,
	var remoteAddress: InetAddress,
	var port: Int,
	val security = Security()
) {

	class Security(
		var username: String?=null,
		var password: String?=null,
		@DefaultValue("USER")
		val roles: List<String> = mutableList()
	)
}

Aren't there runnable tests for the Java equivalent?

works with val too #18017 (comment)

No there are not.

@sdeleuze
Copy link
Contributor

sdeleuze commented Oct 5, 2019

It will be too short for Spring Boot 2.2, I propose we target Spring Boot 2.3 for this PR instead (if possible beginning of the dev cycle in order to avoid too much merge conflicts). Maybe that will be also the opportunity to move forward on #6313 for Java as well in Spring Boot 2.3 timeframe if Boot team think it could be in the roadmap for next year.

@philwebb philwebb changed the title add kotlin code snippets to spring-boot refdoc Add kotlin code snippets to spring-boot refdoc Oct 6, 2019
@philwebb philwebb added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 7, 2019
@philwebb philwebb added this to the 2.3.x milestone Nov 7, 2019
@philwebb philwebb modified the milestones: 2.3.x, 2.x Apr 17, 2020
@snicoll
Copy link
Member

snicoll commented Oct 2, 2020

A pre-requisite of this PR was that our code samples move first to code snippet so that we figure out what to do to provide a Kotlin counterpart. This PR has been sitting for a while and we'd like to to address the first part, see #6313.

Thanks for the PR and sorry for the wasted time.

@snicoll snicoll closed this Oct 2, 2020
@snicoll snicoll removed the type: documentation A documentation update label Oct 2, 2020
@snicoll snicoll removed this from the 2.x milestone Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants