Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
* See: https://opensource.stackexchange.com/questions/7300/copyright-notice-in-the-file-header-apache-v2-license/7301#7301
*
* 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
*
* https://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 org.openapitools.codegen.languages;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.ComposedSchema;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.features.DocumentationFeature;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.model.OperationsMap;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen {
private final Logger LOGGER = LoggerFactory.getLogger(AbstractTypeScriptClientCodegen.class);
public static final String NPM_REPOSITORY = "npmRepository";
public static final String WITH_PROGRESS_SUBSCRIBER = "withProgressSubscriber";
protected String npmRepository = null;
protected Set reservedParamNames = new HashSet<>();
public TypeScriptRxjsClientCodegen() {
super();
modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme));
outputFolder = "generated-code/typescript-rxjs";
embeddedTemplateDir = templateDir = "typescript-rxjs";
this.apiPackage = "apis";
this.apiTemplateFiles.put("apis.mustache", ".ts");
this.modelPackage = "models";
this.modelTemplateFiles.put("models.mustache", ".ts");
this.addExtraReservedWords();
languageSpecificPrimitives.add("Blob");
typeMapping.put("file", "Blob");
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
this.cliOptions.add(new CliOption(WITH_PROGRESS_SUBSCRIBER, "Setting this property to true will generate API controller methods with support for subscribing to request progress.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
// these are used in the api template for more efficient destructuring
this.reservedParamNames.add("headers");
this.reservedParamNames.add("query");
this.reservedParamNames.add("formData");
}
@Override
public String getName() {
return "typescript-rxjs";
}
@Override
public String getHelp() {
return "Generates a TypeScript client library using Rxjs API.";
}
public String getNpmRepository() {
return npmRepository;
}
public void setNpmRepository(String npmRepository) {
this.npmRepository = npmRepository;
}
@Override
public void processOpts() {
super.processOpts();
supportingFiles.add(new SupportingFile("index.mustache", "", "index.ts"));
supportingFiles.add(new SupportingFile("runtime.mustache", "", "runtime.ts"));
supportingFiles.add(new SupportingFile("servers.mustache", "", "servers.ts"));
supportingFiles.add(new SupportingFile("apis.index.mustache", apiPackage().replace('.', File.separatorChar), "index.ts"));
supportingFiles.add(new SupportingFile("models.index.mustache", modelPackage().replace('.', File.separatorChar), "index.ts"));
supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));
if (additionalProperties.containsKey(NPM_NAME)) {
addNpmPackageGeneration();
}
}
@Override
public boolean isDataTypeFile(final String dataType) {
return "Blob".equals(dataType);
}
@Override
public String getTypeDeclaration(Schema p) {
if (ModelUtils.isFileSchema(p)) {
return "Blob";
} else if (ModelUtils.isBinarySchema(p)) {
return "Blob";
}
return super.getTypeDeclaration(p);
}
@Override
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
codegenModel.additionalPropertiesType = getTypeDeclaration(ModelUtils.getAdditionalProperties(schema));
addImport(codegenModel, codegenModel.additionalPropertiesType);
}
@Override
public ModelsMap postProcessModels(ModelsMap objs) {
// process enum in models
List models = postProcessModelsEnum(objs).getModels();
for (ModelMap mo : models) {
CodegenModel cm = mo.getModel();
cm.imports = new TreeSet<>(cm.imports);
// name enum with model name, e.g. StatusEnum => PetStatusEnum
for (CodegenProperty var : cm.vars) {
if (Boolean.TRUE.equals(var.isEnum)) {
// behaviour for enum names is specific for typescript to not use namespaces
var.datatypeWithEnum = var.datatypeWithEnum.replace(var.enumName, cm.classname + var.enumName);
}
}
if (cm.parent != null) {
for (CodegenProperty var : cm.allVars) {
if (Boolean.TRUE.equals(var.isEnum)) {
var.datatypeWithEnum = var.datatypeWithEnum
.replace(var.enumName, cm.classname + var.enumName);
}
}
}
}
return objs;
}
@Override
public Map postProcessAllModels(Map objs) {
Map result = super.postProcessAllModels(objs);
for (ModelsMap entry : result.values()) {
for (ModelMap model : entry.getModels()) {
CodegenModel codegenModel = model.getModel();
model.put("hasImports", codegenModel.imports.size() > 0);
}
}
return result;
}
@Override
public void postProcessParameter(CodegenParameter parameter) {
super.postProcessParameter(parameter);
parameter.dataType = applyLocalTypeMapping(parameter.dataType);
}
@Override
public String getSchemaType(Schema p) {
String openAPIType = super.getSchemaType(p);
if (isLanguagePrimitive(openAPIType)) {
return openAPIType;
}
applyLocalTypeMapping(openAPIType);
return openAPIType;
}
private String applyLocalTypeMapping(String type) {
if (typeMapping.containsKey(type)) {
type = typeMapping.get(type);
}
return type;
}
private boolean isLanguagePrimitive(String type) {
return languageSpecificPrimitives.contains(type);
}
private void addNpmPackageGeneration() {
if (additionalProperties.containsKey(NPM_REPOSITORY)) {
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
}
// Files for building our lib
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
}
@Override
public OperationsMap postProcessOperationsWithModels(OperationsMap operations, List allModels) {
// Convert List of CodegenOperation to List of ExtendedCodegenOperation
List os = operations.getOperations().getOperation();
List newOs = new ArrayList<>();
for (CodegenOperation o : os) {
newOs.add(new ExtendedCodegenOperation(o));
}
operations.getOperations().setOperation(newOs);
this.addOperationModelImportInformation(operations);
this.updateOperationParameterEnumInformation(operations);
this.addConditionalImportInformation(operations);
return operations;
}
private void addOperationModelImportInformation(OperationsMap operations) {
// This method will add extra information to the operations.imports array.
// The api template uses this information to import all the required
// models for a given operation.
List