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)
* Copyright 2018 SmartBear Software
*
* 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 org.openapitools.codegen.languages;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import org.openapitools.codegen.*;
import org.openapitools.codegen.utils.ModelUtils;
import org.openapitools.codegen.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;
import static org.openapitools.codegen.utils.StringUtils.camelize;
public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(TypeScriptNodeClientCodegen.class);
public static final String NPM_NAME = "npmName";
public static final String NPM_VERSION = "npmVersion";
public static final String NPM_REPOSITORY = "npmRepository";
public static final String SNAPSHOT = "snapshot";
protected String npmName = null;
protected String npmVersion = "1.0.0";
protected String npmRepository = null;
protected String apiSuffix = "Api";
public TypeScriptNodeClientCodegen() {
super();
typeMapping.put("file", "Buffer");
languageSpecificPrimitives.add("Buffer");
// clear import mapping (from default generator) as TS does not use it
// at the moment
importMapping.clear();
outputFolder = "generated-code/typescript-node";
embeddedTemplateDir = templateDir = "typescript-node";
modelTemplateFiles.put("model.mustache", ".ts");
apiTemplateFiles.put("api-single.mustache", ".ts");
modelPackage = "model";
apiPackage = "api";
this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package"));
this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package"));
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(SNAPSHOT,
"When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm",
SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
}
@Override
public String getName() {
return "typescript-node";
}
@Override
public String getHelp() {
return "Generates a TypeScript NodeJS client library.";
}
@Override
public boolean isDataTypeFile(final String dataType) {
return "Buffer".equals(dataType);
}
@Override
public String getTypeDeclaration(Schema p) {
if (ModelUtils.isFileSchema(p)) {
return "Buffer";
} else if (ModelUtils.isBinarySchema(p)) {
return "Buffer";
}
return super.getTypeDeclaration(p);
}
@Override
public String toApiName(String name) {
if (name.length() == 0) {
return "Default" + apiSuffix;
}
return camelize(name) + apiSuffix;
}
@Override
public String toApiFilename(String name) {
if (name.length() == 0) {
return "default" + apiSuffix;
}
return camelize(name, true) + apiSuffix;
}
@Override
public String toApiImport(String name) {
return apiPackage() + "/" + toApiFilename(name);
}
@Override
public String toModelFilename(String name) {
return camelize(toModelName(name), true);
}
@Override
public String toModelImport(String name) {
return modelPackage() + "/" + toModelFilename(name);
}
@Override
public Map postProcessAllModels(Map objs) {
Map result = super.postProcessAllModels(objs);
for (Map.Entry entry : result.entrySet()) {
Map inner = (Map) entry.getValue();
List