Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swagger 大摇大摆的文件显示';语义错误';编者_Swagger_Swagger Ui_Swagger 2.0_Swagger Editor - Fatal编程技术网

Swagger 大摇大摆的文件显示';语义错误';编者

Swagger 大摇大摆的文件显示';语义错误';编者,swagger,swagger-ui,swagger-2.0,swagger-editor,Swagger,Swagger Ui,Swagger 2.0,Swagger Editor,在生成用于创建swagger文档的swagger yaml文件并使用editor.swagger.io之后,我得到了如下语义错误。到目前为止,我对下面的标记错误没有任何线索: Semantic error at paths./v1/entitlement/{entitlementId}.put.parameters.5.schema.$ref $ref values must be RFC3986-compliant percent-encoded URIs Jump t

在生成用于创建swagger文档的swagger yaml文件并使用editor.swagger.io之后,我得到了如下语义错误。到目前为止,我对下面的标记错误没有任何线索:

    Semantic error at paths./v1/entitlement/{entitlementId}.put.parameters.5.schema.$ref
    $ref values must be RFC3986-compliant percent-encoded URIs
    Jump to line 391
    Semantic error at paths./v1/entitlements/{skuId}.post.parameters.4.schema.$ref
    $ref values must be RFC3986-compliant percent-encoded URIs
    Jump to line 700
    Semantic error at paths./v1/entitlements/{skuId}.post.responses.200.schema.$ref
    $ref values must be RFC3986-compliant percent-encoded URIs
    Jump to line 710
    
守则:

SwaggerConfig.java-为相应的应用程序控制器配置swagger2属性

package com.pearson.gsam.product.management.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.spi.DocumentationType.SWAGGER_2;

@Configuration
@EnableSwagger2
@Profile({ "dev", "qa","local","stg","it" })
public class SwaggerConfig extends WebMvcConfigurationSupport {

    @Value("${application.name}")
    String appName;
    @Value("${application.description}")
    String appDescription;
    @Value("${application.version}")
    private String appVersion;

    @Bean
    public Docket api() {
        return new Docket(SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiEndPointsInfo());
    }


    private ApiInfo apiEndPointsInfo() {
        return new ApiInfoBuilder()
                .title(appName)
                .description(appDescription)
                .version(appVersion)
                .build();
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");

    }
}

    
swagger-doc.java-创建swagger-API.YAML文件并存储在特定目录中

    package docs;
    
    import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
    import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
    import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
    
    import java.io.File;
    import java.io.FileWriter;
    import java.io.Writer;
    
    import com.pearson.gsam.product.management.entitlement.service.ProductManagementEntitlementService;
    import com.pearson.gsam.product.management.entitlement.service.ProductManagementEntitlementServiceImpl;
    import com.pearson.gsam.product.management.kafka.EventService;
    import com.pearson.gsam.product.management.kafka.KafkaCallBackHandler;
    import org.apache.commons.io.IOUtils;
    import org.junit.jupiter.api.Test;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
    import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
    import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration;
    import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.boot.test.mock.mockito.MockBean;
    import org.springframework.boot.test.mock.mockito.MockBeans;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Import;
    import org.springframework.kafka.test.context.EmbeddedKafka;
    import org.springframework.test.annotation.DirtiesContext;
    import org.springframework.test.context.ActiveProfiles;
    import org.springframework.test.web.servlet.MockMvc;
    
    import com.fasterxml.jackson.databind.JsonNode;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
    import com.pearson.gsam.product.management.config.SwaggerConfig;
    import com.pearson.gsam.product.management.entitlement.ProductManagementEntitlementApplication ;
    
    @ActiveProfiles( "it" )
    @DirtiesContext
    @SpringBootTest(classes = {SwaggerConfig.class},
            properties = {"spring.profiles.active=it"})
    //@SpringBootTest(classes = ProductManagementEntitlementApplication.class)
    @EnableAutoConfiguration(exclude = {EmbeddedMongoAutoConfiguration.class, MongoAutoConfiguration.class, KafkaAutoConfiguration.class})
    @AutoConfigureMockMvc
    @ComponentScan(basePackages = {"com.pearson.gsam.product.management.controller", "springfox"})
    //@EmbeddedKafka
    @MockBeans(
            @MockBean( classes = { ProductManagementEntitlementService.class, EventService.class
                    })
    )
    @Import(SwaggerConfig.class)
    public class SwaggerDoc {
        @Value("${service-name}")
        String serviceName;
        
        @Autowired
        private MockMvc mockMvc;
    
        @Test
        public void generateSwagggerDoc() throws Exception {
            String contentAsString = mockMvc.perform(get("/v2/api-docs"))
                    .andDo(print())
                    .andExpect(status().isOk())
                    .andReturn()
                    .getResponse().getContentAsString();
    
            // parse JSON
            JsonNode jsonNodeTree = new ObjectMapper().readTree(contentAsString);
            // save it as YAML
            String jsonAsYaml = new YAMLMapper().writeValueAsString(jsonNodeTree);
    
            File file = new File("swagger/"+serviceName+"-API_Swagger.yml");
            file.getParentFile().mkdirs();
    
            try (Writer writer = new FileWriter(file)) {
                IOUtils.write(jsonAsYaml, writer);
            }
        }
    }
    
    
我使用下面的罐子来招摇:

    compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
        compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.10.0'

下次请把你的问题格式化好。那真是糟糕透顶attemptsure@JamesZ,发布时出现了一些网络问题,并且出现了双重性。我建议共享您在Swagger编辑器中使用的(或由应用程序生成的)OpenAPI/Swagger规范。很难通过查看来自Swagger validator的错误并引用不完整的代码来识别它。或者,您可以共享控制器的代码,并删除控制器的实际工作以保持其干净。