1.初始化版本,2.引入thirdpart模块,引入canteen模块,初始化菜品分类,spu
This commit is contained in:
commit
aff77150d6
1595 files changed
+168833
No files matched your search
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.bsd.pjcloud.common.swagger.annotation;
|
||||
|
||||
import com.bsd.pjcloud.common.core.factory.YamlPropertySourceFactory;
|
||||
import com.bsd.pjcloud.common.swagger.config.OpenAPIDefinitionImportSelector;
|
||||
import com.bsd.pjcloud.common.swagger.support.SwaggerProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 开启 pig spring doc
|
||||
*
|
||||
* @author pjcloud
|
||||
* @date 2022-03-26
|
||||
*/
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@EnableConfigurationProperties(SwaggerProperties.class)
|
||||
@Import({ OpenAPIDefinitionImportSelector.class })
|
||||
@PropertySource(value = "classpath:openapi-config.yaml", factory = YamlPropertySourceFactory.class)
|
||||
public @interface EnableOpenApi {
|
||||
|
||||
/**
|
||||
* 网关路由前缀
|
||||
* @return String
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* 是否是微服务架构
|
||||
* @return true
|
||||
*/
|
||||
boolean isMicro() default true;
|
||||
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, pjcloud All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: pjcloud
|
||||
*/
|
||||
package com.bsd.pjcloud.common.swagger.config;
|
||||
|
||||
import com.bsd.pjcloud.common.swagger.support.SwaggerProperties;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.security.OAuthFlow;
|
||||
import io.swagger.v3.oas.models.security.OAuthFlows;
|
||||
import io.swagger.v3.oas.models.security.Scopes;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springdoc.core.utils.SpringDocUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* swagger配置
|
||||
*
|
||||
* <p>
|
||||
* 禁用方法1:使用注解@Profile({"dev","test"})
|
||||
* <p>
|
||||
* 表示在开发或测试环境开启,而在生产关闭。(推荐使用) 禁用方法2:使用注解@ConditionalOnProperty(name = "swagger.enable",
|
||||
* <p>
|
||||
* havingValue = "true") 然后在测试配置或者开发配置中添加swagger.enable=true即可开启,生产环境不填则默认关闭Swagger.
|
||||
* </p>
|
||||
*
|
||||
* @author pjcloud
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
|
||||
public class OpenAPIDefinition extends OpenAPI implements InitializingBean, ApplicationContextAware {
|
||||
|
||||
@Setter
|
||||
private String path;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private SecurityScheme securityScheme(SwaggerProperties swaggerProperties) {
|
||||
OAuthFlow clientCredential = new OAuthFlow();
|
||||
clientCredential.setTokenUrl(swaggerProperties.getTokenUrl());
|
||||
clientCredential.setScopes(new Scopes().addString(swaggerProperties.getScope(), swaggerProperties.getScope()));
|
||||
OAuthFlows oauthFlows = new OAuthFlows();
|
||||
oauthFlows.password(clientCredential);
|
||||
SecurityScheme securityScheme = new SecurityScheme();
|
||||
securityScheme.setType(SecurityScheme.Type.OAUTH2);
|
||||
securityScheme.setFlows(oauthFlows);
|
||||
return securityScheme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
SwaggerProperties swaggerProperties = applicationContext.getBean(SwaggerProperties.class);
|
||||
this.info(new Info().title(swaggerProperties.getTitle()));
|
||||
// oauth2.0 password
|
||||
this.schemaRequirement(HttpHeaders.AUTHORIZATION, this.securityScheme(swaggerProperties));
|
||||
// servers
|
||||
List<Server> serverList = new ArrayList<>();
|
||||
serverList.add(new Server().url(swaggerProperties.getGateway() + "/" + path));
|
||||
this.servers(serverList);
|
||||
// 支持参数平铺
|
||||
SpringDocUtils.getConfig().addSimpleTypesForParameterObject(Class.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.bsd.pjcloud.common.swagger.config;
|
||||
|
||||
import com.bsd.pjcloud.common.swagger.annotation.EnableOpenApi;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* openapi 配置类
|
||||
*
|
||||
* @author pjcloud
|
||||
* @date 2023/1/1
|
||||
*/
|
||||
public class OpenAPIDefinitionImportSelector implements ImportBeanDefinitionRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
|
||||
|
||||
Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(EnableOpenApi.class.getName(),
|
||||
true);
|
||||
Object value = annotationAttributes.get("value");
|
||||
if (Objects.isNull(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(OpenAPIDefinition.class);
|
||||
definition.addPropertyValue("path", value);
|
||||
definition.setPrimary(true);
|
||||
|
||||
registry.registerBeanDefinition("openAPIDefinition", definition.getBeanDefinition());
|
||||
|
||||
// 如果是微服务架构则,引入了服务发现声明相关的元数据配置
|
||||
Object isMicro = annotationAttributes.getOrDefault("isMicro", true);
|
||||
if (isMicro.equals(false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BeanDefinitionBuilder openAPIMetadata = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(OpenAPIMetadataConfiguration.class);
|
||||
openAPIMetadata.addPropertyValue("path", value);
|
||||
registry.registerBeanDefinition("openAPIMetadata", openAPIMetadata.getBeanDefinition());
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.bsd.pjcloud.common.swagger.config;
|
||||
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
/**
|
||||
* @author pjcloud
|
||||
* @date 2023/1/4
|
||||
*/
|
||||
public class OpenAPIMetadataConfiguration implements InitializingBean, ApplicationContextAware {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Setter
|
||||
private String path;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
String[] beanNamesForType = applicationContext.getBeanNamesForType(ServiceInstance.class);
|
||||
|
||||
if (beanNamesForType.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServiceInstance serviceInstance = applicationContext.getBean(ServiceInstance.class);
|
||||
serviceInstance.getMetadata().put("spring-doc", path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, pjcloud All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: pjcloud
|
||||
*/
|
||||
package com.bsd.pjcloud.common.swagger.support;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* SwaggerProperties
|
||||
*
|
||||
* @author pjcloud
|
||||
* @date 2018/7/25 14:00
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties("swagger")
|
||||
public class SwaggerProperties {
|
||||
|
||||
/**
|
||||
* 是否开启swagger
|
||||
*/
|
||||
private Boolean enabled = true;
|
||||
|
||||
/**
|
||||
* swagger会解析的包路径
|
||||
**/
|
||||
private String basePackage = "";
|
||||
|
||||
/**
|
||||
* swagger会解析的url规则
|
||||
**/
|
||||
private List<String> basePath = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 在basePath基础上需要排除的url规则
|
||||
**/
|
||||
private List<String> excludePath = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 需要排除的服务
|
||||
*/
|
||||
private List<String> ignoreProviders = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 标题
|
||||
**/
|
||||
private String title = "";
|
||||
|
||||
/**
|
||||
* 网关
|
||||
*/
|
||||
private String gateway;
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
*/
|
||||
private String tokenUrl;
|
||||
|
||||
/**
|
||||
* 作用域
|
||||
*/
|
||||
private String scope;
|
||||
|
||||
/**
|
||||
* 服务转发配置
|
||||
*/
|
||||
private Map<String, String> services;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# swagger 配置
|
||||
swagger:
|
||||
enabled: true
|
||||
title: pjcloud Swagger API
|
||||
gateway: http://${GATEWAY-HOST:pjcloud-gateway}:${GATEWAY-PORT:9999}
|
||||
token-url: ${swagger.gateway}/auth/oauth2/token
|
||||
scope: server
|
||||
Reference in new issue
Block a user