Code Monkey home page Code Monkey logo

Comments (15)

micobarac avatar micobarac commented on May 31, 2024 3

The huge question is: Must the application be app and running on port 8080 prior to running the command above?

from springdoc-openapi-maven-plugin.

micobarac avatar micobarac commented on May 31, 2024 3

Here is the significant part of pom.xml:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>pre-integration-test</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>${start-class}</mainClass>
                    <fork>true</fork>
                    <jvmArguments>-Dspring.application.admin.enabled=true</jvmArguments>
                    <!--
                    Enable the line below to have remote debugging of your application on port 5005
                    <jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
                    -->
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springdoc</groupId>
                <artifactId>springdoc-openapi-maven-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <apiDocsUrl>http://localhost:8080/v3/api-docs</apiDocsUrl>
                    <outputFileName>openapi.json</outputFileName>
                    <outputDir>${project.basedir}/target/docs/asciidoc</outputDir>
                </configuration>
            </plugin>

I merged the existing spring-boot-maven-plugin settings with the one provided in your docs.

from springdoc-openapi-maven-plugin.

micobarac avatar micobarac commented on May 31, 2024 2

I made it work by removing:

                    <execution>
                        <id>pre-integration-test</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>

and running the app on 8080, priror to running maven mvn -Pprod,war clean verify -DskipTests=true command.

from springdoc-openapi-maven-plugin.

randyhbh avatar randyhbh commented on May 31, 2024

You are missing this in your project, is Kotlin code but I guess you will understand the idea

@Configuration
class SecurityConfig() : WebSecurityConfigurerAdapter() {

    @Throws(Exception::class)
    override fun configure(http: HttpSecurity) {
            http
            .csrf().disable()
            .antMatcher("/**")
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.NEVER)
            .and()
            .authorizeRequests()
            .antMatchers("/v3/api-docs").permitAll()
            .anyRequest().denyAll()
            .and()
            .httpBasic()
    }
}

from springdoc-openapi-maven-plugin.

saurabhpro avatar saurabhpro commented on May 31, 2024

You are missing this in your project, is Kotlin code but I guess you will understand the idea

@Configuration
class SecurityConfig() : WebSecurityConfigurerAdapter() {

    @Throws(Exception::class)
    override fun configure(http: HttpSecurity) {
            http
            .csrf().disable()
            .antMatcher("/**")
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.NEVER)
            .and()
            .authorizeRequests()
            .antMatchers("/v3/api-docs").permitAll()
            .anyRequest().denyAll()
            .and()
            .httpBasic()
    }
}

could you elaborate a little, I cant translate it to my Java project

from springdoc-openapi-maven-plugin.

randyhbh avatar randyhbh commented on May 31, 2024

So, your problem is that you are not allowing access to the route where the swagger is exposed.
You need to create a configuration class and extend from WebSecurityConfigurerAdapter and override the method configure(HttpSecurity http){....} and allow the access to "/v3/api-docs" path

from springdoc-openapi-maven-plugin.

poteii avatar poteii commented on May 31, 2024

If we run the spring context from a war deployment(No main class), How to solve java.net.ConnectException: Connection refused (Connection refused)?

from springdoc-openapi-maven-plugin.

randyhbh avatar randyhbh commented on May 31, 2024

The solution will be the same. You just need to find out how to expose the route "/v3/api-docs" for a war deployment, and I will assume is quite similar

from springdoc-openapi-maven-plugin.

poteii avatar poteii commented on May 31, 2024

Hi @randyhbh
I've already to add route "/v3/api-docs" both of WebSecurityConfigurerAdapter class and yaml file. but it still has Connection Refuse. This is my pom.

<plugins>
  <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>pre-integration-test</id>
        <goals>
          <goal>start</goal>
        </goals>
      </execution>
      <execution>
        <id>post-integration-test</id>
        <goals>
          <goal>stop</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <skip>true</skip>
      <jvmArguments>-Dspring.application.admin.enabled=true</jvmArguments>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
      <execution>
        <id>integration-test</id>
        <goals>
          <goal>generate</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <outputDir>${project.build.directory}/springdoc</outputDir>
    </configuration>
  </plugin>
</plugins>

from springdoc-openapi-maven-plugin.

micobarac avatar micobarac commented on May 31, 2024

I have the exact same problem. Adding permission to the security configuration didn't solve the problem.

Btw, why is this issue closed?

from springdoc-openapi-maven-plugin.

randyhbh avatar randyhbh commented on May 31, 2024

@micobarac Could you share your project or a newly created one that reproduce the issue so I can take a look and see if I can help you?

from springdoc-openapi-maven-plugin.

micobarac avatar micobarac commented on May 31, 2024

I have almost the same configuration as @randyhbh .

When I run

mvn -Pprod,war clean verify -DskipTests=true

I get:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.7.RELEASE:start (pre-integration-test) on project openprovider-cdb: Could not figure out if the application has started: Failed to connect to MBean server at port 9001: Could not invoke shutdown operation: Connection refused to host: 127.0.0.1; nested exception is: 
[ERROR]         java.net.ConnectException: Connection refused (Connection refused)
[ERROR] -> [Help 1]
[ERROR] 

from springdoc-openapi-maven-plugin.

ls-pavel-makhov avatar ls-pavel-makhov commented on May 31, 2024

Had the same problem - the issue was in the custom path, which was setup in application.yml.

from springdoc-openapi-maven-plugin.

pwils025 avatar pwils025 commented on May 31, 2024

The huge question is: Must the application be app and running on port 8080 prior to running the command above?

This plugin only works if the app server is running before it can make the output file. In spring boot, we run tests before even building the artifact. How can I just generate the file without having to run the app server?

So I just read through your source code and you're scraping the URL to parse the json and then saving it to a file. This will not work for my automation needs where the file needs to be created at build, not deploy. The phase of Integration test is misleading.

URL urlForGetRequest = new URL(apiDocsUrl);

from springdoc-openapi-maven-plugin.

bnasslahsen avatar bnasslahsen commented on May 31, 2024

No way for that

from springdoc-openapi-maven-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.