public void init(SchemaMeta schemaMeta, Method method, String operationPath, String httpMethod, Operation swaggerOperation) { this.schemaMeta = schemaMeta; schemaQualifiedName = schemaMeta.getSchemaId() + "." + method.getName(); microserviceQualifiedName = schemaMeta.getMicroserviceName() + "." + schemaQualifiedName; this.operationPath = operationPath; this.method = method; this.httpMethod = httpMethod.toUpperCase(Locale.US); this.swaggerOperation = swaggerOperation; executor = ExecutorManager.findExecutor(this); collectMethodType(); responsesMeta.init(schemaMeta.getMicroserviceMeta().getClassLoader(), schemaMeta.getPackageName(), schemaMeta.getSwagger(), swaggerOperation, method.getGenericReturnType()); }
public void init() throws Exception { for (ProducerProvider provider : producerProviderList) { provider.init(); } Microservice microservice = RegistryUtils.getMicroservice(); MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(microservice); for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas()) { String content = SchemaUtils.swaggerToString(schemaMeta.getSwagger()); microservice.addSchema(schemaMeta.getSchemaId(), content); } } }
public void init(OperationMeta operationMeta) { this.operationMeta = operationMeta; Swagger swagger = operationMeta.getSchemaMeta().getSwagger(); Operation operation = operationMeta.getSwaggerOperation(); this.produces = operation.getProduces(); if (produces == null) { this.produces = swagger.getProduces(); } this.createProduceProcessors(); Method method = operationMeta.getMethod(); Type[] genericParamTypes = method.getGenericParameterTypes(); if (genericParamTypes.length != operation.getParameters().size()) { throw new Error("Param count is not equal between swagger and method, path=" + absolutePath); } // 初始化所有rest param for (int idx = 0; idx < genericParamTypes.length; idx++) { Parameter parameter = operation.getParameters().get(idx); Type genericParamType = genericParamTypes[idx]; if ("formData".equals(parameter.getIn())) { formData = true; } RestParam param = new RestParam(idx, parameter, genericParamType); addParam(param); } setAbsolutePath(concatPath(swagger.getBasePath(), operationMeta.getOperationPath())); }
public SchemaMeta getOrCreateProducerSchema(String microserviceName, String schemaId, Class<?> producerClass, Object producerInstance) { MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(microserviceName); ProducerSchemaContext context = new ProducerSchemaContext(); context.setMicroserviceMeta(microserviceMeta); context.setSchemaId(schemaId); context.setProviderClass(producerClass); context.setProducerInstance(producerInstance); SchemaMeta schemaMeta = getOrCreateSchema(context); SwaggerProducer producer = swaggerEnv.createProducer(producerInstance, schemaMeta.getSwagger()); for (OperationMeta operationMeta : schemaMeta.getOperations()) { SwaggerProducerOperation producerOperation = producer.findOperation(operationMeta.getOperationId()); operationMeta.putExtData(Const.PRODUCER_OPERATION, producerOperation); } return schemaMeta; }