forked from loafle/openapi-generator-original
Merge branch 'master' of https://github.com/openapitools/openapi-generator
This commit is contained in:
commit
73605a0c0e
@ -25,7 +25,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Mustache.Compiler;
|
||||
import com.samskivert.mustache.Mustache.Lambda;
|
||||
|
||||
import io.swagger.v3.core.util.Json;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
@ -57,16 +56,11 @@ import org.openapitools.codegen.meta.Stability;
|
||||
import org.openapitools.codegen.meta.features.*;
|
||||
import org.openapitools.codegen.serializer.SerializerUtils;
|
||||
import org.openapitools.codegen.templating.MustacheEngineAdapter;
|
||||
import org.openapitools.codegen.templating.mustache.CamelCaseLambda;
|
||||
import org.openapitools.codegen.templating.mustache.IndentedLambda;
|
||||
import org.openapitools.codegen.templating.mustache.LowercaseLambda;
|
||||
import org.openapitools.codegen.templating.mustache.TitlecaseLambda;
|
||||
import org.openapitools.codegen.templating.mustache.UppercaseLambda;
|
||||
import org.openapitools.codegen.templating.mustache.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.openapitools.codegen.utils.OneOfImplementorAdditionalData;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import static org.openapitools.codegen.utils.OnceLogger.once;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@ -78,6 +72,7 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.openapitools.codegen.utils.OnceLogger.once;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public class DefaultCodegen implements CodegenConfig {
|
||||
@ -1122,7 +1117,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
this.allowUnicodeIdentifiers = allowUnicodeIdentifiers;
|
||||
}
|
||||
|
||||
public Boolean getUseOneOfInterfaces() { return useOneOfInterfaces; }
|
||||
public Boolean getUseOneOfInterfaces() {
|
||||
return useOneOfInterfaces;
|
||||
}
|
||||
|
||||
public void setUseOneOfInterfaces(Boolean useOneOfInterfaces) {
|
||||
this.useOneOfInterfaces = useOneOfInterfaces;
|
||||
@ -1884,7 +1881,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
/**
|
||||
* Return the OAI type (e.g. integer, long, etc) corresponding to a schema.
|
||||
* <pre>$ref</pre> is not taken into account by this method.
|
||||
*
|
||||
* <p>
|
||||
* If the schema is free-form (i.e. 'type: object' with no properties) or inline
|
||||
* schema, the returned OAI type is 'object'.
|
||||
*
|
||||
@ -3303,16 +3300,28 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
if ("default".equals(responseCode)) {
|
||||
if ("default".equals(responseCode) || "defaultResponse".equals(responseCode)) {
|
||||
r.code = "0";
|
||||
} else {
|
||||
r.code = responseCode;
|
||||
switch (r.code.charAt(0)) {
|
||||
case '1': r.is1xx = true; break;
|
||||
case '2': r.is2xx = true; break;
|
||||
case '3': r.is3xx = true; break;
|
||||
case '4': r.is4xx = true; break;
|
||||
case '5': r.is5xx = true; break;
|
||||
case '1':
|
||||
r.is1xx = true;
|
||||
break;
|
||||
case '2':
|
||||
r.is2xx = true;
|
||||
break;
|
||||
case '3':
|
||||
r.is3xx = true;
|
||||
break;
|
||||
case '4':
|
||||
r.is4xx = true;
|
||||
break;
|
||||
case '5':
|
||||
r.is5xx = true;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Invalid response code " + responseCode);
|
||||
}
|
||||
}
|
||||
Schema responseSchema;
|
||||
@ -5756,8 +5765,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
//// Following methods are related to the "useOneOfInterfaces" feature
|
||||
|
||||
/**
|
||||
* Add "x-oneOf-name" extension to a given oneOf schema (assuming it has at least 1 oneOf elements)
|
||||
*
|
||||
* @param s schema to add the extension to
|
||||
* @param name name of the parent oneOf schema
|
||||
*/
|
||||
@ -5769,6 +5780,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
/**
|
||||
* Add a given ComposedSchema as an interface model to be generated, assuming it has `oneOf` defined
|
||||
*
|
||||
* @param cs ComposedSchema object to create as interface model
|
||||
* @param type name to use for the generated interface model
|
||||
*/
|
||||
@ -5801,7 +5813,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
addOneOfInterfaces.add(cm);
|
||||
}
|
||||
|
||||
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {}
|
||||
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {
|
||||
}
|
||||
//// End of methods related to the "useOneOfInterfaces" feature
|
||||
|
||||
protected void modifyFeatureSet(Consumer<FeatureSet.Builder> processor) {
|
||||
|
@ -18,11 +18,9 @@
|
||||
package org.openapitools.codegen.javascript;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenProperty;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.languages.JavascriptClientCodegen;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
@ -98,4 +96,21 @@ public class JavascriptClientCodegenTest {
|
||||
Assert.assertFalse(property2.isContainer);
|
||||
}
|
||||
|
||||
@Test(description = "test isDefualt in the response")
|
||||
public void testResponseIsDefault() throws Exception {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/petstore.yaml");
|
||||
final DefaultCodegen codegen = new DefaultCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
Operation textOperation = openAPI.getPaths().get("/user").getPost();
|
||||
CodegenOperation coText = codegen.fromOperation("/user", "post", textOperation, null);
|
||||
|
||||
for (CodegenResponse cr : coText.responses) {
|
||||
Assert.assertTrue(cr.isDefault);
|
||||
}
|
||||
|
||||
Assert.assertEquals(coText.responses.size(), 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user