From 0b88889cdfd3e90841a071605bac458dbbe3375a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rytis=20Karpu=C5=A1ka?= Date: Sat, 28 Jul 2018 10:23:35 +0300 Subject: [PATCH 1/9] [cpp] Sanitize identifier names (#631) * [cpp] Sanitize identifier names * Remove duplicated methods in cpp code generator subclasses. * Fix unintended codegen differences in cpp tizen caused by it not extending AbstractCppCodegen class. --- .../codegen/languages/AbstractCppCodegen.java | 32 ++++++++++++ .../languages/CppPistacheServerCodegen.java | 39 --------------- .../languages/CppQt5ClientCodegen.java | 49 ------------------- .../languages/CppRestSdkClientCodegen.java | 36 ++------------ .../languages/CppRestbedServerCodegen.java | 41 ---------------- 5 files changed, 37 insertions(+), 160 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java index ccc28aed87ea..814d8e12bf2f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java @@ -128,6 +128,38 @@ public AbstractCppCodegen() { ); } + @Override + public String escapeQuotationMark(String input) { + // remove " to avoid code injection + return input.replace("\"", ""); + } + + @Override + public String escapeUnsafeCharacters(String input) { + return input.replace("*/", "*_/").replace("/*", "/_*"); + } + + @Override + public String toApiName(String type) { + return sanitizeName(modelNamePrefix + Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api"); + } + + @Override + public String toModelName(String type) { + if (type == null) { + LOGGER.warn("Model name can't be null. Default to 'UnknownModel'."); + type = "UnknownModel"; + } + + if (typeMapping.keySet().contains(type) || typeMapping.values().contains(type) + || importMapping.values().contains(type) || defaultIncludes.contains(type) + || languageSpecificPrimitives.contains(type)) { + return type; + } else { + return sanitizeName(modelNamePrefix + Character.toUpperCase(type.charAt(0)) + type.substring(1)); + } + } + @Override public String toVarName(String name) { if (typeMapping.keySet().contains(name) || typeMapping.values().contains(name) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java index a2a7ef0cab8e..a1ac3bf86ae8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java @@ -129,18 +129,6 @@ public void processOpts() { } } - /** - * Escapes a reserved word as defined in the `reservedWords` array. Handle - * escaping those terms here. This logic is only called if a variable - * matches the reserved words - * - * @return the escaped term - */ - @Override - public String escapeReservedWord(String name) { - return "_" + name; // add an underscore to the name - } - @Override public String toModelImport(String name) { if (importMapping.containsKey(name)) { @@ -392,33 +380,6 @@ public String getSchemaType(Schema p) { return toModelName(type); } - @Override - public String toModelName(String type) { - if (typeMapping.keySet().contains(type) || typeMapping.values().contains(type) - || importMapping.values().contains(type) || defaultIncludes.contains(type) - || languageSpecificPrimitives.contains(type)) { - return type; - } else { - return Character.toUpperCase(type.charAt(0)) + type.substring(1); - } - } - - @Override - public String toApiName(String type) { - return Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api"; - } - - @Override - public String escapeQuotationMark(String input) { - // remove " to avoid code injection - return input.replace("\"", ""); - } - - @Override - public String escapeUnsafeCharacters(String input) { - return input.replace("*/", "*_/").replace("/*", "/_*"); - } - @Override public String getTypeDeclaration(String str) { return toModelName(str); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java index f57667f5be5f..bb06b36b1afe 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java @@ -251,20 +251,6 @@ public String toModelImport(String name) { return "#include \"" + folder + toModelName(name) + ".h\""; } - /** - * Escapes a reserved word as defined in the `reservedWords` array. Handle escaping - * those terms here. This logic is only called if a variable matches the reserved words - * - * @return the escaped term - */ - @Override - public String escapeReservedWord(String name) { - if (this.reservedWordsMappings().containsKey(name)) { - return this.reservedWordsMappings().get(name); - } - return "_" + name; - } - /** * Location to write model files. You can use the modelPackage() as defined when the class is * instantiated @@ -378,25 +364,6 @@ public String getSchemaType(Schema p) { return toModelName(type); } - @Override - public String toModelName(String type) { - if (type == null) { - LOGGER.warn("Model name can't be null. Default to 'UnknownModel'."); - type = "UnknownModel"; - } - - if (typeMapping.keySet().contains(type) || - typeMapping.values().contains(type) || - importMapping.values().contains(type) || - defaultIncludes.contains(type) || - languageSpecificPrimitives.contains(type)) { - return type; - } else { - String typeName = sanitizeName(type); - return modelNamePrefix + Character.toUpperCase(typeName.charAt(0)) + typeName.substring(1); - } - } - @Override public String toVarName(String name) { // sanitize name @@ -424,22 +391,6 @@ public String toParamName(String name) { return toVarName(name); } - @Override - public String toApiName(String type) { - return modelNamePrefix + Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api"; - } - - @Override - public String escapeQuotationMark(String input) { - // remove " to avoid code injection - return input.replace("\"", ""); - } - - @Override - public String escapeUnsafeCharacters(String input) { - return input.replace("*/", "*_/").replace("/*", "/_*"); - } - public void setOptionalProjectFileFlag(boolean flag) { this.optionalProjectFileFlag = flag; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java index 0d2a6c047f9e..e631fed98927 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java @@ -157,7 +157,7 @@ public CppRestSdkClientCodegen() { typeMapping.put("binary", "std::string"); typeMapping.put("number", "double"); typeMapping.put("UUID", "utility::string_t"); - typeMapping.put("ByteArray", "utility::string_t"); + typeMapping.put("ByteArray", "utility::string_t"); super.importMapping = new HashMap(); importMapping.put("std::vector", "#include "); @@ -200,6 +200,7 @@ public void processOpts() { * Location to write model files. You can use the modelPackage() as defined * when the class is instantiated */ + @Override public String modelFileFolder() { return outputFolder + "/model"; } @@ -218,7 +219,7 @@ public String toModelImport(String name) { if (importMapping.containsKey(name)) { return importMapping.get(name); } else { - return "#include \"" + name + ".h\""; + return "#include \"" + sanitizeName(name) + ".h\""; } } @@ -281,12 +282,12 @@ protected boolean isFileSchema(CodegenProperty property) { @Override public String toModelFilename(String name) { - return initialCaps(name); + return sanitizeName(initialCaps(name)); } @Override public String toApiFilename(String name) { - return initialCaps(name) + "Api"; + return sanitizeName(initialCaps(name) + "Api"); } /** @@ -388,33 +389,6 @@ public String getSchemaType(Schema p) { return toModelName(type); } - @Override - public String toModelName(String type) { - if (typeMapping.keySet().contains(type) || typeMapping.values().contains(type) - || importMapping.values().contains(type) || defaultIncludes.contains(type) - || languageSpecificPrimitives.contains(type)) { - return type; - } else { - return Character.toUpperCase(type.charAt(0)) + type.substring(1); - } - } - - @Override - public String toApiName(String type) { - return Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api"; - } - - @Override - public String escapeQuotationMark(String input) { - // remove " to avoid code injection - return input.replace("\"", ""); - } - - @Override - public String escapeUnsafeCharacters(String input) { - return input.replace("*/", "*_/").replace("/*", "/_*"); - } - @Override public Map postProcessAllModels(final Map models) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java index 317095f5113f..bb3ad8241159 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java @@ -148,18 +148,6 @@ public void processOpts() { additionalProperties.put("defaultInclude", defaultInclude); } - /** - * Escapes a reserved word as defined in the `reservedWords` array. Handle - * escaping those terms here. This logic is only called if a variable - * matches the reserved words - * - * @return the escaped term - */ - @Override - public String escapeReservedWord(String name) { - return "_" + name; // add an underscore to the name - } - /** * Location to write model files. You can use the modelPackage() as defined * when the class is instantiated @@ -361,33 +349,4 @@ public String getSchemaType(Schema p) { type = openAPIType; return toModelName(type); } - - @Override - public String toModelName(String type) { - if (typeMapping.keySet().contains(type) || typeMapping.values().contains(type) - || importMapping.values().contains(type) || defaultIncludes.contains(type) - || languageSpecificPrimitives.contains(type)) { - return type; - } else { - return Character.toUpperCase(type.charAt(0)) + type.substring(1); - } - } - - @Override - public String toApiName(String type) { - return Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api"; - } - - @Override - public String escapeQuotationMark(String input) { - // remove " to avoid code injection - return input.replace("\"", ""); - } - - @Override - public String escapeUnsafeCharacters(String input) { - return input.replace("*/", "*_/").replace("/*", "/_*"); - } - - } From 3c3ac0a071b95c63adaaadae373036db4d545d8d Mon Sep 17 00:00:00 2001 From: Benjamin Gill Date: Sat, 28 Jul 2018 09:10:49 +0100 Subject: [PATCH 2/9] Add extra modules to main dockerfile (#650) So that the mvn build is successful --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e46f873c12da..e53ca77d84a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,9 @@ COPY ./LICENSE ${GEN_DIR} COPY ./google_checkstyle.xml ${GEN_DIR} # Modules are copied individually here to allow for caching of docker layers between major.minor versions -# NOTE: openapi-generator-online is not included here +COPY ./modules/openapi-generator-gradle-plugin ${GEN_DIR}/modules/openapi-generator-gradle-plugin COPY ./modules/openapi-generator-maven-plugin ${GEN_DIR}/modules/openapi-generator-maven-plugin +COPY ./modules/openapi-generator-online ${GEN_DIR}/modules/openapi-generator-online COPY ./modules/openapi-generator-cli ${GEN_DIR}/modules/openapi-generator-cli COPY ./modules/openapi-generator ${GEN_DIR}/modules/openapi-generator COPY ./pom.xml ${GEN_DIR} From 14ab3d763ec61160b9aeeea30f673feefb1a9990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Bresson?= Date: Sun, 29 Jul 2018 13:10:58 +0200 Subject: [PATCH 3/9] Consider cases where complexType is null (#680) --- .../openapitools/codegen/DefaultCodegen.java | 6 +++++- .../codegen/perl/PerlClientCodegenTest.java | 20 ++++++++++++++++-- .../src/test/resources/3_0/issue677.yaml | 21 +++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 modules/openapi-generator/src/test/resources/3_0/issue677.yaml diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index a2d631ae69a7..0747ade52245 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -4423,7 +4423,11 @@ public CodegenParameter fromRequestBody(RequestBody body, Map sc } if (StringUtils.isEmpty(bodyParameterName)) { - codegenParameter.baseName = mostInnerItem.complexType; + if(StringUtils.isEmpty(mostInnerItem.complexType)) { + codegenParameter.baseName = "request_body"; + } else { + codegenParameter.baseName = mostInnerItem.complexType; + } } else { codegenParameter.baseName = bodyParameterName; } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java index 96f49448ce3b..40b4cb9c5288 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java @@ -17,11 +17,17 @@ package org.openapitools.codegen.perl; -import org.testng.Assert; -import org.testng.annotations.Test; +import io.swagger.parser.OpenAPIParser; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.parser.core.models.ParseOptions; import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.languages.PerlClientCodegen; +import org.openapitools.codegen.utils.ModelUtils; +import org.testng.Assert; +import org.testng.annotations.Test; public class PerlClientCodegenTest { @@ -54,4 +60,14 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception { Assert.assertEquals(codegen.isHideGenerationTimestamp(), false); } + @Test + public void testIssue677() { + final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/issue677.yaml", null, new ParseOptions()).getOpenAPI(); + final PerlClientCodegen codegen = new PerlClientCodegen(); + + Operation operation = openAPI.getPaths().get("/issue677").getPost(); + CodegenOperation co = codegen.fromOperation("/issue677", "POST", operation, ModelUtils.getSchemas(openAPI), openAPI); + Assert.assertNotNull(co); + } + } diff --git a/modules/openapi-generator/src/test/resources/3_0/issue677.yaml b/modules/openapi-generator/src/test/resources/3_0/issue677.yaml new file mode 100644 index 000000000000..1aa5a1c6d776 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue677.yaml @@ -0,0 +1,21 @@ +openapi: 3.0.1 +info: + title: My title + description: API under test + version: 1.0.7 +servers: +- url: https://localhost:9999/root +paths: + /issue677: + post: + requestBody: + content: + application/json: + schema: + type: array + items: + type: string + responses: + 201: + description: OK +components: {} From 68d80ab67dca3b0054dd703a9b780568a77c37a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Mart=C3=ADnez?= Date: Mon, 30 Jul 2018 08:38:10 +0200 Subject: [PATCH 4/9] [Java][Client][RestTemplate] Fixed invalid URL-encoding of query parameters (#646) Fix for the #644 --- .../Java/libraries/resttemplate/ApiClient.mustache | 11 ++++++++++- .../main/java/org/openapitools/client/ApiClient.java | 11 ++++++++++- .../main/java/org/openapitools/client/ApiClient.java | 11 ++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index 471a936ad579..11a042ab347f 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -46,6 +46,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.text.DateFormat; @@ -542,8 +544,15 @@ public class ApiClient { } builder.queryParams(queryParams); } + + URI uri; + try { + uri = new URI(builder.build().toUriString()); + } catch(URISyntaxException ex) { + throw new RestClientException("Could not build URL: " + builder.toUriString(), ex); + } - final BodyBuilder requestBuilder = RequestEntity.method(method, builder.build().toUri()); + final BodyBuilder requestBuilder = RequestEntity.method(method, uri); if(accept != null) { requestBuilder.accept(accept.toArray(new MediaType[accept.size()])); } diff --git a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java index e8829cf00733..c1be2519f364 100644 --- a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java @@ -40,6 +40,8 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.text.DateFormat; @@ -535,8 +537,15 @@ public T invokeAPI(String path, HttpMethod method, MultiValueMap T invokeAPI(String path, HttpMethod method, MultiValueMap Date: Mon, 30 Jul 2018 15:09:56 +0800 Subject: [PATCH 5/9] fix base path when it's not defined in the spec (#678) --- .../java/org/openapitools/codegen/DefaultGenerator.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index 503bf2413597..7bd9ff212bdc 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -193,8 +193,14 @@ private void configureGeneratorProperties() { URL url = URLPathUtils.getServerURL(openAPI); contextPath = config.escapeText(url.getPath()); - basePath = config.escapeText(URLPathUtils.getHost(openAPI)); basePathWithoutHost = contextPath; // for backward compatibility + basePath = config.escapeText(URLPathUtils.getHost(openAPI)); + if ("/".equals(basePath.substring(basePath.length() - 1))) { + // remove trailing "/" + // https://host.example.com/ => https://host.example.com + basePath = basePath.substring(0, basePath.length() - 1); + } + } private void configureOpenAPIInfo() { From cb9a734ebb0e5f5d2bfdd39e36464d50950be32f Mon Sep 17 00:00:00 2001 From: Benjamin Gill Date: Mon, 30 Jul 2018 08:31:55 +0100 Subject: [PATCH 6/9] [rust-server] add support for multiple samples (#658) * Add support for multiple rust-server samples Though we only have the one as yet. This will make it easier to move rust-server back on to the main test spec, whilst preserving the ability to have rust-specific test specs. * Rust samples need unique names * Move samples to a dedicated directory So that there is nothing else in the folder where they live so that the workspace definition in the root Cargo.toml can be simple. --- bin/rust-server-petstore.sh | 10 ++-- .../server/petstore/rust-server/Cargo.toml | 50 +------------------ .../.cargo/config | 0 .../.gitignore | 2 + .../.openapi-generator-ignore | 0 .../.openapi-generator/VERSION | 0 .../Cargo.toml | 48 ++++++++++++++++++ .../README.md | 22 ++++---- .../api/openapi.yaml | 0 .../examples/ca.pem | 0 .../examples/client.rs | 8 +-- .../examples/server-chain.pem | 0 .../examples/server-key.pem | 0 .../examples/server.rs | 8 +-- .../examples/server_lib/mod.rs | 8 +-- .../examples/server_lib/server.rs | 6 +-- .../src/client/mod.rs | 0 .../src/lib.rs | 0 .../src/mimetypes.rs | 0 .../src/models.rs | 0 .../src/server/context.rs | 0 .../src/server/mod.rs | 0 22 files changed, 84 insertions(+), 78 deletions(-) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/.cargo/config (100%) create mode 100644 samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.gitignore rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/.openapi-generator-ignore (100%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/.openapi-generator/VERSION (100%) create mode 100644 samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/README.md (79%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/api/openapi.yaml (100%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/examples/ca.pem (100%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/examples/client.rs (97%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/examples/server-chain.pem (100%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/examples/server-key.pem (100%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/examples/server.rs (86%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/examples/server_lib/mod.rs (66%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/examples/server_lib/server.rs (98%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/src/client/mod.rs (100%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/src/lib.rs (100%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/src/mimetypes.rs (100%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/src/models.rs (100%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/src/server/context.rs (100%) rename samples/server/petstore/rust-server/{ => output/petstore-with-fake-endpoints-models-for-testing}/src/server/mod.rs (100%) diff --git a/bin/rust-server-petstore.sh b/bin/rust-server-petstore.sh index 06a8c4d02023..5d76464ace38 100755 --- a/bin/rust-server-petstore.sh +++ b/bin/rust-server-petstore.sh @@ -25,8 +25,10 @@ then mvn -B clean package fi -# if you've executed sbt assembly previously it will use that instead. -export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/rust-server -i modules/openapi-generator/src/test/resources/2_0/rust-server/petstore-with-fake-endpoints-models-for-testing.yaml -g rust-server -o samples/server/petstore/rust-server -DpackageName=petstore_api --additional-properties hideGenerationTimestamp=true $@" +for spec_path in modules/openapi-generator/src/test/resources/2_0/rust-server/* ; do + export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" + spec=$(basename "$spec_path" | sed 's/.yaml//') + ags="generate -t modules/openapi-generator/src/main/resources/rust-server -i $spec_path -g rust-server -o samples/server/petstore/rust-server/output/$spec -DpackageName=$spec --additional-properties hideGenerationTimestamp=true $@" -java $JAVA_OPTS -jar $executable $ags + java $JAVA_OPTS -jar $executable $ags +done diff --git a/samples/server/petstore/rust-server/Cargo.toml b/samples/server/petstore/rust-server/Cargo.toml index 2cbbb4cc2e35..68d06c54103b 100644 --- a/samples/server/petstore/rust-server/Cargo.toml +++ b/samples/server/petstore/rust-server/Cargo.toml @@ -1,48 +1,2 @@ -[package] -name = "petstore_api" -version = "1.0.0" -authors = [] -description = "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\" -license = "Unlicense" - -[features] -default = ["client", "server"] -client = ["serde_json", "serde_urlencoded", "serde-xml-rs", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "url", "uuid"] -server = ["serde_json", "serde-xml-rs", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "tokio-proto", "tokio-tls", "regex", "percent-encoding", "url", "uuid"] - -[dependencies] -# Required by example server. -# -chrono = { version = "0.4", features = ["serde"] } -futures = "0.1" -hyper = {version = "0.11", optional = true} -hyper-tls = {version = "0.1.2", optional = true} -swagger = "1.0.1" - -# Not required by example server. -# -lazy_static = "0.2" -log = "0.3.0" -mime = "0.3.3" -multipart = {version = "0.13.3", optional = true} -native-tls = {version = "0.1.4", optional = true} -openssl = {version = "0.9.14", optional = true} -percent-encoding = {version = "1.0.0", optional = true} -regex = {version = "0.2", optional = true} -serde = "1.0" -serde_derive = "1.0" -serde_ignored = {version = "0.0.4", optional = true} -serde_json = {version = "1.0", optional = true} -serde_urlencoded = {version = "0.5.1", optional = true} -tokio-core = {version = "0.1.6", optional = true} -tokio-proto = {version = "0.1.1", optional = true} -tokio-tls = {version = "0.1.3", optional = true, features = ["tokio-proto"]} -url = {version = "1.5", optional = true} -uuid = {version = "0.5", optional = true, features = ["serde", "v4"]} -# ToDo: this should be updated to point at the official crate once -# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream -serde-xml-rs = {git = "git://github.com/Metaswitch/serde-xml-rs.git" , branch = "master", optional = true} - -[dev-dependencies] -clap = "2.25" -error-chain = "0.12" +[workspace] +members = ["output/*"] diff --git a/samples/server/petstore/rust-server/.cargo/config b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.cargo/config similarity index 100% rename from samples/server/petstore/rust-server/.cargo/config rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.cargo/config diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.gitignore b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.gitignore new file mode 100644 index 000000000000..a9d37c560c6a --- /dev/null +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.gitignore @@ -0,0 +1,2 @@ +target +Cargo.lock diff --git a/samples/server/petstore/rust-server/.openapi-generator-ignore b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator-ignore similarity index 100% rename from samples/server/petstore/rust-server/.openapi-generator-ignore rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator-ignore diff --git a/samples/server/petstore/rust-server/.openapi-generator/VERSION b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/VERSION similarity index 100% rename from samples/server/petstore/rust-server/.openapi-generator/VERSION rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/VERSION diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml new file mode 100644 index 000000000000..e5dc334269d3 --- /dev/null +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/Cargo.toml @@ -0,0 +1,48 @@ +[package] +name = "petstore-with-fake-endpoints-models-for-testing" +version = "1.0.0" +authors = [] +description = "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\" +license = "Unlicense" + +[features] +default = ["client", "server"] +client = ["serde_json", "serde_urlencoded", "serde-xml-rs", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "url", "uuid"] +server = ["serde_json", "serde-xml-rs", "serde_ignored", "hyper", "hyper-tls", "native-tls", "openssl", "tokio-core", "tokio-proto", "tokio-tls", "regex", "percent-encoding", "url", "uuid"] + +[dependencies] +# Required by example server. +# +chrono = { version = "0.4", features = ["serde"] } +futures = "0.1" +hyper = {version = "0.11", optional = true} +hyper-tls = {version = "0.1.2", optional = true} +swagger = "1.0.1" + +# Not required by example server. +# +lazy_static = "0.2" +log = "0.3.0" +mime = "0.3.3" +multipart = {version = "0.13.3", optional = true} +native-tls = {version = "0.1.4", optional = true} +openssl = {version = "0.9.14", optional = true} +percent-encoding = {version = "1.0.0", optional = true} +regex = {version = "0.2", optional = true} +serde = "1.0" +serde_derive = "1.0" +serde_ignored = {version = "0.0.4", optional = true} +serde_json = {version = "1.0", optional = true} +serde_urlencoded = {version = "0.5.1", optional = true} +tokio-core = {version = "0.1.6", optional = true} +tokio-proto = {version = "0.1.1", optional = true} +tokio-tls = {version = "0.1.3", optional = true, features = ["tokio-proto"]} +url = {version = "1.5", optional = true} +uuid = {version = "0.5", optional = true, features = ["serde", "v4"]} +# ToDo: this should be updated to point at the official crate once +# https://github.com/RReverser/serde-xml-rs/pull/45 is accepted upstream +serde-xml-rs = {git = "git://github.com/Metaswitch/serde-xml-rs.git" , branch = "master", optional = true} + +[dev-dependencies] +clap = "2.25" +error-chain = "0.12" diff --git a/samples/server/petstore/rust-server/README.md b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/README.md similarity index 79% rename from samples/server/petstore/rust-server/README.md rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/README.md index 9d56541b6a93..f8b30f1711e1 100644 --- a/samples/server/petstore/rust-server/README.md +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/README.md @@ -1,4 +1,4 @@ -# Rust API for petstore_api +# Rust API for petstore-with-fake-endpoints-models-for-testing This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ @@ -14,17 +14,17 @@ To see how to make this your own, look here: - API version: 1.0.0 -This autogenerated project defines an API crate `petstore_api` which contains: +This autogenerated project defines an API crate `petstore-with-fake-endpoints-models-for-testing` which contains: * An `Api` trait defining the API in Rust. * Data types representing the underlying data model. * A `Client` type which implements `Api` and issues HTTP requests for each operation. * A router which accepts HTTP requests and invokes the appropriate `Api` method for each operation. -It also contains an example server and client which make use of `petstore_api`: -* The example server starts up a web server using the `petstore_api` router, +It also contains an example server and client which make use of `petstore-with-fake-endpoints-models-for-testing`: +* The example server starts up a web server using the `petstore-with-fake-endpoints-models-for-testing` router, and supplies a trivial implementation of `Api` which returns failure for every operation. * The example client provides a CLI which lets you invoke any single operation on the - `petstore_api` client by passing appropriate arguments on the command line. + `petstore-with-fake-endpoints-models-for-testing` client by passing appropriate arguments on the command line. You can use the example server and client as a basis for your own code. See below for [more detail on implementing a server](#writing-a-server). @@ -105,17 +105,17 @@ This will use the keys/certificates from the examples directory. Note that the s The server example is designed to form the basis for implementing your own server. Simply follow these steps. * Set up a new Rust project, e.g., with `cargo init --bin`. -* Insert `petstore_api` into the `members` array under [workspace] in the root `Cargo.toml`, e.g., `members = [ "petstore_api" ]`. -* Add `petstore_api = {version = "1.0.0", path = "petstore_api"}` under `[dependencies]` in the root `Cargo.toml`. -* Copy the `[dependencies]` and `[dev-dependencies]` from `petstore_api/Cargo.toml` into the root `Cargo.toml`'s `[dependencies]` section. +* Insert `petstore-with-fake-endpoints-models-for-testing` into the `members` array under [workspace] in the root `Cargo.toml`, e.g., `members = [ "petstore-with-fake-endpoints-models-for-testing" ]`. +* Add `petstore-with-fake-endpoints-models-for-testing = {version = "1.0.0", path = "petstore-with-fake-endpoints-models-for-testing"}` under `[dependencies]` in the root `Cargo.toml`. +* Copy the `[dependencies]` and `[dev-dependencies]` from `petstore-with-fake-endpoints-models-for-testing/Cargo.toml` into the root `Cargo.toml`'s `[dependencies]` section. * Copy all of the `[dev-dependencies]`, but only the `[dependencies]` that are required by the example server. These should be clearly indicated by comments. * Remove `"optional = true"` from each of these lines if present. Each autogenerated API will contain an implementation stub and main entry point, which should be copied into your project the first time: ``` -cp petstore_api/examples/server.rs src/main.rs -cp petstore_api/examples/server_lib/mod.rs src/lib.rs -cp petstore_api/examples/server_lib/server.rs src/server.rs +cp petstore-with-fake-endpoints-models-for-testing/examples/server.rs src/main.rs +cp petstore-with-fake-endpoints-models-for-testing/examples/server_lib/mod.rs src/lib.rs +cp petstore-with-fake-endpoints-models-for-testing/examples/server_lib/server.rs src/server.rs ``` Now diff --git a/samples/server/petstore/rust-server/api/openapi.yaml b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/api/openapi.yaml similarity index 100% rename from samples/server/petstore/rust-server/api/openapi.yaml rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/api/openapi.yaml diff --git a/samples/server/petstore/rust-server/examples/ca.pem b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/ca.pem similarity index 100% rename from samples/server/petstore/rust-server/examples/ca.pem rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/ca.pem diff --git a/samples/server/petstore/rust-server/examples/client.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/client.rs similarity index 97% rename from samples/server/petstore/rust-server/examples/client.rs rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/client.rs index d87dd25b87ef..be8c084e7ba4 100644 --- a/samples/server/petstore/rust-server/examples/client.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/client.rs @@ -1,6 +1,6 @@ #![allow(missing_docs, unused_variables, trivial_casts)] -extern crate petstore_api; +extern crate petstore_with_fake_endpoints_models_for_testing; #[allow(unused_extern_crates)] extern crate futures; #[allow(unused_extern_crates)] @@ -17,7 +17,7 @@ use swagger::{ContextBuilder, EmptyContext, XSpanIdString, Has, Push, AuthData}; use futures::{Future, future, Stream, stream}; use tokio_core::reactor; #[allow(unused_imports)] -use petstore_api::{ApiNoContext, ContextWrapperExt, +use petstore_with_fake_endpoints_models_for_testing::{ApiNoContext, ContextWrapperExt, ApiError, TestSpecialTagsResponse, FakeOuterBooleanSerializeResponse, @@ -107,11 +107,11 @@ fn main() { matches.value_of("port").unwrap()); let client = if matches.is_present("https") { // Using Simple HTTPS - petstore_api::Client::try_new_https(core.handle(), &base_url, "examples/ca.pem") + petstore_with_fake_endpoints_models_for_testing::Client::try_new_https(core.handle(), &base_url, "examples/ca.pem") .expect("Failed to create HTTPS client") } else { // Using HTTP - petstore_api::Client::try_new_http(core.handle(), &base_url) + petstore_with_fake_endpoints_models_for_testing::Client::try_new_http(core.handle(), &base_url) .expect("Failed to create HTTP client") }; diff --git a/samples/server/petstore/rust-server/examples/server-chain.pem b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server-chain.pem similarity index 100% rename from samples/server/petstore/rust-server/examples/server-chain.pem rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server-chain.pem diff --git a/samples/server/petstore/rust-server/examples/server-key.pem b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server-key.pem similarity index 100% rename from samples/server/petstore/rust-server/examples/server-key.pem rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server-key.pem diff --git a/samples/server/petstore/rust-server/examples/server.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server.rs similarity index 86% rename from samples/server/petstore/rust-server/examples/server.rs rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server.rs index 270b1e5cdb24..0f2aba9655b2 100644 --- a/samples/server/petstore/rust-server/examples/server.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server.rs @@ -1,10 +1,10 @@ -//! Main binary entry point for petstore_api implementation. +//! Main binary entry point for petstore_with_fake_endpoints_models_for_testing implementation. #![allow(missing_docs)] // Imports required by this file. // extern crate ; -extern crate petstore_api; +extern crate petstore_with_fake_endpoints_models_for_testing; extern crate swagger; extern crate hyper; extern crate openssl; @@ -14,7 +14,7 @@ extern crate tokio_tls; extern crate clap; // Imports required by server library. -// extern crate petstore_api; +// extern crate petstore_with_fake_endpoints_models_for_testing; // extern crate swagger; extern crate futures; extern crate chrono; @@ -55,7 +55,7 @@ fn main() { .get_matches(); let service_fn = - petstore_api::server::context::NewAddContext::<_, EmptyContext>::new( + petstore_with_fake_endpoints_models_for_testing::server::context::NewAddContext::<_, EmptyContext>::new( AllowAllAuthenticator::new( server_lib::NewService::new(), "cosmo" diff --git a/samples/server/petstore/rust-server/examples/server_lib/mod.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server_lib/mod.rs similarity index 66% rename from samples/server/petstore/rust-server/examples/server_lib/mod.rs rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server_lib/mod.rs index c4f682d65397..9c406c28aa6b 100644 --- a/samples/server/petstore/rust-server/examples/server_lib/mod.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server_lib/mod.rs @@ -1,4 +1,4 @@ -//! Main library entry point for petstore_api implementation. +//! Main library entry point for petstore_with_fake_endpoints_models_for_testing implementation. mod server; @@ -11,7 +11,7 @@ use std::io; use std::clone::Clone; use std::marker::PhantomData; use hyper; -use petstore_api; +use petstore_with_fake_endpoints_models_for_testing; use swagger::{Has, XSpanIdString}; use swagger::auth::Authorization; @@ -29,10 +29,10 @@ impl hyper::server::NewService for NewService where C: Has type Request = (hyper::Request, C); type Response = hyper::Response; type Error = hyper::Error; - type Instance = petstore_api::server::Service, C>; + type Instance = petstore_with_fake_endpoints_models_for_testing::server::Service, C>; /// Instantiate a new server. fn new_service(&self) -> io::Result { - Ok(petstore_api::server::Service::new(server::Server::new())) + Ok(petstore_with_fake_endpoints_models_for_testing::server::Service::new(server::Server::new())) } } diff --git a/samples/server/petstore/rust-server/examples/server_lib/server.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server_lib/server.rs similarity index 98% rename from samples/server/petstore/rust-server/examples/server_lib/server.rs rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server_lib/server.rs index c470b7be1093..1f1d1e00a241 100644 --- a/samples/server/petstore/rust-server/examples/server_lib/server.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server_lib/server.rs @@ -1,4 +1,4 @@ -//! Server implementation of petstore_api. +//! Server implementation of petstore_with_fake_endpoints_models_for_testing. #![allow(unused_imports)] @@ -10,7 +10,7 @@ use std::marker::PhantomData; use swagger; use swagger::{Has, XSpanIdString}; -use petstore_api::{Api, ApiError, +use petstore_with_fake_endpoints_models_for_testing::{Api, ApiError, TestSpecialTagsResponse, FakeOuterBooleanSerializeResponse, FakeOuterCompositeSerializeResponse, @@ -44,7 +44,7 @@ use petstore_api::{Api, ApiError, LogoutUserResponse, UpdateUserResponse }; -use petstore_api::models; +use petstore_with_fake_endpoints_models_for_testing::models; #[derive(Copy, Clone)] pub struct Server { diff --git a/samples/server/petstore/rust-server/src/client/mod.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs similarity index 100% rename from samples/server/petstore/rust-server/src/client/mod.rs rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs diff --git a/samples/server/petstore/rust-server/src/lib.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs similarity index 100% rename from samples/server/petstore/rust-server/src/lib.rs rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs diff --git a/samples/server/petstore/rust-server/src/mimetypes.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/mimetypes.rs similarity index 100% rename from samples/server/petstore/rust-server/src/mimetypes.rs rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/mimetypes.rs diff --git a/samples/server/petstore/rust-server/src/models.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs similarity index 100% rename from samples/server/petstore/rust-server/src/models.rs rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs diff --git a/samples/server/petstore/rust-server/src/server/context.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/context.rs similarity index 100% rename from samples/server/petstore/rust-server/src/server/context.rs rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/context.rs diff --git a/samples/server/petstore/rust-server/src/server/mod.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs similarity index 100% rename from samples/server/petstore/rust-server/src/server/mod.rs rename to samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs From b587052de4b6fa1c442fca4d5a7fee91f7f07b22 Mon Sep 17 00:00:00 2001 From: sunn <33183834+etherealjoy@users.noreply.github.com> Date: Mon, 30 Jul 2018 09:33:00 +0200 Subject: [PATCH 7/9] cpp-tizen extends AbstractCppCodegen (#676) * cpp-tizen extends AbstractCppCodegen * Update javadoc comment --- .../languages/CppTizenClientCodegen.java | 29 ++++++------------- .../cpp-tizen/.openapi-generator/VERSION | 2 +- .../client/petstore/cpp-tizen/doc/Doxyfile | 2 +- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java index 1e3f1a849f1e..049a906182fe 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java @@ -32,7 +32,7 @@ import java.util.HashMap; import java.util.HashSet; -public class CppTizenClientCodegen extends DefaultCodegen implements CodegenConfig { +public class CppTizenClientCodegen extends AbstractCppCodegen implements CodegenConfig { protected static String PREFIX = "ArtikCloud"; protected String sourceFolder = "src"; protected String documentationFolder = "doc"; @@ -270,14 +270,6 @@ public String toVarName(String name) { return "" + paramName; } - @Override - public String escapeReservedWord(String name) { - if (this.reservedWordsMappings().containsKey(name)) { - return this.reservedWordsMappings().get(name); - } - return "_" + name; - } - @Override public String toOperationId(String operationId) { // throw exception if method name is empty @@ -293,16 +285,13 @@ public String toOperationId(String operationId) { // add_pet_by_id => addPetById return camelize(operationId, true); } - - @Override - public String escapeQuotationMark(String input) { - // remove " to avoid code injection - return input.replace("\"", ""); - } - - @Override - public String escapeUnsafeCharacters(String input) { - return input.replace("*/", "*_/").replace("/*", "/_*"); + /** + * Output the Getter name for boolean property, e.g. getActive + * + * @param name the name of the property + * @return getter name based on naming convention + */ + public String toBooleanGetter(String name) { + return "get" + getterAndSetterCapitalize(name); } - } diff --git a/samples/client/petstore/cpp-tizen/.openapi-generator/VERSION b/samples/client/petstore/cpp-tizen/.openapi-generator/VERSION index 096bf47efe31..4395ff592326 100644 --- a/samples/client/petstore/cpp-tizen/.openapi-generator/VERSION +++ b/samples/client/petstore/cpp-tizen/.openapi-generator/VERSION @@ -1 +1 @@ -3.0.0-SNAPSHOT \ No newline at end of file +3.2.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/cpp-tizen/doc/Doxyfile b/samples/client/petstore/cpp-tizen/doc/Doxyfile index bbb92191a0a5..9a0ba8f71860 100644 --- a/samples/client/petstore/cpp-tizen/doc/Doxyfile +++ b/samples/client/petstore/cpp-tizen/doc/Doxyfile @@ -46,7 +46,7 @@ PROJECT_NUMBER = 1.0.0 PROJECT_BRIEF = "An SDK for creating client applications for OpenAPI Petstore on Tizen Platform (http://tizen.org/)" -# With the PROJECT_LOGO tag one can specify an logo or icon that is included in +# With the PROJECT_LOGO tag one can specify a logo or icon that is included in # the documentation. The maximum height of the logo should not exceed 55 pixels # and the maximum width should not exceed 200 pixels. Doxygen will copy the logo # to the output directory. From 036fa6918c98176ab5fff63a737f6cfac5cb95bf Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 30 Jul 2018 15:42:06 +0800 Subject: [PATCH 8/9] fix operation id starting with number for python client (#682) --- .../codegen/languages/PythonClientCodegen.java | 12 +++++++++--- .../petstore/python/.openapi-generator/VERSION | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index cb829433f5d2..3ce9fd71d207 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -160,7 +160,7 @@ public PythonClientCodegen() { cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC) .defaultValue(Boolean.TRUE.toString())); cliOptions.add(new CliOption(CodegenConstants.SOURCECODEONLY_GENERATION, CodegenConstants.SOURCECODEONLY_GENERATION_DESC) - .defaultValue(Boolean.FALSE.toString())); + .defaultValue(Boolean.FALSE.toString())); supportedLibraries.put("urllib3", "urllib3-based client"); supportedLibraries.put("asyncio", "Asyncio-based client (python 3.5+)"); @@ -224,7 +224,7 @@ public void processOpts() { setPackageUrl((String) additionalProperties.get(PACKAGE_URL)); } - String readmePath ="README.md"; + String readmePath = "README.md"; String readmeTemplate = "README.mustache"; if (generateSourceCodeOnly) { readmePath = packageName + "_" + readmePath; @@ -232,7 +232,7 @@ public void processOpts() { } supportingFiles.add(new SupportingFile(readmeTemplate, "", readmePath)); - if (!generateSourceCodeOnly){ + if (!generateSourceCodeOnly) { supportingFiles.add(new SupportingFile("tox.mustache", "", "tox.ini")); supportingFiles.add(new SupportingFile("test-requirements.mustache", "", "test-requirements.txt")); supportingFiles.add(new SupportingFile("requirements.mustache", "", "requirements.txt")); @@ -552,6 +552,12 @@ public String toOperationId(String operationId) { operationId = "call_" + operationId; } + // model name starts with a number + if (operationId.matches("^\\d.*")) { + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); + operationId = "call_" + operationId; + } + return underscore(sanitizeName(operationId)); } diff --git a/samples/client/petstore/python/.openapi-generator/VERSION b/samples/client/petstore/python/.openapi-generator/VERSION index dde25ef08e8c..4395ff592326 100644 --- a/samples/client/petstore/python/.openapi-generator/VERSION +++ b/samples/client/petstore/python/.openapi-generator/VERSION @@ -1 +1 @@ -3.1.1-SNAPSHOT \ No newline at end of file +3.2.0-SNAPSHOT \ No newline at end of file From 1226242b02d3349a84fe0c3adee4e5e2c5d47aa9 Mon Sep 17 00:00:00 2001 From: muenzpraeger Date: Mon, 30 Jul 2018 10:36:11 +0200 Subject: [PATCH 9/9] [apex] migrating to OpenAPITools --- .../languages/AbstractApexCodegen.java | 683 ++++++++++++++++++ .../codegen/languages/ApexClientCodegen.java | 579 +++------------ .../main/resources/apex/README_sfdx.mustache | 2 +- .../src/main/resources/apex/Swagger.cls | 6 +- .../src/main/resources/apex/SwaggerTest.cls | 5 +- .../src/main/resources/apex/api.mustache | 4 +- .../src/main/resources/apex/api_test.mustache | 12 +- .../main/resources/apex/git_push.sh.mustache | 4 +- .../main/resources/apex/licenseInfo.mustache | 4 +- .../main/resources/apex/model_test.mustache | 9 - .../src/main/resources/apex/package.mustache | 2 +- .../src/main/resources/apex/pojo.mustache | 19 +- .../src/main/resources/apex/pojo_doc.mustache | 2 +- .../apex/sfdx-project-scratch-def.json | 8 + .../resources/apex/sfdx-project.json.mustache | 11 + .../src/main/resources/apex/sfdx.mustache | 10 - .../petstore/apex/.openapi-generator/VERSION | 1 - ...nerator-ignore => .swagger-codegen-ignore} | 6 +- .../petstore/apex/.swagger-codegen/VERSION | 1 + .../client/petstore/apex/docs/SwagPetApi.md | 52 +- .../client/petstore/apex/docs/SwagStoreApi.md | 24 +- .../client/petstore/apex/docs/SwagUserApi.md | 68 +- .../main/default/classes/SwagApiResponse.cls | 18 +- .../classes/SwagApiResponse.cls-meta.xml | 2 +- .../main/default/classes/SwagCategory.cls | 16 +- .../default/classes/SwagCategory.cls-meta.xml | 2 +- .../main/default/classes/SwagClient.cls | 2 +- .../default/classes/SwagClient.cls-meta.xml | 2 +- .../main/default/classes/SwagOrder.cls | 24 +- .../default/classes/SwagOrder.cls-meta.xml | 2 +- .../main/default/classes/SwagPet.cls | 24 +- .../main/default/classes/SwagPet.cls-meta.xml | 2 +- .../main/default/classes/SwagPetApi.cls | 50 +- .../default/classes/SwagPetApi.cls-meta.xml | 2 +- .../main/default/classes/SwagStoreApi.cls | 30 +- .../default/classes/SwagStoreApi.cls-meta.xml | 2 +- .../main/default/classes/SwagTag.cls | 16 +- .../main/default/classes/SwagTag.cls-meta.xml | 2 +- .../main/default/classes/SwagUser.cls | 28 +- .../default/classes/SwagUser.cls-meta.xml | 2 +- .../main/default/classes/SwagUserApi.cls | 66 +- .../default/classes/SwagUserApi.cls-meta.xml | 2 +- .../main/default/classes/Swagger.cls | 6 +- .../main/default/classes/Swagger.cls-meta.xml | 2 +- .../classes/SwaggerResponseMock.cls-meta.xml | 2 +- .../main/default/classes/SwaggerTest.cls | 5 +- .../default/classes/SwaggerTest.cls-meta.xml | 2 +- ...Swagger_Petstore.namedCredential-meta.xml} | 2 +- .../client/petstore/apex/sfdx-project.json | 11 + 49 files changed, 1106 insertions(+), 730 deletions(-) create mode 100644 modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractApexCodegen.java create mode 100644 modules/openapi-generator/src/main/resources/apex/sfdx-project-scratch-def.json create mode 100644 modules/openapi-generator/src/main/resources/apex/sfdx-project.json.mustache delete mode 100644 modules/openapi-generator/src/main/resources/apex/sfdx.mustache delete mode 100644 samples/client/petstore/apex/.openapi-generator/VERSION rename samples/client/petstore/apex/{.openapi-generator-ignore => .swagger-codegen-ignore} (78%) create mode 100644 samples/client/petstore/apex/.swagger-codegen/VERSION rename samples/client/petstore/apex/force-app/main/default/namedCredentials/{OpenAPI_Petstore.namedCredential => Swagger_Petstore.namedCredential-meta.xml} (88%) create mode 100644 samples/client/petstore/apex/sfdx-project.json diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractApexCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractApexCodegen.java new file mode 100644 index 000000000000..f9d2fa653b69 --- /dev/null +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractApexCodegen.java @@ -0,0 +1,683 @@ +package io.swagger.codegen.languages; + +import java.io.File; +import java.util.*; + +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; + +import com.google.common.base.Strings; + +import io.swagger.codegen.*; +import io.swagger.models.Model; +import io.swagger.models.Operation; +import io.swagger.models.Path; +import io.swagger.models.Swagger; +import io.swagger.models.parameters.FormParameter; +import io.swagger.models.parameters.Parameter; +import io.swagger.models.properties.*; + + +public abstract class AbstractApexCodegen extends DefaultCodegen implements CodegenConfig { + + protected Boolean serializableModel = false; + + public AbstractApexCodegen() { + super(); + } + + @Override + public CodegenType getTag() { + return CodegenType.CLIENT; + } + + @Override + public String getName() { + return "apex"; + } + + @Override + public String getHelp() { + return "Generates an Apex API client library."; + } + + @Override + public void processOpts() { + super.processOpts(); + } + + @Override + public String escapeReservedWord(String name) { + if(this.reservedWordsMappings().containsKey(name)) { + return this.reservedWordsMappings().get(name); + } + return "_" + name; + } + + @Override + public String sanitizeName(String name) { + name = super.sanitizeName(name); + if (name.contains("__")) { // Preventing namespacing + name.replaceAll("__", "_"); + } + if (name.matches("^\\d.*")) { // Prevent named credentials with leading number + name.replaceAll("^\\d.*", ""); + } + return name; + } + + @Override + public String toVarName(String name) { + // sanitize name + name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + + if (name.toLowerCase().matches("^_*class$")) { + return "propertyClass"; + } + + if("_".equals(name)) { + name = "_u"; + } + + // if it's all uppper case, do nothing + if (name.matches("^[A-Z_]*$")) { + if (isReservedWord(name)) { + name = escapeReservedWord(name); + } + return name; + } + + if(startsWithTwoUppercaseLetters(name)){ + name = name.substring(0, 2).toLowerCase() + name.substring(2); + } + + // camelize (lower first character) the variable name + // pet_id => petId + name = camelize(name, true); + + // for reserved word or word starting with number, append _ + if (isReservedWord(name) || name.matches("^\\d.*")) { + name = escapeReservedWord(name); + } + + return name; + } + + private boolean startsWithTwoUppercaseLetters(String name) { + boolean startsWithTwoUppercaseLetters = false; + if(name.length() > 1) { + startsWithTwoUppercaseLetters = name.substring(0, 2).equals(name.substring(0, 2).toUpperCase()); + } + return startsWithTwoUppercaseLetters; + } + + @Override + public String toParamName(String name) { + // to avoid conflicts with 'callback' parameter for async call + if ("callback".equals(name)) { + return "paramCallback"; + } + + // should be the same as variable name + return toVarName(name); + } + + @Override + public String toModelName(final String name) { + + final String sanitizedName = sanitizeName(name); + + String nameWithPrefixSuffix = sanitizedName; + if (!StringUtils.isEmpty(modelNamePrefix)) { + // add '_' so that model name can be camelized correctly + nameWithPrefixSuffix = modelNamePrefix + "_" + nameWithPrefixSuffix; + } + + if (!StringUtils.isEmpty(modelNameSuffix)) { + // add '_' so that model name can be camelized correctly + nameWithPrefixSuffix = nameWithPrefixSuffix + "_" + modelNameSuffix; + } + + // camelize the model name + // phone_number => PhoneNumber + final String camelizedName = camelize(nameWithPrefixSuffix); + + // model name cannot use reserved keyword, e.g. return + if (isReservedWord(camelizedName)) { + final String modelName = "Model" + camelizedName; + LOGGER.warn(camelizedName + " (reserved word) cannot be used as model name. Renamed to " + modelName); + return modelName; + } + + // model name starts with number + if (camelizedName.matches("^\\d.*")) { + final String modelName = "Model" + camelizedName; // e.g. 200Response => Model200Response (after camelize) + LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + modelName); + return modelName; + } + + return camelizedName; + } + + @Override + public String toModelFilename(String name) { + // should be the same as the model name + return toModelName(name); + } + + @Override + public String getTypeDeclaration(Property p) { + if (p instanceof ArrayProperty) { + ArrayProperty ap = (ArrayProperty) p; + Property inner = ap.getItems(); + if (inner == null) { + LOGGER.warn(ap.getName() + "(array property) does not have a proper inner type defined"); + // TODO maybe better defaulting to StringProperty than returning null + return null; + } + return getSwaggerType(p) + "<" + getTypeDeclaration(inner) + ">"; + } else if (p instanceof MapProperty) { + MapProperty mp = (MapProperty) p; + Property inner = mp.getAdditionalProperties(); + if (inner == null) { + LOGGER.warn(mp.getName() + "(map property) does not have a proper inner type defined"); + // TODO maybe better defaulting to StringProperty than returning null + return null; + } + return getSwaggerType(p) + ""; + } + return super.getTypeDeclaration(p); + } + + @Override + public String getAlias(String name) { + if (typeAliases != null && typeAliases.containsKey(name)) { + return typeAliases.get(name); + } + return name; + } + + @Override + public String toDefaultValue(Property p) { + if (p instanceof ArrayProperty) { + final ArrayProperty ap = (ArrayProperty) p; + final String pattern = "new ArrayList<%s>()"; + if (ap.getItems() == null) { + return null; + } + + return String.format(pattern, getTypeDeclaration(ap.getItems())); + } else if (p instanceof MapProperty) { + final MapProperty ap = (MapProperty) p; + final String pattern = "new HashMap<%s>()"; + if (ap.getAdditionalProperties() == null) { + return null; + } + + return String.format(pattern, String.format("String, %s", getTypeDeclaration(ap.getAdditionalProperties()))); + } else if (p instanceof IntegerProperty) { + IntegerProperty dp = (IntegerProperty) p; + if (dp.getDefault() != null) { + return dp.getDefault().toString(); + } + return "null"; + } else if (p instanceof LongProperty) { + LongProperty dp = (LongProperty) p; + if (dp.getDefault() != null) { + return dp.getDefault().toString()+"l"; + } + return "null"; + } else if (p instanceof DoubleProperty) { + DoubleProperty dp = (DoubleProperty) p; + if (dp.getDefault() != null) { + return dp.getDefault().toString() + "d"; + } + return "null"; + } else if (p instanceof FloatProperty) { + FloatProperty dp = (FloatProperty) p; + if (dp.getDefault() != null) { + return dp.getDefault().toString() + "f"; + } + return "null"; + } else if (p instanceof BooleanProperty) { + BooleanProperty bp = (BooleanProperty) p; + if (bp.getDefault() != null) { + return bp.getDefault().toString(); + } + return "null"; + } else if (p instanceof StringProperty) { + StringProperty sp = (StringProperty) p; + if (sp.getDefault() != null) { + String _default = sp.getDefault(); + if (sp.getEnum() == null) { + return "\"" + escapeText(_default) + "\""; + } else { + // convert to enum var name later in postProcessModels + return _default; + } + } + return "null"; + } + return super.toDefaultValue(p); + } + + @Override + public void setParameterExampleValue(CodegenParameter p) { + + if (Boolean.TRUE.equals(p.isLong)) { + p.example = "2147483648L"; + } else if (Boolean.TRUE.equals(p.isFile)) { + p.example = "Blob.valueOf('Sample text file\\nContents')"; + } else if (Boolean.TRUE.equals(p.isDate)) { + p.example = "Date.newInstance(1960, 2, 17)"; + } else if (Boolean.TRUE.equals(p.isDateTime)) { + p.example = "Datetime.newInstanceGmt(2013, 11, 12, 3, 3, 3)"; + } else if (Boolean.TRUE.equals(p.isListContainer)) { + p.example = "new " + p.dataType + "{" + p.items.example + "}"; + } else if (Boolean.TRUE.equals(p.isMapContainer)) { + p.example = "new " + p.dataType + "{" + p.items.example + "}"; + } else if (Boolean.TRUE.equals(p.isString)) { + p.example = "'" + p.example + "'"; + } else if ("".equals(p.example) || p.example == null && p.dataType != "Object") { + // Get an example object from the generated model + if (!isReservedWord(p.dataType.toLowerCase())) { + p.example = p.dataType + ".getExample()"; + } + } else { + p.example = "''"; + } + + } + + @Override + public String toExampleValue(Property p) { + if (p == null) { + return ""; + } + + Object obj = p.getExample(); + String example = obj == null ? "" : obj.toString(); + + if (p instanceof ArrayProperty) { + example = "new " + getTypeDeclaration(p) + "{" + toExampleValue( + ((ArrayProperty) p).getItems()) + "}"; + } else if (p instanceof BooleanProperty) { + example = String.valueOf(!"false".equals(example)); + } else if (p instanceof ByteArrayProperty) { + if (example.isEmpty()) { + example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu"; + } + ((ByteArrayProperty) p).setExample(example); + example = "EncodingUtil.base64Decode('" + example + "')"; + } else if (p instanceof DateProperty) { + if (example.matches("^\\d{4}(-\\d{2}){2}")) { + example = example.substring(0, 10).replaceAll("-0?", ", "); + } else if (example.isEmpty()) { + example = "2000, 1, 23"; + } else { + LOGGER.warn(String.format("The example provided for property '%s' is not a valid RFC3339 date. Defaulting to '2000-01-23'. [%s]", p + .getName(), example)); + example = "2000, 1, 23"; + } + example = "Date.newInstance(" + example + ")"; + } else if (p instanceof DateTimeProperty) { + if (example.matches("^\\d{4}([-T:]\\d{2}){5}.+")) { + example = example.substring(0, 19).replaceAll("[-T:]0?", ", "); + } else if (example.isEmpty()) { + example = "2000, 1, 23, 4, 56, 7"; + } else { + LOGGER.warn(String.format("The example provided for property '%s' is not a valid RFC3339 datetime. Defaulting to '2000-01-23T04-56-07Z'. [%s]", p + .getName(), example)); + example = "2000, 1, 23, 4, 56, 7"; + } + example = "Datetime.newInstanceGmt(" + example + ")"; + } else if (p instanceof DecimalProperty) { + example = example.replaceAll("[^-0-9.]", ""); + example = example.isEmpty() ? "1.3579" : example; + } else if (p instanceof FileProperty) { + if (example.isEmpty()) { + example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu"; + ((FileProperty) p).setExample(example); + } + example = "EncodingUtil.base64Decode(" + example + ")"; + } else if (p instanceof EmailProperty) { + if (example.isEmpty()) { + example = "example@example.com"; + ((EmailProperty) p).setExample(example); + } + example = "'" + example + "'"; + } else if (p instanceof LongProperty) { + example = example.isEmpty() ? "123456789L" : example + "L"; + } else if (p instanceof MapProperty) { + example = "new " + getTypeDeclaration(p) + "{'key'=>" + toExampleValue( + ((MapProperty) p).getAdditionalProperties()) + "}"; + } else if (p instanceof ObjectProperty) { + example = example.isEmpty() ? "null" : example; + } else if (p instanceof PasswordProperty) { + example = example.isEmpty() ? "password123" : escapeText(example); + ((PasswordProperty) p).setExample(example); + example = "'" + example + "'"; + } else if (p instanceof RefProperty) { + if(languageSpecificPrimitives().contains(getTypeDeclaration(p))) { + example = getTypeDeclaration(p) + ".getExample()"; + } else { + example = "''"; + } + } else if (p instanceof StringProperty) { + StringProperty sp = (StringProperty) p; + List enums = sp.getEnum(); + if (enums != null && example.isEmpty()) { + example = enums.get(0); + sp.setExample(example); + } else if (example.isEmpty()) { + example = ""; + } else { + example = escapeText(example); + sp.setExample(example); + } + example = "'" + example + "'"; + } else if (p instanceof UUIDProperty) { + example = example.isEmpty() + ? "'046b6c7f-0b8a-43b9-b35d-6489e6daee91'" + : "'" + escapeText(example) + "'"; + } else if (p instanceof BaseIntegerProperty) { + example = example.matches("^-?\\d+$") ? example : "0"; + } else { + example = super.toExampleValue(p); + } + return example; + } + + @Override + public String getSwaggerType(Property p) { + String swaggerType = super.getSwaggerType(p); + + swaggerType = getAlias(swaggerType); + + // don't apply renaming on types from the typeMapping + if (typeMapping.containsKey(swaggerType)) { + return typeMapping.get(swaggerType); + } + + if (null == swaggerType) { + LOGGER.error("No Type defined for Property " + p); + } + return toModelName(swaggerType); + } + + @Override + public String toOperationId(String operationId) { + // throw exception if method name is empty + if (StringUtils.isEmpty(operationId)) { + throw new RuntimeException("Empty method/operation name (operationId) not allowed"); + } + + operationId = camelize(sanitizeName(operationId), true); + + // method name cannot use reserved keyword, e.g. return + if (isReservedWord(operationId)) { + String newOperationId = camelize("call_" + operationId, true); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); + return newOperationId; + } + + return operationId; + } + + @Override + public CodegenModel fromModel(String name, Model model, Map allDefinitions) { + CodegenModel cm = super.fromModel(name, model, allDefinitions); + + // TODO Check enum model handling + if (cm.interfaces == null) { + cm.interfaces = new ArrayList(); + } + + Boolean hasDefaultValues = false; + + // for (de)serializing properties renamed for Apex (e.g. reserved words) + List> propertyMappings = new ArrayList<>(); + for (CodegenProperty p : cm.allVars) { + hasDefaultValues |= p.defaultValue != null; + if (!p.baseName.equals(p.name)) { + Map mapping = new HashMap<>(); + mapping.put("externalName", p.baseName); + mapping.put("internalName", p.name); + propertyMappings.add(mapping); + } + } + + cm.vendorExtensions.put("hasPropertyMappings", !propertyMappings.isEmpty()); + cm.vendorExtensions.put("hasDefaultValues", hasDefaultValues); + cm.vendorExtensions.put("propertyMappings", propertyMappings); + + if (!propertyMappings.isEmpty()) { + cm.interfaces.add("Swagger.MappedProperties"); + } + return cm; + } + + @Override + public void postProcessParameter(CodegenParameter parameter) { + if (parameter.isBodyParam && parameter.isListContainer) { + // items of array bodyParams are being nested an extra level too deep for some reason + parameter.items = parameter.items.items; + setParameterExampleValue(parameter); + } + } + + @Override + public Map postProcessModels(Map objs) { + return postProcessModelsEnum(objs); + } + + private static String getAccept(Operation operation) { + String accepts = null; + String defaultContentType = "application/json"; + if (operation.getProduces() != null && !operation.getProduces().isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (String produces : operation.getProduces()) { + if (defaultContentType.equalsIgnoreCase(produces)) { + accepts = defaultContentType; + break; + } else { + if (sb.length() > 0) { + sb.append(","); + } + sb.append(produces); + } + } + if (accepts == null) { + accepts = sb.toString(); + } + } else { + accepts = defaultContentType; + } + + return accepts; + } + + @Override + protected boolean needToImport(String type) { + return super.needToImport(type) && type.indexOf(".") < 0; + } + + @Override + public String toEnumName(CodegenProperty property) { + return sanitizeName(camelize(property.name)) + "Enum"; + } + + @Override + public String toEnumVarName(String value, String datatype) { + if (value.length() == 0) { + return "EMPTY"; + } + + // for symbol, e.g. $, # + if (getSymbolName(value) != null) { + return getSymbolName(value).toUpperCase(); + } + + // number + if ("Integer".equals(datatype) || "Long".equals(datatype) || + "Float".equals(datatype) || "Double".equals(datatype)) { + String varName = "NUMBER_" + value; + varName = varName.replaceAll("-", "MINUS_"); + varName = varName.replaceAll("\\+", "PLUS_"); + varName = varName.replaceAll("\\.", "_DOT_"); + return varName; + } + + // string + String var = value.replaceAll("\\W+", "_").toUpperCase(); + if (var.matches("\\d.*")) { + return "_" + var; + } else { + return var; + } + } + + @Override + public String toEnumValue(String value, String datatype) { + if ("Integer".equals(datatype) || "Double".equals(datatype)) { + return value; + } else if ("Long".equals(datatype)) { + // add l to number, e.g. 2048 => 2048l + return value + "l"; + } else if ("Float".equals(datatype)) { + // add f to number, e.g. 3.14 => 3.14f + return value + "f"; + } else { + return "\"" + escapeText(value) + "\""; + } + } + + @Override + public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map definitions, Swagger swagger) { + Boolean hasFormParams = false; + for (Parameter p : operation.getParameters()) { + if ("formData".equals(p.getIn())) { + hasFormParams = true; + break; + } + } + + // only support serialization into JSON and urlencoded forms for now + operation.setConsumes( + Collections.singletonList(hasFormParams + ? "application/x-www-form-urlencoded" + : "application/json")); + + // only support deserialization from JSON for now + operation.setProduces(Collections.singletonList("application/json")); + + CodegenOperation op = super.fromOperation( + path, httpMethod, operation, definitions, swagger); + if (op.getHasExamples()) { + // prepare examples for Apex test classes + Property responseProperty = findMethodResponse(operation.getResponses()).getSchema(); + String deserializedExample = toExampleValue(responseProperty); + for (Map example : op.examples) { + example.put("example", escapeText(example.get("example"))); + example.put("deserializedExample", deserializedExample); + } + } + + return op; + } + + private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) { + // This generator uses inline classes to define enums, which breaks when + // dealing with models that have subTypes. To clean this up, we will analyze + // the parent and child models, look for enums that match, and remove + // them from the child models and leave them in the parent. + // Because the child models extend the parents, the enums will be available via the parent. + + // Only bother with reconciliation if the parent model has enums. + if (!parentCodegenModel.hasEnums) { + return codegenModel; + } + + // Get the properties for the parent and child models + final List parentModelCodegenProperties = parentCodegenModel.vars; + List codegenProperties = codegenModel.vars; + + // Iterate over all of the parent model properties + boolean removedChildEnum = false; + for (CodegenProperty parentModelCodegenPropery : parentModelCodegenProperties) { + // Look for enums + if (parentModelCodegenPropery.isEnum) { + // Now that we have found an enum in the parent class, + // and search the child class for the same enum. + Iterator iterator = codegenProperties.iterator(); + while (iterator.hasNext()) { + CodegenProperty codegenProperty = iterator.next(); + if (codegenProperty.isEnum && codegenProperty.equals(parentModelCodegenPropery)) { + // We found an enum in the child class that is + // a duplicate of the one in the parent, so remove it. + iterator.remove(); + removedChildEnum = true; + } + } + } + } + + if(removedChildEnum) { + // If we removed an entry from this model's vars, we need to ensure hasMore is updated + int count = 0, numVars = codegenProperties.size(); + for(CodegenProperty codegenProperty : codegenProperties) { + count += 1; + codegenProperty.hasMore = (count < numVars) ? true : false; + } + codegenModel.vars = codegenProperties; + } + return codegenModel; + } + + private static String sanitizePackageName(String packageName) { + packageName = packageName.trim(); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_"); + if(Strings.isNullOrEmpty(packageName)) { + return "invalidPackageName"; + } + return packageName; + } + + + public void setSerializableModel(Boolean serializableModel) { + this.serializableModel = serializableModel; + } + + private String sanitizePath(String p) { + //prefer replace a ", instead of a fuLL URL encode for readability + return p.replaceAll("\"", "%22"); + } + + public String toRegularExpression(String pattern) { + return escapeText(pattern); + } + + public boolean convertPropertyToBoolean(String propertyKey) { + boolean booleanValue = false; + if (additionalProperties.containsKey(propertyKey)) { + booleanValue = Boolean.valueOf(additionalProperties.get(propertyKey).toString()); + } + + return booleanValue; + } + + public void writePropertyBack(String propertyKey, boolean value) { + additionalProperties.put(propertyKey, value); + } + + @Override + public String sanitizeTag(String tag) { + return camelize(sanitizeName(tag)); + } + + @Override + public String toModelTestFilename(String name) { + return toModelName(name) + "Test"; + } + +} diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ApexClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ApexClientCodegen.java index d1242c95831e..5c9118d14bfd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ApexClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ApexClientCodegen.java @@ -1,55 +1,19 @@ -/* - * 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.OpenAPI; -import io.swagger.v3.oas.models.Operation; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.media.ArraySchema; -import io.swagger.v3.oas.models.media.BooleanSchema; -import io.swagger.v3.oas.models.media.ByteArraySchema; -import io.swagger.v3.oas.models.media.EmailSchema; -import io.swagger.v3.oas.models.media.FileSchema; -import io.swagger.v3.oas.models.media.PasswordSchema; -import io.swagger.v3.oas.models.media.Schema; -import io.swagger.v3.oas.models.responses.ApiResponse; - -import org.apache.commons.lang3.StringUtils; -import org.openapitools.codegen.CliOption; -import org.openapitools.codegen.CodegenModel; -import org.openapitools.codegen.CodegenOperation; -import org.openapitools.codegen.CodegenParameter; -import org.openapitools.codegen.CodegenProperty; -import org.openapitools.codegen.CodegenType; -import org.openapitools.codegen.SupportingFile; -import org.openapitools.codegen.utils.ModelUtils; +package io.swagger.codegen.languages; + +import io.swagger.codegen.*; +import io.swagger.models.Info; +import io.swagger.models.Model; +import io.swagger.models.Operation; +import io.swagger.models.Swagger; +import io.swagger.models.parameters.Parameter; +import io.swagger.models.properties.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; +import java.util.*; -public class ApexClientCodegen extends AbstractJavaCodegen { +public class ApexClientCodegen extends AbstractApexCodegen { private static final String CLASS_PREFIX = "classPrefix"; private static final String API_VERSION = "apiVersion"; @@ -57,25 +21,23 @@ public class ApexClientCodegen extends AbstractJavaCodegen { private static final String NAMED_CREDENTIAL = "namedCredential"; private static final Logger LOGGER = LoggerFactory.getLogger(ApexClientCodegen.class); private String classPrefix = "Swag"; - private String apiVersion = "39.0"; + private String apiVersion = "42.0"; private String buildMethod = "sfdx"; private String namedCredential = classPrefix; private String srcPath = "force-app/main/default/"; + private String sfdxConfigPath = "config/"; + private HashMap primitiveDefaults = new HashMap(); public ApexClientCodegen() { super(); importMapping.clear(); - testFolder = sourceFolder = srcPath; - embeddedTemplateDir = templateDir = "apex"; outputFolder = "generated-code" + File.separator + "apex"; - apiPackage = "classes"; - modelPackage = "classes"; + modelPackage = apiPackage = srcPath + "classes"; testPackage = "force-app.main.default.classes"; modelNamePrefix = classPrefix; - dateLibrary = ""; apiTemplateFiles.put("api.mustache", ".cls"); apiTemplateFiles.put("cls-meta.mustache", ".cls-meta.xml"); @@ -109,30 +71,42 @@ public ApexClientCodegen() { typeMapping.put("short", "Integer"); typeMapping.put("UUID", "String"); + // https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_reserved_words.htm setReservedWordsLowerCase( - Arrays.asList("abstract", "activate", "and", "any", "array", "as", "asc", "autonomous", - "begin", "bigdecimal", "blob", "break", "bulk", "by", "byte", "case", "cast", - "catch", "char", "class", "collect", "commit", "const", "continue", - "convertcurrency", "date", "decimal", "default", "delete", "desc", "do", "else", - "end", "enum", "exception", "exit", "export", "extends", "false", "final", - "finally", "float", "for", "from", "future", "global", "goto", "group", "having", - "hint", "if", "implements", "import", "inner", "insert", "instanceof", "int", - "interface", "into", "join", "last_90_days", "last_month", "last_n_days", - "last_week", "like", "limit", "list", "long", "loop", "map", "merge", "new", - "next_90_days", "next_month", "next_n_days", "next_week", "not", "null", "nulls", - "number", "object", "of", "on", "or", "outer", "override", "package", "parallel", - "pragma", "private", "protected", "public", "retrieve", "return", "returning", - "rollback", "savepoint", "search", "select", "set", "short", "sort", "stat", - "static", "super", "switch", "synchronized", "system", "testmethod", "then", "this", - "this_month", "this_week", "throw", "today", "tolabel", "tomorrow", "transaction", - "trigger", "true", "try", "type", "undelete", "update", "upsert", "using", - "virtual", "webservice", "when", "where", "while", "yesterday" - )); + Arrays.asList("abstract", "activate", "and", "any", "array", "as", "asc", "autonomous", + "begin", "bigdecimal", "blob", "break", "bulk", "by", "byte", "case", "cast", + "catch", "char", "class", "collect", "commit", "const", "continue", + "convertcurrency", "currency", "date", "datetime", "decimal", "default", "delete", "desc", "do", "else", + "end", "enum", "exception", "exit", "export", "extends", "false", "final", + "finally", "float", "for", "from", "future", "global", "goto", "group", "having", + "hint", "if", "implements", "import", "in", "inner", "insert", "instanceof", "int", + "interface", "into", "join", "last_90_days", "last_month", "last_n_days", + "last_week", "like", "limit", "list", "long", "loop", "map", "merge", "new", + "next_90_days", "next_month", "next_n_days", "next_week", "not", "null", "nulls", + "number", "object", "of", "on", "or", "outer", "override", "package", "parallel", + "pragma", "private", "protected", "public", "retrieve", "return", "returning", + "rollback", "savepoint", "search", "select", "set", "short", "sort", "stat", + "static", "super", "switch", "synchronized", "system", "testmethod", "then", "this", + "this_month", "this_week", "throw", "time", "today", "tolabel", "tomorrow", "transaction", + "trigger", "true", "try", "type", "undelete", "update", "upsert", "using", + "virtual", "webservice", "when", "where", "while", "yesterday" + )); languageSpecificPrimitives = new HashSet( - Arrays.asList("Blob", "Boolean", "Date", "Datetime", "Decimal", "Double", "ID", - "Integer", "Long", "Object", "String", "Time" - )); + Arrays.asList("Blob", "Boolean", "Date", "Datetime", "Decimal", "Double", "ID", + "Integer", "Long", "Object", "String", "Time" + )); + + primitiveDefaults.put("Boolean", true); + primitiveDefaults.put("Decimal", 1); + primitiveDefaults.put("Double", 1); + primitiveDefaults.put("Integer", 1); + primitiveDefaults.put("Long", 1); + primitiveDefaults.put("String", ""); + + instantiationTypes.put("array", "List"); + instantiationTypes.put("map", "Map"); + } @Override @@ -150,18 +124,60 @@ public void processOpts() { additionalProperties.put(API_VERSION, apiVersion); if (additionalProperties.containsKey(BUILD_METHOD)) { - setBuildMethod((String) additionalProperties.get(BUILD_METHOD)); + setBuildMethod((String)additionalProperties.get(BUILD_METHOD)); } additionalProperties.put(BUILD_METHOD, buildMethod); if (additionalProperties.containsKey(NAMED_CREDENTIAL)) { - setNamedCredential((String) additionalProperties.get(NAMED_CREDENTIAL)); + setNamedCredential((String)additionalProperties.get(NAMED_CREDENTIAL)); } additionalProperties.put(NAMED_CREDENTIAL, namedCredential); postProcessOpts(); } + @Override + public void preprocessSwagger(Swagger swagger) { + Info info = swagger.getInfo(); + String calloutLabel = info.getTitle(); + additionalProperties.put("calloutLabel", calloutLabel); + String sanitized = sanitizeName(calloutLabel); + additionalProperties.put("calloutName", sanitized); + supportingFiles.add(new SupportingFile("namedCredential.mustache", srcPath + "/namedCredentials", + sanitized + ".namedCredential-meta.xml" + )); + + if (additionalProperties.get(BUILD_METHOD).equals("sfdx")) { + generateSfdxSupportingFiles(); + } else if (additionalProperties.get(BUILD_METHOD).equals("ant")) { + generateAntSupportingFiles(); + } + } + + @Override + public String escapeQuotationMark(String input) { + return input.replace("'", "\\'"); + } + + @Override + public String escapeUnsafeCharacters(String input) { + return input.replace("*/", "*_/").replace("/*", "/_*"); + } + + @Override + public String escapeText(String input) { + if (input == null) { + return input; + } + + return input.replace("'", "\\'").replace("\n", "\\n").replace("\r", "\\r").replace("*/", "*_/").replace("/*", "/_*"); + } + + @Override + public String toApiName(String name) { + return camelize(classPrefix + super.toApiName(name)); + } + @Override public String escapeReservedWord(String name) { // Identifiers must start with a letter @@ -180,27 +196,29 @@ public String toModelName(String name) { } @Override - public String toDefaultValue(Schema p) { + public String toDefaultValue(Property p) { String out = null; - if (ModelUtils.isArraySchema(p)) { - Schema inner = ((ArraySchema) p).getItems(); + if (p instanceof ArrayProperty) { + Property inner = ((ArrayProperty) p).getItems(); out = String.format( - "new List<%s>()", - inner == null ? "Object" : getTypeDeclaration(inner) + "new List<%s>()", + inner == null ? "Object" : getTypeDeclaration(inner) ); - } else if (ModelUtils.isBooleanSchema(p)) { + } else if (p instanceof BooleanProperty) { // true => "true", false => "false", null => "null" - out = String.valueOf(((BooleanSchema) p).getDefault()); - } else if (ModelUtils.isLongSchema(p)) { // long - out = p.getDefault() == null ? out : p.getDefault().toString() + "L"; - } else if (ModelUtils.isMapSchema(p)) { - Schema inner = (Schema) p.getAdditionalProperties(); + out = String.valueOf(((BooleanProperty) p).getDefault()); + } else if (p instanceof LongProperty) { + Long def = ((LongProperty) p).getDefault(); + out = def == null ? out : def.toString() + "L"; + } else if (p instanceof MapProperty) { + Property inner = ((MapProperty) p).getAdditionalProperties(); String s = inner == null ? "Object" : getTypeDeclaration(inner); out = String.format("new Map()", s); - } else if (ModelUtils.isStringSchema(p)) { - String def = (String) p.getDefault(); + } else if (p instanceof StringProperty) { + StringProperty sp = (StringProperty) p; + String def = sp.getDefault(); if (def != null) { - out = p.getEnum() == null ? String.format("'%s'", escapeText(def)) : def; + out = sp.getEnum() == null ? String.format("'%s'", escapeText(def)) : def; } } else { out = super.toDefaultValue(p); @@ -210,256 +228,12 @@ public String toDefaultValue(Schema p) { return "null".equals(out) ? null : out; } - @Override - public void setParameterExampleValue(CodegenParameter p) { - String example; - - if (p.defaultValue == null) { - example = p.example; - } else { - example = p.defaultValue; - } - - String type = p.baseType; - if (type == null) { - type = p.dataType; - } - - if (Boolean.TRUE.equals(p.isInteger)) { - if (example == null) { - example = "56"; - } - } else if (Boolean.TRUE.equals(p.isLong)) { - if (example == null) { - example = "2147483648L"; - } - } else if (Boolean.TRUE.equals(p.isDouble) - || Boolean.TRUE.equals(p.isFloat) - || Boolean.TRUE.equals(p.isNumber)) { - if (example == null) { - example = "3.4"; - } - } else if (Boolean.TRUE.equals(p.isBoolean)) { - if (Boolean.parseBoolean(p.example)) { - p.example = "1"; - } else { - p.example = "0"; - } - } else if (Boolean.TRUE.equals(p.isFile) || Boolean.TRUE.equals(p.isBinary)) { - example = "Blob.valueOf('Sample text file\\nContents')"; - } else if (Boolean.TRUE.equals(p.isByteArray)) { - if (example == null) { - example = "YmFzZSA2NCBkYXRh"; - } - example = "\"" + escapeText(example) + "\""; - } else if (Boolean.TRUE.equals(p.isDate)) { - if (example == null) { - example = "1960, 2, 17"; - } - example = "Date.newInstance(" + escapeText(p.example) + ")"; - } else if (Boolean.TRUE.equals(p.isDateTime)) { - if (example == null) { - example = "2013, 11, 12, 3, 3, 3"; - } - example = "Datetime.newInstanceGmt(" + escapeText(p.example) + ")"; - } else if (Boolean.TRUE.equals(p.isString)) { - if (example == null) { - example = p.paramName + "_example"; - } - example = "\'" + escapeText(example) + "\'"; - - } else if (!languageSpecificPrimitives.contains(type)) { - // type is a model class, e.g. User - example = type + ".getExample()"; - } - - // container - if (Boolean.TRUE.equals(p.isListContainer)) { - example = setPropertyExampleValue(p.items); - example = "new " + p.dataType + "{" + example + "}"; - } else if (Boolean.TRUE.equals(p.isMapContainer)) { - example = setPropertyExampleValue(p.items); - example = "new " + p.dataType + "{" + example + "}"; - } else if (example == null) { - example = "null"; - } - - p.example = example; - } - - protected String setPropertyExampleValue(CodegenProperty p) { - String example; - - if (p == null) { - return "null"; - } - - if (p.defaultValue == null) { - example = p.example; - } else { - example = p.defaultValue; - } - - String type = p.baseType; - if (type == null) { - type = p.dataType; - } - - if (Boolean.TRUE.equals(p.isInteger)) { - if (example == null) { - example = "56"; - } - } else if (Boolean.TRUE.equals(p.isLong)) { - if (example == null) { - example = "2147483648L"; - } - } else if (Boolean.TRUE.equals(p.isDouble) - || Boolean.TRUE.equals(p.isFloat) - || Boolean.TRUE.equals(p.isNumber)) { - if (example == null) { - example = "3.4"; - } - } else if (Boolean.TRUE.equals(p.isBoolean)) { - if (example == null) { - example = "true"; - } - } else if (Boolean.TRUE.equals(p.isFile) || Boolean.TRUE.equals(p.isBinary)) { - if (example == null) { - example = "Blob.valueOf('Sample text file\\nContents')"; - } - example = escapeText(example); - } else if (Boolean.TRUE.equals(p.isDate)) { - if (example == null) { - example = "1960, 2, 17"; - } - example = "Date.newInstance(" + escapeText(p.example) + ")"; - } else if (Boolean.TRUE.equals(p.isDateTime)) { - if (example == null) { - example = "2013, 11, 12, 3, 3, 3"; - } - example = "Datetime.newInstanceGmt(" + escapeText(p.example) + ")"; - } else if (Boolean.TRUE.equals(p.isString)) { - if (example == null) { - example = p.name + "_example"; - } - example = "\'" + escapeText(example) + "\'"; - - } else if (!languageSpecificPrimitives.contains(type)) { - // type is a model class, e.g. User - example = type + ".getExample()"; - } - - return example; - } - - @Override - public CodegenModel fromModel(String name, Schema model, Map allDefinitions) { - CodegenModel cm = super.fromModel(name, model, allDefinitions); - if (cm.interfaces == null) { - cm.interfaces = new ArrayList(); - } - - Boolean hasDefaultValues = false; - - // for (de)serializing properties renamed for Apex (e.g. reserved words) - List> propertyMappings = new ArrayList<>(); - for (CodegenProperty p : cm.allVars) { - hasDefaultValues |= p.defaultValue != null; - if (!p.baseName.equals(p.name)) { - Map mapping = new HashMap<>(); - mapping.put("externalName", p.baseName); - mapping.put("internalName", p.name); - propertyMappings.add(mapping); - } - } - - cm.vendorExtensions.put("hasPropertyMappings", !propertyMappings.isEmpty()); - cm.vendorExtensions.put("hasDefaultValues", hasDefaultValues); - cm.vendorExtensions.put("propertyMappings", propertyMappings); - - if (!propertyMappings.isEmpty()) { - cm.interfaces.add("Swagger.MappedProperties"); - } - return cm; - } - - /* the following workaround is no longer needed - @Override - public void postProcessParameter(CodegenParameter parameter) { - if (parameter.isBodyParam && parameter.isListContainer) { - // items of array bodyParams are being nested an extra level too deep for some reason - parameter.items = parameter.items.items; - setParameterExampleValue(parameter); - } - } - */ - - @Override - public void preprocessOpenAPI(OpenAPI openAPI) { - Info info = openAPI.getInfo(); - String calloutLabel = info.getTitle(); - additionalProperties.put("calloutLabel", calloutLabel); - String sanitized = sanitizeName(calloutLabel); - additionalProperties.put("calloutName", sanitized); - supportingFiles.add(new SupportingFile("namedCredential.mustache", srcPath + "/namedCredentials", - sanitized + ".namedCredential" - )); - - if (additionalProperties.get(BUILD_METHOD).equals("sfdx")) { - generateSfdxSupportingFiles(); - } else if (additionalProperties.get(BUILD_METHOD).equals("ant")) { - generateAntSupportingFiles(); - } - - } - - @Override - public CodegenOperation fromOperation(String path, - String httpMethod, - Operation operation, - Map definitions, - OpenAPI openAPI) { - Boolean hasFormParams = false; - // comment out the following as there's no consume/produce in OAS3.0 - // we can move the logic below to postProcessOperations if needed - /* - // only support serialization into JSON and urlencoded forms for now - operation.setConsumes( - Collections.singletonList(hasFormParameter(operation) - ? "application/x-www-form-urlencoded" - : "application/json")); - - // only support deserialization from JSON for now - operation.setProduces(Collections.singletonList("application/json")); - */ - - CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions, openAPI); - - if (op.getHasExamples()) { - // prepare examples for Apex test classes - ApiResponse responseProperty = findMethodResponse(operation.getResponses()); - String deserializedExample = toExampleValue(ModelUtils.getSchemaFromResponse(responseProperty)); - for (Map example : op.examples) { - example.put("example", escapeText(example.get("example"))); - example.put("deserializedExample", deserializedExample); - } - } - - return op; - } - - @Override - public String escapeQuotationMark(String input) { - return input.replace("'", "\\'"); - } - public void setBuildMethod(String buildMethod) { if (buildMethod.equals("ant")) { this.srcPath = "deploy/"; } else { this.srcPath = "src/"; } - testFolder = sourceFolder = srcPath; this.buildMethod = buildMethod; } @@ -488,145 +262,22 @@ private String toApiVersion(String apiVersion) { private void postProcessOpts() { supportingFiles.add( - new SupportingFile("client.mustache", srcPath + "classes", classPrefix + "Client.cls")); + new SupportingFile("client.mustache", srcPath + "classes", classPrefix + "Client.cls")); supportingFiles.add(new SupportingFile("cls-meta.mustache", srcPath + "classes", - classPrefix + "Client.cls-meta.xml" + classPrefix + "Client.cls-meta.xml" )); } - @Override - public String escapeText(String input) { - if (input == null) { - return input; - } - - return input.replace("'", "\\'").replace("\n", "\\n").replace("\r", "\\r"); - } - - @Override - public String toModelTestFilename(String name) { - return toModelName(name) + "Test"; - } - - @Override - public String toExampleValue(Schema p) { - if (p == null) { - return ""; - } - Object obj = p.getExample(); - String example = obj == null ? "" : obj.toString(); - if (ModelUtils.isArraySchema(p)) { // array - example = "new " + getTypeDeclaration(p) + "{" + toExampleValue( - ((ArraySchema) p).getItems()) + "}"; - } else if (ModelUtils.isBooleanSchema(p)) { - example = String.valueOf(!"false".equals(example)); - } else if (ModelUtils.isByteArraySchema(p)) { // byte array - if (example.isEmpty()) { - example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu"; - } - ((ByteArraySchema) p).setExample(example); - example = "EncodingUtil.base64Decode('" + example + "')"; - } else if (ModelUtils.isDateSchema(p)) { // date - if (example.matches("^\\d{4}(-\\d{2}){2}")) { - example = example.substring(0, 10).replaceAll("-0?", ", "); - } else if (example.isEmpty()) { - example = "2000, 1, 23"; - } else { - LOGGER.warn(String.format("The example provided for property '%s' is not a valid RFC3339 date. Defaulting to '2000-01-23'. [%s]", p - .getName(), example)); - example = "2000, 1, 23"; - } - example = "Date.newInstance(" + example + ")"; - } else if (ModelUtils.isDateTimeSchema(p)) { // datetime - if (example.matches("^\\d{4}([-T:]\\d{2}){5}.+")) { - example = example.substring(0, 19).replaceAll("[-T:]0?", ", "); - } else if (example.isEmpty()) { - example = "2000, 1, 23, 4, 56, 7"; - } else { - LOGGER.warn(String.format("The example provided for property '%s' is not a valid RFC3339 datetime. Defaulting to '2000-01-23T04-56-07Z'. [%s]", p - .getName(), example)); - example = "2000, 1, 23, 4, 56, 7"; - } - example = "Datetime.newInstanceGmt(" + example + ")"; - } else if (ModelUtils.isNumberSchema(p)) { // number - example = example.replaceAll("[^-0-9.]", ""); - example = example.isEmpty() ? "1.3579" : example; - } else if (ModelUtils.isFileSchema(p)) { // file - if (example.isEmpty()) { - example = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu"; - ((FileSchema) p).setExample(example); - } - example = "EncodingUtil.base64Decode(" + example + ")"; - } else if (ModelUtils.isEmailSchema(p)) { // email - if (example.isEmpty()) { - example = "example@example.com"; - ((EmailSchema) p).setExample(example); - } - example = "'" + example + "'"; - } else if (ModelUtils.isLongSchema(p)) { // long - example = example.isEmpty() ? "123456789L" : example + "L"; - } else if (ModelUtils.isMapSchema(p)) { // map - example = "new " + getTypeDeclaration(p) + "{'key'=>" + toExampleValue( - (Schema) p.getAdditionalProperties()) + "}"; - } else if (ModelUtils.isObjectSchema(p)) { // object - example = example.isEmpty() ? "null" : example; - } else if (ModelUtils.isPasswordSchema(p)) { // password - example = example.isEmpty() ? "password123" : escapeText(example); - ((PasswordSchema) p).setExample(example); - example = "'" + example + "'"; - } else if (!StringUtils.isEmpty(p.get$ref())) { - example = getTypeDeclaration(p) + ".getExample()"; - } else if (ModelUtils.isUUIDSchema(p)) { - example = example.isEmpty() - ? "'046b6c7f-0b8a-43b9-b35d-6489e6daee91'" - : "'" + escapeText(example) + "'"; - } else if (ModelUtils.isStringSchema(p)) { // string - List enums = p.getEnum(); - if (enums != null && example.isEmpty()) { - example = enums.get(0); - p.setExample(example); - } else if (example.isEmpty()) { - example = "aeiou"; - } else { - example = escapeText(example); - p.setExample(example); - } - example = "'" + example + "'"; - } - - return example; - } - - @Override - public String toApiName(String name) { - return camelize(classPrefix + super.toApiName(name)); - } - @Override public void updateCodegenPropertyEnum(CodegenProperty var) { super.updateCodegenPropertyEnum(var); if (var.isEnum && var.example != null) { String example = var.example.replace("'", ""); - example = toEnumVarName(example, var.dataType); + example = toEnumVarName(example, var.datatype); var.example = toEnumDefaultValue(example, var.datatypeWithEnum); } } - @Override - public CodegenType getTag() { - return CodegenType.CLIENT; - } - - @Override - public String getName() { - return "apex"; - } - - @Override - public String getHelp() { - return "Generates an Apex API client library (beta)."; - } - private void generateAntSupportingFiles() { supportingFiles.add(new SupportingFile("package.mustache", "deploy", "package.xml")); @@ -638,11 +289,17 @@ private void generateAntSupportingFiles() { supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); writeOptional(outputFolder, new SupportingFile("README_ant.mustache", "README.md")); + } private void generateSfdxSupportingFiles() { - supportingFiles.add(new SupportingFile("sfdx.mustache", "", "sfdx-oss-manifest.json")); + + supportingFiles.add(new SupportingFile("sfdx-project-scratch-def.json", sfdxConfigPath, "project-scratch-def.json")); + supportingFiles.add(new SupportingFile("sfdx-project.json.mustache", "sfdx-project.json")); + writeOptional(outputFolder, new SupportingFile("README_sfdx.mustache", "README.md")); + } + } diff --git a/modules/openapi-generator/src/main/resources/apex/README_sfdx.mustache b/modules/openapi-generator/src/main/resources/apex/README_sfdx.mustache index 50f428b51283..c65a0d10b770 100644 --- a/modules/openapi-generator/src/main/resources/apex/README_sfdx.mustache +++ b/modules/openapi-generator/src/main/resources/apex/README_sfdx.mustache @@ -100,7 +100,7 @@ Class | Method | HTTP request | Description {{/isBasic}} {{#isOAuth}}- **Type**: OAuth - **Flow**: {{flow}} -- **Authorizatoin URL**: {{authorizationUrl}} +- **Authorization URL**: {{authorizationUrl}} - **Scopes**: {{^scopes}}N/A{{/scopes}} {{#scopes}} - {{scope}}: {{description}} {{/scopes}} diff --git a/modules/openapi-generator/src/main/resources/apex/Swagger.cls b/modules/openapi-generator/src/main/resources/apex/Swagger.cls index 172c3038111c..bb4e44f79717 100644 --- a/modules/openapi-generator/src/main/resources/apex/Swagger.cls +++ b/modules/openapi-generator/src/main/resources/apex/Swagger.cls @@ -271,9 +271,7 @@ public class Swagger { @TestVisible protected virtual void applyAuthentication(List names, Map headers, List query) { - for (Authentication auth : getAuthMethods(names)) { - auth.apply(headers, query); - } + // TODO Check auth methods } @TestVisible @@ -298,7 +296,7 @@ public class Swagger { protected virtual String toEndpoint(String path, Map params, List queryParams) { String query = '?' + paramsToString(queryParams); - return '"callout:' + calloutName + toPath(path, params) + query.removeEnd('?') + '""'; + return 'callout:' + calloutName + toPath(path, params) + query.removeEnd('?'); } @TestVisible diff --git a/modules/openapi-generator/src/main/resources/apex/SwaggerTest.cls b/modules/openapi-generator/src/main/resources/apex/SwaggerTest.cls index e3cec8831c69..d95e9b60aa8e 100644 --- a/modules/openapi-generator/src/main/resources/apex/SwaggerTest.cls +++ b/modules/openapi-generator/src/main/resources/apex/SwaggerTest.cls @@ -292,7 +292,7 @@ private class SwaggerTest { new Swagger.Param('foo', 'bar'), new Swagger.Param('bat', '123') }; - String expected = 'https://www.mccombs.utexas.edu/departments/finance?foo=bar&bat=123'; + String expected = 'callout:Winkelmeyer/departments/finance?foo=bar&bat=123'; String actual = client.toEndpoint(path, params, queryParams); System.assertEquals(expected, actual); } @@ -360,7 +360,8 @@ private class SwaggerTest { private class MockApiClient extends Swagger.ApiClient { public MockApiClient() { - basePath = 'https://www.mccombs.utexas.edu'; + basePath = 'https://blog.winkelmeyer.com'; + calloutName = 'Winkelmeyer'; } } } \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/apex/api.mustache b/modules/openapi-generator/src/main/resources/apex/api.mustache index ebbef7283f65..700c66eb15c6 100644 --- a/modules/openapi-generator/src/main/resources/apex/api.mustache +++ b/modules/openapi-generator/src/main/resources/apex/api.mustache @@ -88,13 +88,13 @@ public class {{classname}} { {{/headerParams}} }{{/hasHeaderParams}}{{^hasHeaderParams}}(){{/hasHeaderParams}}, {{#hasProduces}} - new List{ {{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}} }, + new List{ {{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}} {{^hasProduces}} new List(), {{/hasProduces}} {{#hasConsumes}} - new List{ {{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}} }, + new List{ {{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}} }, {{/hasConsumes}} {{^hasConsumes}} new List(), diff --git a/modules/openapi-generator/src/main/resources/apex/api_test.mustache b/modules/openapi-generator/src/main/resources/apex/api_test.mustache index f7a3cf0a63fe..c5db48989980 100644 --- a/modules/openapi-generator/src/main/resources/apex/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/apex/api_test.mustache @@ -34,18 +34,19 @@ private class {{classname}}Test { {{{returnType}}} response; {{{returnType}}} expectedResponse; {{/returnType}} + String js = ''; {{#authMethods}} client = new {{classPrefix}}Client(); api = new {{classname}}(client);{{#isApiKey}} - ((Swagger.ApiKeyAuth){{/isApiKey}} client.getAuthentication('{{name}}'); - {{#isApiKey}} - client.setApiKey('foo-bar-api-key'); + ((Swagger.ApiKeyAuth)client.getAuthentication('{{name}}')).setApiKey('foo-bar-api-key'); {{/isApiKey}} {{#examples}} + + js = JSON.serialize({{{deserializedExample}}}); res.setHeader('Content-Type', '{{contentType}}'); - res.setBody('{{{example}}}'); + res.setBody(js); expectedResponse = {{{deserializedExample}}}; response = ({{{returnType}}}) api.{{operationId}}({{#hasParams}}params{{/hasParams}}); System.assertEquals(expectedResponse, response); @@ -59,8 +60,9 @@ private class {{classname}}Test { api = new {{classname}}(new {{classPrefix}}Client()); {{#examples}} + js = JSON.serialize({{{deserializedExample}}}); res.setHeader('Content-Type', '{{contentType}}'); - res.setBody('{{{example}}}'); + res.setBody(js); expectedResponse = {{{deserializedExample}}}; response = ({{{returnType}}}) api.{{operationId}}({{#hasParams}}params{{/hasParams}}); System.assertEquals(expectedResponse, response); diff --git a/modules/openapi-generator/src/main/resources/apex/git_push.sh.mustache b/modules/openapi-generator/src/main/resources/apex/git_push.sh.mustache index 8a32e53995d6..e153ce23ecf4 100644 --- a/modules/openapi-generator/src/main/resources/apex/git_push.sh.mustache +++ b/modules/openapi-generator/src/main/resources/apex/git_push.sh.mustache @@ -1,7 +1,7 @@ #!/bin/sh # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ # -# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" +# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" git_user_id=$1 git_repo_id=$2 @@ -36,7 +36,7 @@ git_remote=`git remote` if [ "$git_remote" = "" ]; then # git remote not defined if [ "$GIT_TOKEN" = "" ]; then - echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment." git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git else git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git diff --git a/modules/openapi-generator/src/main/resources/apex/licenseInfo.mustache b/modules/openapi-generator/src/main/resources/apex/licenseInfo.mustache index 335db1c59381..94c36dda3af5 100644 --- a/modules/openapi-generator/src/main/resources/apex/licenseInfo.mustache +++ b/modules/openapi-generator/src/main/resources/apex/licenseInfo.mustache @@ -5,7 +5,7 @@ * {{#version}}OpenAPI spec version: {{{version}}}{{/version}} * {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ diff --git a/modules/openapi-generator/src/main/resources/apex/model_test.mustache b/modules/openapi-generator/src/main/resources/apex/model_test.mustache index 7b22a41e5576..3aef0d655725 100644 --- a/modules/openapi-generator/src/main/resources/apex/model_test.mustache +++ b/modules/openapi-generator/src/main/resources/apex/model_test.mustache @@ -45,15 +45,6 @@ private class {{classname}}Test { System.assert({{classVarName}}4.equals({{classVarName}}3)); } - @isTest - private static void notEqualsUnlikeInstance() { - {{classname}} {{classVarName}}1 = {{classname}}.getExample(); - {{classname}} {{classVarName}}2 = new {{classname}}(); - - System.assertEquals(false, {{classVarName}}1.equals({{classVarName}}2)); - System.assertEquals(false, {{classVarName}}2.equals({{classVarName}}1)); - } - @isTest private static void notEqualsDifferentType() { {{classname}} {{classVarName}}1 = {{classname}}.getExample(); diff --git a/modules/openapi-generator/src/main/resources/apex/package.mustache b/modules/openapi-generator/src/main/resources/apex/package.mustache index e05b18ab7e36..e13680359baf 100644 --- a/modules/openapi-generator/src/main/resources/apex/package.mustache +++ b/modules/openapi-generator/src/main/resources/apex/package.mustache @@ -3,7 +3,7 @@ {{appName}} API Client Client library for calling the {{appName}} API.{{#appDescription}} {{{appDescription}}}{{/appDescription}} -Generated with OpenAPI Generator (https://openapi-generator.tech) +Generated with Swagger Codegen (github.com/swagger-api/swagger-codegen) {{#apiInfo}} {{#apis}} diff --git a/modules/openapi-generator/src/main/resources/apex/pojo.mustache b/modules/openapi-generator/src/main/resources/apex/pojo.mustache index c26649e959d8..320b90922d84 100644 --- a/modules/openapi-generator/src/main/resources/apex/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/apex/pojo.mustache @@ -6,13 +6,15 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{#interfac {{#isEnum}} {{^isContainer}} {{>modelInnerEnum}} - {{/isContainer}} - {{#isContainer}} - {{#mostInnerItems}} -{{>modelInnerEnum}} - {{/mostInnerItems}} {{/isContainer}} {{/isEnum}} + {{#items.isEnum}} + {{#items}} + {{^isContainer}} +{{>modelInnerEnum}} + {{/isContainer}} + {{/items}} + {{/items.isEnum}} /** {{#description}} * {{{description}}} @@ -58,16 +60,17 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{#interfac public static {{classname}} getExample() { {{classname}} {{classVarName}} = new {{classname}}(); {{#vars}} - {{classVarName}}.{{name}} = {{{example}}}; + {{#example}}{{classVarName}}.{{name}} = {{{example}}};{{/example}} {{/vars}} return {{classVarName}}; } public Boolean equals(Object obj) { - if (obj instanceof {{classname}}) { + if (obj instanceof {{classname}}) { {{#hasVars}} {{classname}} {{classVarName}} = ({{classname}}) obj; return {{#vars}}this.{{name}} == {{classVarName}}.{{name}}{{#hasMore}} - && {{/hasMore}}{{/vars}}; + && {{/hasMore}}{{/vars}};{{/hasVars}}{{^hasVars}} + return true;{{/hasVars}} } return false; } diff --git a/modules/openapi-generator/src/main/resources/apex/pojo_doc.mustache b/modules/openapi-generator/src/main/resources/apex/pojo_doc.mustache index 07b73cc6f5f8..0e4c07498669 100644 --- a/modules/openapi-generator/src/main/resources/apex/pojo_doc.mustache +++ b/modules/openapi-generator/src/main/resources/apex/pojo_doc.mustache @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -{{#vars}}**{{name}}** | {{#isEnum}}[**{{datatypeWithEnum}}**](#{{datatypeWithEnum}}){{/isEnum}}{{^isEnum}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}}{{/isEnum}} | {{description}} | {{^required}} [optional]{{/required}}{{#readOnly}} [readonly]{{/readOnly}} +{{#vars}}**{{name}}** | {{#isEnum}}[**{{datatypeWithEnum}}**](#{{datatypeWithEnum}}){{/isEnum}}{{^isEnum}}{{#isPrimitiveType}}**{{datatype}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{datatype}}**]({{complexType}}.md){{/isPrimitiveType}}{{/isEnum}} | {{description}} | {{^required}} [optional]{{/required}}{{#readOnly}} [readonly]{{/readOnly}} {{/vars}} {{#vars}}{{#isEnum}} diff --git a/modules/openapi-generator/src/main/resources/apex/sfdx-project-scratch-def.json b/modules/openapi-generator/src/main/resources/apex/sfdx-project-scratch-def.json new file mode 100644 index 000000000000..36aace552669 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/apex/sfdx-project-scratch-def.json @@ -0,0 +1,8 @@ +{ + "orgName": "muenzpraeger - René Winkelmeyer", + "edition": "Developer", + "orgPreferences": { + "enabled": ["S1DesktopEnabled"], + "disabled": ["S1EncryptedStoragePref2"] + } +} diff --git a/modules/openapi-generator/src/main/resources/apex/sfdx-project.json.mustache b/modules/openapi-generator/src/main/resources/apex/sfdx-project.json.mustache new file mode 100644 index 000000000000..08ac49c0cea7 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/apex/sfdx-project.json.mustache @@ -0,0 +1,11 @@ +{ + "packageDirectories": [ + { + "path": "force-app", + "default": true + } + ], + "namespace": "", + "sfdcLoginUrl": "https://login.salesforce.com", + "sourceApiVersion": "{{apiVersion}}" +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/apex/sfdx.mustache b/modules/openapi-generator/src/main/resources/apex/sfdx.mustache deleted file mode 100644 index f63e2e36114a..000000000000 --- a/modules/openapi-generator/src/main/resources/apex/sfdx.mustache +++ /dev/null @@ -1,10 +0,0 @@ -{ - "sfdxSource": true, - "version": "1.0.0", - "sourceFolder": "src/", - "folders": [ - "src/classes" - ], - "files": [ - ] -} \ No newline at end of file diff --git a/samples/client/petstore/apex/.openapi-generator/VERSION b/samples/client/petstore/apex/.openapi-generator/VERSION deleted file mode 100644 index 096bf47efe31..000000000000 --- a/samples/client/petstore/apex/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -3.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/apex/.openapi-generator-ignore b/samples/client/petstore/apex/.swagger-codegen-ignore similarity index 78% rename from samples/client/petstore/apex/.openapi-generator-ignore rename to samples/client/petstore/apex/.swagger-codegen-ignore index 7484ee590a38..c5fa491b4c55 100644 --- a/samples/client/petstore/apex/.openapi-generator-ignore +++ b/samples/client/petstore/apex/.swagger-codegen-ignore @@ -1,11 +1,11 @@ -# OpenAPI Generator Ignore -# Generated by openapi-generator https://github.com/openapitools/openapi-generator +# Swagger Codegen Ignore +# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen # Use this file to prevent files from being overwritten by the generator. # The patterns follow closely to .gitignore or .dockerignore. # As an example, the C# client generator defines ApiClient.cs. -# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: #ApiClient.cs # You can match any string of characters against a directory, file or extension with a single asterisk (*): diff --git a/samples/client/petstore/apex/.swagger-codegen/VERSION b/samples/client/petstore/apex/.swagger-codegen/VERSION new file mode 100644 index 000000000000..855ff9501eb8 --- /dev/null +++ b/samples/client/petstore/apex/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.4.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/apex/docs/SwagPetApi.md b/samples/client/petstore/apex/docs/SwagPetApi.md index ad5843ea638e..0911fbd0fa8d 100644 --- a/samples/client/petstore/apex/docs/SwagPetApi.md +++ b/samples/client/petstore/apex/docs/SwagPetApi.md @@ -16,10 +16,12 @@ Method | HTTP request | Description # **addPet** -> addPet(swagPet) +> addPet(body) Add a new pet to the store + + ### Example ```java SwagPetApi api = new SwagPetApi(); @@ -30,7 +32,7 @@ Swagger.OAuth petstore_auth = (Swagger.OAuth) client.getAuthentication('petstore petstore_auth.setAccessToken('YOUR ACCESS TOKEN'); Map params = new Map{ - 'swagPet' => SwagPet.getExample() + 'body' => SwagPet.getExample() }; try { @@ -45,7 +47,7 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **swagPet** | [**SwagPet**](SwagPet.md)| Pet object that needs to be added to the store | + **body** | [**SwagPet**](Pet.md)| Pet object that needs to be added to the store | ### Return type @@ -57,8 +59,8 @@ null (empty response body) ### HTTP request headers - - **Content-Type**: application/json, application/xml - - **Accept**: Not defined + - **Content-Type**: application/json + - **Accept**: application/json # **deletePet** @@ -66,6 +68,8 @@ null (empty response body) Deletes a pet + + ### Example ```java SwagPetApi api = new SwagPetApi(); @@ -105,8 +109,8 @@ null (empty response body) ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: Not defined + - **Content-Type**: application/json + - **Accept**: application/json # **findPetsByStatus** @@ -154,8 +158,8 @@ Name | Type | Description | Notes ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: application/xml, application/json + - **Content-Type**: application/json + - **Accept**: application/json # **findPetsByTags** @@ -175,7 +179,7 @@ Swagger.OAuth petstore_auth = (Swagger.OAuth) client.getAuthentication('petstore petstore_auth.setAccessToken('YOUR ACCESS TOKEN'); Map params = new Map{ - 'tags' => new List{'\'aeiou\''} + 'tags' => new List{'aeiou'} }; try { @@ -203,8 +207,8 @@ Name | Type | Description | Notes ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: application/xml, application/json + - **Content-Type**: application/json + - **Accept**: application/json # **getPetById** @@ -252,15 +256,17 @@ Name | Type | Description | Notes ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: application/xml, application/json + - **Content-Type**: application/json + - **Accept**: application/json # **updatePet** -> updatePet(swagPet) +> updatePet(body) Update an existing pet + + ### Example ```java SwagPetApi api = new SwagPetApi(); @@ -271,7 +277,7 @@ Swagger.OAuth petstore_auth = (Swagger.OAuth) client.getAuthentication('petstore petstore_auth.setAccessToken('YOUR ACCESS TOKEN'); Map params = new Map{ - 'swagPet' => SwagPet.getExample() + 'body' => SwagPet.getExample() }; try { @@ -286,7 +292,7 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **swagPet** | [**SwagPet**](SwagPet.md)| Pet object that needs to be added to the store | + **body** | [**SwagPet**](Pet.md)| Pet object that needs to be added to the store | ### Return type @@ -298,8 +304,8 @@ null (empty response body) ### HTTP request headers - - **Content-Type**: application/json, application/xml - - **Accept**: Not defined + - **Content-Type**: application/json + - **Accept**: application/json # **updatePetWithForm** @@ -307,6 +313,8 @@ null (empty response body) Updates a pet in the store with form data + + ### Example ```java SwagPetApi api = new SwagPetApi(); @@ -349,7 +357,7 @@ null (empty response body) ### HTTP request headers - **Content-Type**: application/x-www-form-urlencoded - - **Accept**: Not defined + - **Accept**: application/json # **uploadFile** @@ -357,6 +365,8 @@ null (empty response body) uploads an image + + ### Example ```java SwagPetApi api = new SwagPetApi(); @@ -399,6 +409,6 @@ Name | Type | Description | Notes ### HTTP request headers - - **Content-Type**: multipart/form-data + - **Content-Type**: application/x-www-form-urlencoded - **Accept**: application/json diff --git a/samples/client/petstore/apex/docs/SwagStoreApi.md b/samples/client/petstore/apex/docs/SwagStoreApi.md index de0b614f3d4e..c0212e0300f5 100644 --- a/samples/client/petstore/apex/docs/SwagStoreApi.md +++ b/samples/client/petstore/apex/docs/SwagStoreApi.md @@ -50,8 +50,8 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: Not defined + - **Content-Type**: application/json + - **Accept**: application/json # **getInventory** @@ -84,7 +84,7 @@ This endpoint does not need any parameter. ### Return type -**Map<String, Integer>** +[**Map<String, Integer>**](Map.md) ### Authorization @@ -92,7 +92,7 @@ This endpoint does not need any parameter. ### HTTP request headers - - **Content-Type**: Not defined + - **Content-Type**: application/json - **Accept**: application/json @@ -136,21 +136,23 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: application/xml, application/json + - **Content-Type**: application/json + - **Accept**: application/json # **placeOrder** -> SwagOrder placeOrder(swagOrder) +> SwagOrder placeOrder(body) Place an order for a pet + + ### Example ```java SwagStoreApi api = new SwagStoreApi(); Map params = new Map{ - 'swagOrder' => SwagOrder.getExample() + 'body' => SwagOrder.getExample() }; try { @@ -166,7 +168,7 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **swagOrder** | [**SwagOrder**](SwagOrder.md)| order placed for purchasing the pet | + **body** | [**SwagOrder**](Order.md)| order placed for purchasing the pet | ### Return type @@ -178,6 +180,6 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: application/xml, application/json + - **Content-Type**: application/json + - **Accept**: application/json diff --git a/samples/client/petstore/apex/docs/SwagUserApi.md b/samples/client/petstore/apex/docs/SwagUserApi.md index 622607d65d2a..aa559ddeac20 100644 --- a/samples/client/petstore/apex/docs/SwagUserApi.md +++ b/samples/client/petstore/apex/docs/SwagUserApi.md @@ -16,7 +16,7 @@ Method | HTTP request | Description # **createUser** -> createUser(swagUser) +> createUser(body) Create user @@ -27,7 +27,7 @@ This can only be done by the logged in user. SwagUserApi api = new SwagUserApi(); Map params = new Map{ - 'swagUser' => SwagUser.getExample() + 'body' => SwagUser.getExample() }; try { @@ -42,7 +42,7 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **swagUser** | [**SwagUser**](SwagUser.md)| Created user object | + **body** | [**SwagUser**](User.md)| Created user object | ### Return type @@ -54,21 +54,23 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: Not defined + - **Content-Type**: application/json + - **Accept**: application/json # **createUsersWithArrayInput** -> createUsersWithArrayInput(swagUser) +> createUsersWithArrayInput(body) Creates list of users with given input array + + ### Example ```java SwagUserApi api = new SwagUserApi(); Map params = new Map{ - 'swagUser' => new List{SwagUser.getExample()} + 'body' => new List{SwagUser.getExample()} }; try { @@ -83,7 +85,7 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **swagUser** | [**List<SwagUser>**](List.md)| List of user object | + **body** | [**List<SwagUser>**](SwagUser.md)| List of user object | ### Return type @@ -95,21 +97,23 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: Not defined + - **Content-Type**: application/json + - **Accept**: application/json # **createUsersWithListInput** -> createUsersWithListInput(swagUser) +> createUsersWithListInput(body) Creates list of users with given input array + + ### Example ```java SwagUserApi api = new SwagUserApi(); Map params = new Map{ - 'swagUser' => new List{SwagUser.getExample()} + 'body' => new List{SwagUser.getExample()} }; try { @@ -124,7 +128,7 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **swagUser** | [**List<SwagUser>**](List.md)| List of user object | + **body** | [**List<SwagUser>**](SwagUser.md)| List of user object | ### Return type @@ -136,8 +140,8 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: Not defined + - **Content-Type**: application/json + - **Accept**: application/json # **deleteUser** @@ -179,8 +183,8 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: Not defined + - **Content-Type**: application/json + - **Accept**: application/json # **getUserByName** @@ -188,6 +192,8 @@ No authorization required Get user by user name + + ### Example ```java SwagUserApi api = new SwagUserApi(); @@ -209,7 +215,7 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **username** | **String**| The name that needs to be fetched. Use user1 for testing. | + **username** | **String**| The name that needs to be fetched. Use user1 for testing. | ### Return type @@ -221,8 +227,8 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: application/xml, application/json + - **Content-Type**: application/json + - **Accept**: application/json # **loginUser** @@ -230,6 +236,8 @@ No authorization required Logs user into the system + + ### Example ```java SwagUserApi api = new SwagUserApi(); @@ -265,8 +273,8 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: application/xml, application/json + - **Content-Type**: application/json + - **Accept**: application/json # **logoutUser** @@ -274,6 +282,8 @@ No authorization required Logs out current logged in user session + + ### Example ```java SwagUserApi api = new SwagUserApi(); @@ -299,12 +309,12 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: Not defined + - **Content-Type**: application/json + - **Accept**: application/json # **updateUser** -> updateUser(username, swagUser) +> updateUser(username, body) Updated user @@ -316,7 +326,7 @@ SwagUserApi api = new SwagUserApi(); Map params = new Map{ 'username' => 'username_example', - 'swagUser' => SwagUser.getExample() + 'body' => SwagUser.getExample() }; try { @@ -332,7 +342,7 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **username** | **String**| name that need to be deleted | - **swagUser** | [**SwagUser**](SwagUser.md)| Updated user object | + **body** | [**SwagUser**](User.md)| Updated user object | ### Return type @@ -344,6 +354,6 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: Not defined + - **Content-Type**: application/json + - **Accept**: application/json diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagApiResponse.cls b/samples/client/petstore/apex/force-app/main/default/classes/SwagApiResponse.cls index c5d38079650b..6536ed4e583d 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagApiResponse.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagApiResponse.cls @@ -1,12 +1,12 @@ /* - * OpenAPI Petstore - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * + * Contact: apiteam@swagger.io * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ @@ -42,14 +42,14 @@ public class SwagApiResponse implements Swagger.MappedProperties { public static SwagApiResponse getExample() { SwagApiResponse apiResponse = new SwagApiResponse(); - apiResponse.code = ; - apiResponse.r_type = 'aeiou'; - apiResponse.message = 'aeiou'; + apiResponse.code = 0; + apiResponse.r_type = ''; + apiResponse.message = ''; return apiResponse; } public Boolean equals(Object obj) { - if (obj instanceof SwagApiResponse) { + if (obj instanceof SwagApiResponse) { SwagApiResponse apiResponse = (SwagApiResponse) obj; return this.code == apiResponse.code && this.r_type == apiResponse.r_type diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagApiResponse.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwagApiResponse.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagApiResponse.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagApiResponse.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagCategory.cls b/samples/client/petstore/apex/force-app/main/default/classes/SwagCategory.cls index 985aa5b1ecdd..8aaa896d463e 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagCategory.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagCategory.cls @@ -1,12 +1,12 @@ /* - * OpenAPI Petstore - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * + * Contact: apiteam@swagger.io * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ @@ -28,13 +28,13 @@ public class SwagCategory { public static SwagCategory getExample() { SwagCategory category = new SwagCategory(); - category.id = 123456789L; - category.name = 'aeiou'; + category.id = 123456789L; + category.name = ''; return category; } public Boolean equals(Object obj) { - if (obj instanceof SwagCategory) { + if (obj instanceof SwagCategory) { SwagCategory category = (SwagCategory) obj; return this.id == category.id && this.name == category.name; diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagCategory.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwagCategory.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagCategory.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagCategory.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagClient.cls b/samples/client/petstore/apex/force-app/main/default/classes/SwagClient.cls index ee404c543fe3..e229bc325bff 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagClient.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagClient.cls @@ -1,7 +1,7 @@ public class SwagClient extends Swagger.ApiClient { public SwagClient() { basePath = 'http://petstore.swagger.io/v2'; - calloutName = 'OpenAPI_Petstore'; + calloutName = 'Swagger_Petstore'; authentications.put('api_key', new Swagger.ApiKeyHeaderAuth('api_key')); } } diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagClient.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwagClient.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagClient.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagClient.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagOrder.cls b/samples/client/petstore/apex/force-app/main/default/classes/SwagOrder.cls index 0937a675e9bd..b9fa02a759ad 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagOrder.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagOrder.cls @@ -1,12 +1,12 @@ /* - * OpenAPI Petstore - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * + * Contact: apiteam@swagger.io * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ @@ -65,17 +65,17 @@ public class SwagOrder { public static SwagOrder getExample() { SwagOrder order = new SwagOrder(); - order.id = 123456789L; - order.petId = 123456789L; - order.quantity = ; - order.shipDate = Datetime.newInstanceGmt(2000, 1, 23, 4, 56, 7); - order.status = StatusEnum.PLACED; - order.complete = true; + order.id = 123456789L; + order.petId = 123456789L; + order.quantity = 0; + order.shipDate = Datetime.newInstanceGmt(2000, 1, 23, 4, 56, 7); + order.status = StatusEnum.PLACED; + order.complete = true; return order; } public Boolean equals(Object obj) { - if (obj instanceof SwagOrder) { + if (obj instanceof SwagOrder) { SwagOrder order = (SwagOrder) obj; return this.id == order.id && this.petId == order.petId diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagOrder.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwagOrder.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagOrder.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagOrder.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagPet.cls b/samples/client/petstore/apex/force-app/main/default/classes/SwagPet.cls index b04b5a621b15..30ba9df4ea14 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagPet.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagPet.cls @@ -1,12 +1,12 @@ /* - * OpenAPI Petstore - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * + * Contact: apiteam@swagger.io * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ @@ -66,17 +66,17 @@ public class SwagPet { public static SwagPet getExample() { SwagPet pet = new SwagPet(); - pet.id = 123456789L; - pet.category = SwagCategory.getExample(); - pet.name = 'doggie'; - pet.photoUrls = new List{'aeiou'}; - pet.tags = new List{SwagTag.getExample()}; - pet.status = StatusEnum.AVAILABLE; + pet.id = 123456789L; + pet.category = ''; + pet.name = 'doggie'; + pet.photoUrls = new List{''}; + pet.tags = new List{''}; + pet.status = StatusEnum.AVAILABLE; return pet; } public Boolean equals(Object obj) { - if (obj instanceof SwagPet) { + if (obj instanceof SwagPet) { SwagPet pet = (SwagPet) obj; return this.id == pet.id && this.category == pet.category diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagPet.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwagPet.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagPet.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagPet.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagPetApi.cls b/samples/client/petstore/apex/force-app/main/default/classes/SwagPetApi.cls index 747fd271122a..059b7bdcd78e 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagPetApi.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagPetApi.cls @@ -1,12 +1,12 @@ /* - * OpenAPI Petstore - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * + * Contact: apiteam@swagger.io * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ @@ -28,22 +28,22 @@ public class SwagPetApi { /** * Add a new pet to the store * - * @param swagPet Pet object that needs to be added to the store (required) + * @param body Pet object that needs to be added to the store (required) * @throws Swagger.ApiException if fails to make API call */ public void addPet(Map params) { - client.assertNotNull(params.get('swagPet'), 'swagPet'); + client.assertNotNull(params.get('body'), 'body'); List query = new List(); List form = new List(); client.invoke( 'POST', '/pet', - (SwagPet) params.get('swagPet'), + (SwagPet) params.get('body'), query, form, new Map(), new Map(), - new List(), - new List{ 'application/json', 'application/xml' }, + new List{ 'application/json' }, + new List{ 'application/json' }, new List { 'petstore_auth' }, null ); @@ -69,8 +69,8 @@ public class SwagPetApi { new Map{ 'api_key' => (String) params.get('apiKey') }, - new List(), - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List { 'petstore_auth' }, null ); @@ -96,8 +96,8 @@ public class SwagPetApi { query, form, new Map(), new Map(), - new List{ 'application/xml', 'application/json' }, - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List { 'petstore_auth' }, List.class ); @@ -123,8 +123,8 @@ public class SwagPetApi { query, form, new Map(), new Map(), - new List{ 'application/xml', 'application/json' }, - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List { 'petstore_auth' }, List.class ); @@ -148,8 +148,8 @@ public class SwagPetApi { 'petId' => (Long) params.get('petId') }, new Map(), - new List{ 'application/xml', 'application/json' }, - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List { 'api_key' }, SwagPet.class ); @@ -157,22 +157,22 @@ public class SwagPetApi { /** * Update an existing pet * - * @param swagPet Pet object that needs to be added to the store (required) + * @param body Pet object that needs to be added to the store (required) * @throws Swagger.ApiException if fails to make API call */ public void updatePet(Map params) { - client.assertNotNull(params.get('swagPet'), 'swagPet'); + client.assertNotNull(params.get('body'), 'body'); List query = new List(); List form = new List(); client.invoke( 'PUT', '/pet', - (SwagPet) params.get('swagPet'), + (SwagPet) params.get('body'), query, form, new Map(), new Map(), - new List(), - new List{ 'application/json', 'application/xml' }, + new List{ 'application/json' }, + new List{ 'application/json' }, new List { 'petstore_auth' }, null ); @@ -201,7 +201,7 @@ public class SwagPetApi { 'petId' => (Long) params.get('petId') }, new Map(), - new List(), + new List{ 'application/json' }, new List{ 'application/x-www-form-urlencoded' }, new List { 'petstore_auth' }, null @@ -233,7 +233,7 @@ public class SwagPetApi { }, new Map(), new List{ 'application/json' }, - new List{ 'multipart/form-data' }, + new List{ 'application/x-www-form-urlencoded' }, new List { 'petstore_auth' }, SwagApiResponse.class ); diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagPetApi.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwagPetApi.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagPetApi.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagPetApi.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagStoreApi.cls b/samples/client/petstore/apex/force-app/main/default/classes/SwagStoreApi.cls index a9f948232f21..feb55354464d 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagStoreApi.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagStoreApi.cls @@ -1,12 +1,12 @@ /* - * OpenAPI Petstore - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * + * Contact: apiteam@swagger.io * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ @@ -43,8 +43,8 @@ public class SwagStoreApi { 'orderId' => (String) params.get('orderId') }, new Map(), - new List(), - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List(), null ); @@ -65,7 +65,7 @@ public class SwagStoreApi { new Map(), new Map(), new List{ 'application/json' }, - new List(), + new List{ 'application/json' }, new List { 'api_key' }, Map.class ); @@ -89,8 +89,8 @@ public class SwagStoreApi { 'orderId' => (Long) params.get('orderId') }, new Map(), - new List{ 'application/xml', 'application/json' }, - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List(), SwagOrder.class ); @@ -98,23 +98,23 @@ public class SwagStoreApi { /** * Place an order for a pet * - * @param swagOrder order placed for purchasing the pet (required) + * @param body order placed for purchasing the pet (required) * @return SwagOrder * @throws Swagger.ApiException if fails to make API call */ public SwagOrder placeOrder(Map params) { - client.assertNotNull(params.get('swagOrder'), 'swagOrder'); + client.assertNotNull(params.get('body'), 'body'); List query = new List(); List form = new List(); return (SwagOrder) client.invoke( 'POST', '/store/order', - (SwagOrder) params.get('swagOrder'), + (SwagOrder) params.get('body'), query, form, new Map(), new Map(), - new List{ 'application/xml', 'application/json' }, - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List(), SwagOrder.class ); diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagStoreApi.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwagStoreApi.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagStoreApi.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagStoreApi.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagTag.cls b/samples/client/petstore/apex/force-app/main/default/classes/SwagTag.cls index 8f90699f7738..4a758c92f334 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagTag.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagTag.cls @@ -1,12 +1,12 @@ /* - * OpenAPI Petstore - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * + * Contact: apiteam@swagger.io * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ @@ -28,13 +28,13 @@ public class SwagTag { public static SwagTag getExample() { SwagTag tag = new SwagTag(); - tag.id = 123456789L; - tag.name = 'aeiou'; + tag.id = 123456789L; + tag.name = ''; return tag; } public Boolean equals(Object obj) { - if (obj instanceof SwagTag) { + if (obj instanceof SwagTag) { SwagTag tag = (SwagTag) obj; return this.id == tag.id && this.name == tag.name; diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagTag.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwagTag.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagTag.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagTag.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagUser.cls b/samples/client/petstore/apex/force-app/main/default/classes/SwagUser.cls index 63e4c8423eb9..77fe98ad342a 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagUser.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagUser.cls @@ -1,12 +1,12 @@ /* - * OpenAPI Petstore - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * + * Contact: apiteam@swagger.io * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ @@ -64,19 +64,19 @@ public class SwagUser { public static SwagUser getExample() { SwagUser user = new SwagUser(); - user.id = 123456789L; - user.username = 'aeiou'; - user.firstName = 'aeiou'; - user.lastName = 'aeiou'; - user.email = 'aeiou'; - user.password = 'aeiou'; - user.phone = 'aeiou'; - user.userStatus = ; + user.id = 123456789L; + user.username = ''; + user.firstName = ''; + user.lastName = ''; + user.email = ''; + user.password = ''; + user.phone = ''; + user.userStatus = 0; return user; } public Boolean equals(Object obj) { - if (obj instanceof SwagUser) { + if (obj instanceof SwagUser) { SwagUser user = (SwagUser) obj; return this.id == user.id && this.username == user.username diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagUser.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwagUser.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagUser.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagUser.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagUserApi.cls b/samples/client/petstore/apex/force-app/main/default/classes/SwagUserApi.cls index ae296e8d3ba6..a0a30657b42c 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagUserApi.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagUserApi.cls @@ -1,12 +1,12 @@ /* - * OpenAPI Petstore - * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 - * + * Contact: apiteam@swagger.io * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ @@ -28,22 +28,22 @@ public class SwagUserApi { /** * Create user * This can only be done by the logged in user. - * @param swagUser Created user object (required) + * @param body Created user object (required) * @throws Swagger.ApiException if fails to make API call */ public void createUser(Map params) { - client.assertNotNull(params.get('swagUser'), 'swagUser'); + client.assertNotNull(params.get('body'), 'body'); List query = new List(); List form = new List(); client.invoke( 'POST', '/user', - (SwagUser) params.get('swagUser'), + (SwagUser) params.get('body'), query, form, new Map(), new Map(), - new List(), - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List(), null ); @@ -51,22 +51,22 @@ public class SwagUserApi { /** * Creates list of users with given input array * - * @param swagUser List of user object (required) + * @param body List of user object (required) * @throws Swagger.ApiException if fails to make API call */ public void createUsersWithArrayInput(Map params) { - client.assertNotNull(params.get('swagUser'), 'swagUser'); + client.assertNotNull(params.get('body'), 'body'); List query = new List(); List form = new List(); client.invoke( 'POST', '/user/createWithArray', - (List) params.get('swagUser'), + (List) params.get('body'), query, form, new Map(), new Map(), - new List(), - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List(), null ); @@ -74,22 +74,22 @@ public class SwagUserApi { /** * Creates list of users with given input array * - * @param swagUser List of user object (required) + * @param body List of user object (required) * @throws Swagger.ApiException if fails to make API call */ public void createUsersWithListInput(Map params) { - client.assertNotNull(params.get('swagUser'), 'swagUser'); + client.assertNotNull(params.get('body'), 'body'); List query = new List(); List form = new List(); client.invoke( 'POST', '/user/createWithList', - (List) params.get('swagUser'), + (List) params.get('body'), query, form, new Map(), new Map(), - new List(), - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List(), null ); @@ -112,8 +112,8 @@ public class SwagUserApi { 'username' => (String) params.get('username') }, new Map(), - new List(), - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List(), null ); @@ -137,8 +137,8 @@ public class SwagUserApi { 'username' => (String) params.get('username') }, new Map(), - new List{ 'application/xml', 'application/json' }, - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List(), SwagUser.class ); @@ -167,8 +167,8 @@ public class SwagUserApi { query, form, new Map(), new Map(), - new List{ 'application/xml', 'application/json' }, - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List(), String.class ); @@ -187,8 +187,8 @@ public class SwagUserApi { query, form, new Map(), new Map(), - new List(), - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List(), null ); @@ -197,25 +197,25 @@ public class SwagUserApi { * Updated user * This can only be done by the logged in user. * @param username name that need to be deleted (required) - * @param swagUser Updated user object (required) + * @param body Updated user object (required) * @throws Swagger.ApiException if fails to make API call */ public void updateUser(Map params) { client.assertNotNull(params.get('username'), 'username'); - client.assertNotNull(params.get('swagUser'), 'swagUser'); + client.assertNotNull(params.get('body'), 'body'); List query = new List(); List form = new List(); client.invoke( 'PUT', '/user/{username}', - (SwagUser) params.get('swagUser'), + (SwagUser) params.get('body'), query, form, new Map{ 'username' => (String) params.get('username') }, new Map(), - new List(), - new List(), + new List{ 'application/json' }, + new List{ 'application/json' }, new List(), null ); diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwagUserApi.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwagUserApi.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwagUserApi.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwagUserApi.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/Swagger.cls b/samples/client/petstore/apex/force-app/main/default/classes/Swagger.cls index 172c3038111c..bb4e44f79717 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/Swagger.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/Swagger.cls @@ -271,9 +271,7 @@ public class Swagger { @TestVisible protected virtual void applyAuthentication(List names, Map headers, List query) { - for (Authentication auth : getAuthMethods(names)) { - auth.apply(headers, query); - } + // TODO Check auth methods } @TestVisible @@ -298,7 +296,7 @@ public class Swagger { protected virtual String toEndpoint(String path, Map params, List queryParams) { String query = '?' + paramsToString(queryParams); - return '"callout:' + calloutName + toPath(path, params) + query.removeEnd('?') + '""'; + return 'callout:' + calloutName + toPath(path, params) + query.removeEnd('?'); } @TestVisible diff --git a/samples/client/petstore/apex/force-app/main/default/classes/Swagger.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/Swagger.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/Swagger.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/Swagger.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwaggerResponseMock.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwaggerResponseMock.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwaggerResponseMock.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwaggerResponseMock.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwaggerTest.cls b/samples/client/petstore/apex/force-app/main/default/classes/SwaggerTest.cls index e3cec8831c69..d95e9b60aa8e 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwaggerTest.cls +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwaggerTest.cls @@ -292,7 +292,7 @@ private class SwaggerTest { new Swagger.Param('foo', 'bar'), new Swagger.Param('bat', '123') }; - String expected = 'https://www.mccombs.utexas.edu/departments/finance?foo=bar&bat=123'; + String expected = 'callout:Winkelmeyer/departments/finance?foo=bar&bat=123'; String actual = client.toEndpoint(path, params, queryParams); System.assertEquals(expected, actual); } @@ -360,7 +360,8 @@ private class SwaggerTest { private class MockApiClient extends Swagger.ApiClient { public MockApiClient() { - basePath = 'https://www.mccombs.utexas.edu'; + basePath = 'https://blog.winkelmeyer.com'; + calloutName = 'Winkelmeyer'; } } } \ No newline at end of file diff --git a/samples/client/petstore/apex/force-app/main/default/classes/SwaggerTest.cls-meta.xml b/samples/client/petstore/apex/force-app/main/default/classes/SwaggerTest.cls-meta.xml index 8b061c82b6f7..fec71a26693f 100644 --- a/samples/client/petstore/apex/force-app/main/default/classes/SwaggerTest.cls-meta.xml +++ b/samples/client/petstore/apex/force-app/main/default/classes/SwaggerTest.cls-meta.xml @@ -1,5 +1,5 @@ - 39.0 + 42.0 Active diff --git a/samples/client/petstore/apex/force-app/main/default/namedCredentials/OpenAPI_Petstore.namedCredential b/samples/client/petstore/apex/force-app/main/default/namedCredentials/Swagger_Petstore.namedCredential-meta.xml similarity index 88% rename from samples/client/petstore/apex/force-app/main/default/namedCredentials/OpenAPI_Petstore.namedCredential rename to samples/client/petstore/apex/force-app/main/default/namedCredentials/Swagger_Petstore.namedCredential-meta.xml index bd29c9d5239c..e7d8d71ac1c7 100644 --- a/samples/client/petstore/apex/force-app/main/default/namedCredentials/OpenAPI_Petstore.namedCredential +++ b/samples/client/petstore/apex/force-app/main/default/namedCredentials/Swagger_Petstore.namedCredential-meta.xml @@ -3,5 +3,5 @@ http://petstore.swagger.io/v2 Anonymous NoAuthentication - + \ No newline at end of file diff --git a/samples/client/petstore/apex/sfdx-project.json b/samples/client/petstore/apex/sfdx-project.json new file mode 100644 index 000000000000..e0fe2f7ab165 --- /dev/null +++ b/samples/client/petstore/apex/sfdx-project.json @@ -0,0 +1,11 @@ +{ + "packageDirectories": [ + { + "path": "force-app", + "default": true + } + ], + "namespace": "", + "sfdcLoginUrl": "https://login.salesforce.com", + "sourceApiVersion": "42.0" +} \ No newline at end of file