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

Revert "remove everything" #1

Merged
merged 5 commits into from
Jul 17, 2020
Merged

Revert "remove everything" #1

merged 5 commits into from
Jul 17, 2020

Conversation

ghostbuster91
Copy link
Contributor

This reverts commit 64864bd.

This reverts commit 64864bd.
@ghostbuster91 ghostbuster91 requested a review from adamw July 7, 2020 21:13
build.sbt Outdated Show resolved Hide resolved
openApiIgnoreFileOverride := s"$root/openapi-ignore-file",
libraryDependencies ++= Seq(
"com.softwaremill.sttp.client" %% "core" % "2.2.0",
"com.softwaremill.sttp.client" %% "json4s" % "2.2.0",
Copy link
Member

Choose a reason for hiding this comment

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

the version should be extracted to a constant. Also, I'd use circe as it's the more popular choice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We cannot use circe, as this plugin contains openapi-generator in 4.3.1 version which doesn't contain improved sttp generator. I've created an issue to release newer version: OpenAPITools/sbt-openapi-generator#15

Copy link
Member

Choose a reason for hiding this comment

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

even better, the version of the openapi-generator to use could be configured as a setting of the plugin (not hard-coded)?

Copy link
Contributor Author

@ghostbuster91 ghostbuster91 Jul 8, 2020

Choose a reason for hiding this comment

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

I also thought about such approach but that seems to counter the openapi convention. Other plugins like gradle and maven are released each time a new version of generator came out. Probably there is a good reason for that. There is already an issue in sbt-openapi-plugin project to setup an automatic release process based on openapi-generator's releases. (OpenAPITools/sbt-openapi-generator#2)

"org.json4s" %% "json4s-jackson" % "3.6.8"
),
(compile in Compile) := ((compile in Compile) dependsOn openApiGenerate).value,
cleanFiles += baseDirectory.value / "src"
Copy link
Member

Choose a reason for hiding this comment

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

I think we should generate those into src-managed. See: https://www.scala-sbt.org/1.x/docs/Howto-Generating-Files.html

Maybe we can also leverage the sourceGenerators task?

Copy link
Contributor Author

@ghostbuster91 ghostbuster91 Jul 8, 2020

Choose a reason for hiding this comment

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

That looks awesome, unfortunately we can't use sourceGenerators because this requires all files to be compile-able and despite explicitly saying to generator that we want only src/main files it also generates .openapi-generator-ignore and .openapi-generator/VERSION files ...

I also agree that we should use sourceManaged, but while it works I am not sure if it is safe since the generator still doesn't allow us change the destination of the source files - we can only change the baseDir directory.
So it looks like this:

$ tree petstore-api/target/scala-2.12  
petstore-api/target/scala-2.12
├── src_managed
│   └── main
│       └── demo
│           └── src
│               └── main
│                   └── scala
│                       └── org
│                           └── openapitools
│                               └── client
│                                   ├── api
│                                   │   ├── EnumsSerializers.scala
│                                   │   ├── PetApi.scala
│                                   │   ├── StoreApi.scala
│                                   │   └── UserApi.scala
│                                   ├── core
│                                   │   ├── ApiInvoker.scala
│                                   │   ├── requests.scala
│                                   │   └── Serializers.scala
│                                   └── model
│                                       ├── ApiResponse.scala
│                                       ├── Category.scala
│                                       ├── Order.scala
│                                       ├── Pet.scala
│                                       ├── Tag.scala
│                                       └── User.scala

So after all it seems like this ignoreFile isn't what we were looking for.

Copy link
Contributor Author

@ghostbuster91 ghostbuster91 Jul 8, 2020

Choose a reason for hiding this comment

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

I wonder what implications would be of doing it in the openapi-way. We could generate a self-containing sbt-project into petstore-api directory and since it contains build.sbt file it will be recognized by the root project. am I right?

Copy link
Member

Choose a reason for hiding this comment

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

I wonder what implications would be of doing it in the openapi-way. We could generate a self-containing sbt-project into petstore-api directory and since it contains build.sbt file it will be recognized by the root project. am I right?

yes, but it would also contain its own settings, which would overwrite user's settings. We don't want to do that - the plugin should only do its job: generate a client, and minimally interfere with other parts of the project

Copy link
Member

Choose a reason for hiding this comment

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

That looks awesome, unfortunately we can't use sourceGenerators because this requires all files to be compile-able and despite explicitly saying to generator that we want only src/main files it also generates .openapi-generator-ignore and .openapi-generator/VERSION files ...

I also agree that we should use sourceManaged, but while it works I am not sure if it is safe since the generator still doesn't allow us change the destination of the source files - we can only change the baseDir directory.

Ah, so that's a bug in the openapi sbt-plugin or the generator. We'll have to live with that so far :). So maybe we can leave this as-is, but add a comment on why sourceGenerators are not used, and link to issues (if they exist) which report the problem?

So after all it seems like this ignoreFile isn't what we were looking for.

Well it is, but needs fixing, no? ;)

Copy link
Contributor Author

@ghostbuster91 ghostbuster91 Jul 8, 2020

Choose a reason for hiding this comment

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

Ah, so that's a bug in the openapi sbt-plugin or the generator. We'll have to live with that so far :). So maybe we can leave this as-is, but add a comment on why sourceGenerators are not used, and link to issues (if they exist) which report the problem?

Agree, currently there is no issue apart from OpenAPITools/openapi-generator#6685 but I think that it will evolve into new one, probably in sbt-openapi-plugin.

Well it is, but needs fixing, no? ;)

I think that it is something which by coincidence was partially useful for us, but I cannot image it being changed in such a way that will allow us to put sources into srcManaged directly. I wasn't just build for that purpose.

Copy link

@jrouly jrouly Nov 3, 2020

Choose a reason for hiding this comment

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

I just filed a PR against OpenAPITools that would allow use of sbt source generators by disabling metadata file generation in a way compatible with the sbt plugin.

If that's interesting to you still it could use some support!

OpenAPITools/openapi-generator#7862

implicit val serializer: SttpSerializer = new SttpSerializer()
implicit val apiKeyValue = ApiKeyValue("")
implicit val backend = HttpURLConnectionBackend()
println(StoreApi().getInventory().send())
Copy link
Member

Choose a reason for hiding this comment

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

ah the server address is in the yaml ... but there is a way to overwrite it here, if we wanted to call another address?

Copy link
Contributor Author

@ghostbuster91 ghostbuster91 Jul 8, 2020

Choose a reason for hiding this comment

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

Yes, this is the default parameter which is defined for the apply method from the companion object

@ghostbuster91 ghostbuster91 merged commit 4e8a611 into master Jul 17, 2020
@ghostbuster91 ghostbuster91 deleted the pr-for-review branch July 17, 2020 14:50
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.

3 participants