获取“规范中未定义操作!”对于 SpringDoc Swagger

问题描述 投票:0回答:1

我已经使用 OpenAPI 库实现了 swagger。 我的应用程序在 spring boot 2.7.1 上运行 我收到“规范中没有定义操作!”,甚至我的控制器也有 api。可能是什么问题呢。 这是代码。

OrderController.java

package com.example.service;

import com.example.service.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/v1/orders")
@Tag(name = "contact", description = "the Contact API")
public class OrderController {
    
    //System.out.println("OrderController");

    @PostMapping("/orders")
    public int saveOrderDetails(@RequestBody Order order) {
        int orderId = 1;
        return orderId;
    }

    @Operation(summary = "Find Contacts by name", description = "Name search by %name% format", tags = { "contact" })
    @GetMapping(value = "/orders/{orderId}", produces = { "application/json", "application/xml" })
    public Order getOrderDetails(@RequestParam("orderId") int orderId) {
        Order order = new Order();
        return order;
    }

    @PutMapping("/orders")
    public ResponseEntity<String> updateOrderDetails(@RequestBody Order order) {
        return new ResponseEntity<>("Updated successfully",
                HttpStatus.OK);
    }

    @DeleteMapping("/orders")
    public ResponseEntity<String> deleteOrderDetails(@RequestParam("orderId") int orderId) {
        return new ResponseEntity<>("Deleted successfully",
                HttpStatus.NO_CONTENT);
    }
}

应用程序.java

public class Application {

    
    
    public static void main(String[] args) throws VtmException 
    {
              SpringApplication.run(Application.class, args);
         }

        @Bean
   public OpenAPI vOpenAPI() {
       
    
       return new OpenAPI()
               .info(new Info().title("Advanced REST API")
               .description("REST API application"))
               .components(new Components());
   }

pom.xml

<dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.8.0</version>
        </dependency> 

应用程序.属性

springdoc.packagesToScan=com.example.service
springdoc.pathsToMatch=/vtm/v1

# swagger-ui custom path
springdoc.swagger-ui.path=/swagger-ui.html

# /api-docs endpoint custom path
springdoc.api-docs.path=/v3/api-docs

springdoc.api-docs.enabled=true

尝试在 swagger 中获取输出,但得到“规范中没有定义操作!”

我希望能够为 api 获得正确的输出。

java spring-boot swagger openapi springdoc
1个回答
0
投票

删除 application.properties 中的所有这些配置,因为这些配置在您的情况下没有用

springdoc.pathsToMatch=/vtm/v1
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.api-docs.path=/v3/api-docs
springdoc.api-docs.enabled=true

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.