swagger-api / swagger-api/swagger-codegen

[Java]Missing classes when generating code

Open
#8,364 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I am trying to generate Java client classes. I am using the following plugin config:

            <plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.3.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/swagger-api-v1.json</inputSpec>
                            <language>spring</language>
                            <library>spring-cloud</library>
                            <output>${project.build.directory}/generated-sources</output>
                            <apiPackage>${default.package}.handler</apiPackage>
                            <modelPackage>${default.package}.model</modelPackage>
                            <invokerPackage>${default.package}.handler</invokerPackage>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

The specfile specifies OAuth2.

   "securityDefinitions": {
    "app-developer": {
      "type": "oauth2",
      "flow": "application",
      "tokenUrl": "https://api.myApp.com/oauth/v2/token",
      "scopes": {
        "crs": "App Services"
      }
    }
  },
  "security": [
    {
      "app-developer": [
        "crs"
      ]
    }
  ],

When i run mvn package i get:

[ERROR] /C:/work/djingo/repos/skill-recipe-java/target/generated-sources/src/main/java/io/swagger/configuration/ClientConfiguration.java:[11,62] package org.springframework.cloud.security.oauth2.client.feign does not exist
[ERROR] /C:/work/djingo/repos/skill-recipe-java/target/generated-sources/src/main/java/io/swagger/configuration/ClientConfiguration.java:[12,50] package org.springframework.security.oauth2.client does not exist
[ERROR] /C:/work/djingo/repos/skill-recipe-java/target/generated-sources/src/main/java/io/swagger/configuration/ClientConfiguration.java:[13,59] package org.springframework.security.oauth2.client.resource does not exist
[ERROR] /C:/work/djingo/repos/skill-recipe-java/target/generated-sources/src/main/java/io/swagger/configuration/ClientConfiguration.java:[14,69] package org.springframework.security.oauth2.client.token.grant.client does not exist
[ERROR] /C:/work/djingo/repos/skill-recipe-java/target/generated-sources/src/main/java/io/swagger/configuration/ClientConfiguration.java:[15,67] package org.springframework.security.oauth2.client.token.grant.code does not exist
[ERROR] /C:/work/djingo/repos/skill-recipe-java/target/generated-sources/src/main/java/io/swagger/configuration/ClientConfiguration.java:[16,71] package org.springframework.security.oauth2.client.token.grant.implicit does not exist
[ERROR] /C:/work/djingo/repos/skill-recipe-java/target/generated-sources/src/main/java/io/swagger/configuration/ClientConfiguration.java:[17,71] package org.springframework.security.oauth2.client.token.grant.password does not exist
[ERROR] /C:/work/djingo/repos/skill-recipe-java/target/generated-sources/src/main/java/io/swagger/configuration/ClientConfiguration.java:[18,61] package org.springframework.security.oauth2.common.exceptions does not exist
[ERROR] /C:/work/djingo/repos/skill-recipe-java/target/generated-sources/src/main/java/io/swagger/configuration/ClientConfiguration.java:[19,61] package org.springframework.security.oauth2.common.exceptions does not exist

I suppose I need to add some Spring OAuth2 dependencies but i couldn't find it documented anywhere.

Swagger-codegen version

2.3.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Maven generation with the shown swagger-codegen 2.3.1 configuration and OAuth2 security definition. Inspect target/generated-sources/src/main/java/io/swagger/configuration/ClientConfiguration.java and the generated imports that fail compilation. Done means the generated Spring client either compiles with its required dependencies or the required dependency setup is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.