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

[Java] Missing dependency on generated project on build.sbt #1605

Closed
deigote opened this issue Dec 4, 2018 · 6 comments
Closed

[Java] Missing dependency on generated project on build.sbt #1605

deigote opened this issue Dec 4, 2018 · 6 comments

Comments

@deigote
Copy link

deigote commented Dec 4, 2018

Description

When generating code for my spec using Java and no other option, the SBT build file is missing a dependency.

The dependency seems to be present in gradle and pom build files. Adding it manually to build.sbt ("org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1") fixes the issue.

openapi-generator version

I'm using docker image openapitools/openapi-generator-cli:v3.3.4 .

OpenAPI declaration file content or url

I think any spec will do. Here one I quickly compiled for testing the issue:

openapi: "3.0.0"

info:
  title: Test
  version: v1
  contact:
    name: deigote
    email: diego@toharia.com
  description: |-
    Test API

externalDocs:
  url: http://localhost:9000/docs
  description: documentation

servers:
- url: http://localhost:9000

security:
- basicAuth: []

paths:
  /users:
    get:
      operationId: listUsers
      summary: List users.
      responses:
        '200':
          description: |-
            The users were correctly retrieved
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
      tags:
      - users

components:
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
  schemas:
    User:
      required:
      - id
      properties:
        id:
          description: an unique identifier of this user
          type: string
          example: "2142082683"           
Command line used for generation
docker run --rm -v (pwd):/local openapitools/openapi-generator-cli:v3.3.4 generate \
                  -i /local/spec.yml \
                  -g java \
                  -o /local/openApiCode
Steps to reproduce
docker run --rm -v (pwd):/local openapitools/openapi-generator-cli:v3.3.4 generate \
                  -i /local/spec.yml \
                  -g java \
                  -o /local/openApiCode
cd openApiCode
sbt test
Suggest a fix/enhancement

I guess it's a matter of including the missing dependency in the build.sbt file. I'm surprised the dependency is there for pom and gradle, I would have assumed that each build file is generated from a common set of data, including the dependencies. So maybe it's something else.

@wing328
Copy link
Member

wing328 commented Dec 4, 2018

@deigote thanks for reporting the issue. May I know if you've time to contribute a fix by submitting a PR?

@deigote
Copy link
Author

deigote commented Dec 4, 2018

I can try. Can you point me to the relevant modules or classes where I could start looking at?

@jmini
Copy link
Member

jmini commented Dec 4, 2018

I guess it's a matter of including the missing dependency in the build.sbt file. I'm surprised the dependency is there for pom and gradle, I would have assumed that each build file is generated from a common set of data, including the dependencies.

It would be great if it was working like this, but sadly the included dependencies are only included in the templates with some if-else mustache templates.

And we also have a lot of copy paste between the templates for the different java libs we support.


For feign, it is OK:

  • Template for maven POM:

<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.client</artifactId>
<version>${oltu-version}</version>
</dependency>


If you look at the same in the okhttp-gson/ folder, you will notice that the sbt template is not aligned with maven and gradle files. See:

libraryDependencies ++= Seq(
"io.swagger" % "swagger-annotations" % "1.5.17",
"com.squareup.okhttp" % "okhttp" % "2.7.5",
"com.squareup.okhttp" % "logging-interceptor" % "2.7.5",
"com.google.code.gson" % "gson" % "2.8.1",
{{#joda}}
"joda-time" % "joda-time" % "2.9.9" % "compile",
{{/joda}}
{{#threetenbp}}
"org.threeten" % "threetenbp" % "1.3.5" % "compile",
{{/threetenbp}}
"io.gsonfire" % "gson-fire" % "1.8.0" % "compile",
"junit" % "junit" % "4.12" % "test",
"com.novocode" % "junit-interface" % "0.10" % "test"
)

@jmini
Copy link
Member

jmini commented Dec 5, 2018

Can you point me to the relevant modules or classes where I could start looking at?

@deigote I hope my explanations are clear enough, if not feel free to ask for more...

@deigote
Copy link
Author

deigote commented Dec 5, 2018

@jmini they are! I'll try to submit a PR over the weekend, thanks.

@jmini
Copy link
Member

jmini commented Jan 10, 2019

Was fixed by @wing328 in #1838

See https://github.com/OpenAPITools/openapi-generator/pull/1838/files#diff-59b7d0fdab4b182e8edfb0cbaccd2bf4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants