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.
I'm using docker image openapitools/openapi-generator-cli:v3.3.4 .
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: [email protected]
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"
docker run --rm -v (pwd):/local openapitools/openapi-generator-cli:v3.3.4 generate \
-i /local/spec.yml \
-g java \
-o /local/openApiCode
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
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.
@deigote thanks for reporting the issue. May I know if you've time to contribute a fix by submitting a PR?
I can try. Can you point me to the relevant modules or classes where I could start looking at?
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 gradle file:
https://github.com/OpenAPITools/openapi-generator/blob/cd61442387d09e72c11b62edd2e94c7188aa19a8/modules/openapi-generator/src/main/resources/Java/libraries/feign/build.gradle.mustache#L151
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:
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...
@jmini they are! I'll try to submit a PR over the weekend, thanks.
Was fixed by @wing328 in #1838
See https://github.com/OpenAPITools/openapi-generator/pull/1838/files#diff-59b7d0fdab4b182e8edfb0cbaccd2bf4