Skip to content

Commit

Permalink
Merge branch 'OpenAPITools:master' into replace-deprecated-classes-8561
Browse files Browse the repository at this point in the history
  • Loading branch information
MelleD committed Jul 7, 2023
2 parents 94a71ff + a5f1c01 commit 7877993
Show file tree
Hide file tree
Showing 73 changed files with 697 additions and 273 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/samples-spring-jdk17.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Samples Java Spring (JDK17)

on:
push:
paths:
- samples/openapi3/client/petstore/spring-cloud-3-with-optional
pull_request:
paths:
- samples/openapi3/client/petstore/spring-cloud-3-with-optional
jobs:
build:
name: Build Java Spring (JDK17)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sample:
# clients
- samples/openapi3/client/petstore/spring-cloud-3-with-optional
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- name: Cache maven dependencies
uses: actions/cache@v3
env:
cache-name: maven-repository
with:
path: |
~/.m2
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
- name: Build
working-directory: ${{ matrix.sample }}
run: mvn clean package
3 changes: 1 addition & 2 deletions .github/workflows/samples-spring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- samples/openapi3/client/petstore/spring-stubs-skip-default-interface
- samples/openapi3/client/petstore/spring-cloud-async
- samples/openapi3/client/petstore/spring-cloud-spring-pageable
- samples/openapi3/client/petstore/spring-cloud-3-with-optional.yaml
- samples/client/petstore/spring-cloud-tags
# servers
- samples/server/petstore/springboot
- samples/openapi3/server/petstore/springboot
Expand All @@ -47,7 +47,6 @@ jobs:
- samples/server/petstore/springboot-spring-pageable-delegatePattern
- samples/server/petstore/springboot-spring-pageable-without-j8
- samples/server/petstore/springboot-spring-pageable
- samples/openapi3/client/petstore/spring-cloud-tags.yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import io.github.gradlenexus.publishplugin.ReleaseNexusStagingRepository
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("com.gradle.plugin-publish") version "1.0.0"
id("com.gradle.plugin-publish") version "1.1.0"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("java-gradle-plugin")
id("maven-publish")
Expand Down
7 changes: 6 additions & 1 deletion modules/openapi-generator-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@
<gradleVersion>${gradleVersion}</gradleVersion>
<args>
<arg>-P openApiGeneratorVersion=${project.version}</arg>
<!--
<arg>-Psigning.keyId=${env.SIGNING_KEY}</arg>
<arg>-Psigning.password=${env.SIGNING_PASSPHRASE}</arg>
<arg>-Psigning.secretKeyRingFile=${env.TRAVIS_BUILD_DIR}/sec.gpg</arg>
-->
</args>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<phase>install</phase>
<goals>
<!-- goal must be "invoke" -->
<goal>invoke</goal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ task buildGoSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTas
}

task buildDotnetSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask){
generatorName = "csharp-netcore"
generatorName = "csharp"
inputSpec = "$rootDir/petstore-v3.0.yaml".toString()
additionalProperties = [
packageGuid: "{321C8C3F-0156-40C1-AE42-D59761FB9B6C}",
useCompareNetObjects: "true"
]
outputDir = "$buildDir/csharp-netcore".toString()
outputDir = "$buildDir/csharp".toString()
globalProperties = [
models: "",
apis : "",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
}
}

Set<CodegenParameter> referenceTypes = operation.allParams.stream().filter(p -> p.vendorExtensions.get("x-is-value-type") == null && !p.isNullable).collect(Collectors.toSet());
List<CodegenParameter> referenceTypes = operation.allParams.stream().filter(p -> p.vendorExtensions.get("x-is-value-type") == null && !p.isNullable).collect(Collectors.toList());
operation.vendorExtensions.put("x-not-nullable-reference-types", referenceTypes);
operation.vendorExtensions.put("x-has-not-nullable-reference-types", referenceTypes.size() > 0);
processOperation(operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1586,8 +1586,8 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
}
for (Operation operation : path.readOperations()) {
LOGGER.info("Processing operation {}", operation.getOperationId());
if (hasBodyParameter(openAPI, operation) || hasFormParameter(openAPI, operation)) {
String defaultContentType = hasFormParameter(openAPI, operation) ? "application/x-www-form-urlencoded" : "application/json";
if (hasBodyParameter(operation) || hasFormParameter(operation)) {
String defaultContentType = hasFormParameter(operation) ? "application/x-www-form-urlencoded" : "application/json";
List<String> consumes = new ArrayList<>(getConsumesInfo(openAPI, operation));
String contentType = consumes.isEmpty() ? defaultContentType : consumes.get(0);
operation.addExtension("x-content-type", contentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
FrameworkStrategy.NET_6_0,
FrameworkStrategy.NET_7_0
);
private static FrameworkStrategy latestFramework = frameworkStrategies.get(frameworkStrategies.size() -1);
private static FrameworkStrategy latestFramework = frameworkStrategies.get(frameworkStrategies.size() - 1);
protected final Map<String, String> frameworks;
protected String packageGuid = "{" + java.util.UUID.randomUUID().toString().toUpperCase(Locale.ROOT) + "}";
protected String clientPackage = "Client";
Expand Down Expand Up @@ -344,15 +344,15 @@ public CSharpClientCodegen() {
@Override
protected Set<String> getNullableTypes() {
return GENERICHOST.equals(getLibrary())
? super.getNullableTypes()
: new HashSet<>(Arrays.asList("decimal", "bool", "int", "uint", "long", "ulong", "float", "double", "DateTime", "DateTimeOffset", "Guid"));
? super.getNullableTypes()
: new HashSet<>(Arrays.asList("decimal", "bool", "int", "uint", "long", "ulong", "float", "double", "DateTime", "DateTimeOffset", "Guid"));
}

@Override
protected Set<String> getValueTypes() {
return GENERICHOST.equals(getLibrary())
? super.getValueTypes()
: new HashSet<>(Arrays.asList("decimal", "bool", "int", "uint", "long", "ulong", "float", "double"));
? super.getValueTypes()
: new HashSet<>(Arrays.asList("decimal", "bool", "int", "uint", "long", "ulong", "float", "double"));
}

@Override
Expand Down Expand Up @@ -1589,7 +1589,7 @@ protected void removePropertiesDeclaredInComposedTypes(Map<String, ModelsMap> ob
? null
: model.discriminator.getPropertyName();

for(CodegenProperty oneOfProperty : composedProperties) {
for (CodegenProperty oneOfProperty : composedProperties) {
String ref = oneOfProperty.getRef();
if (ref != null) {
for (Map.Entry<String, ModelsMap> composedEntry : objs.entrySet()) {
Expand Down Expand Up @@ -1624,8 +1624,8 @@ protected void removePropertiesDeclaredInComposedTypes(Map<String, ModelsMap> ob
protected boolean isValueType(CodegenProperty var) {
// this is temporary until x-csharp-value-type is removed
return this.getLibrary().equals("generichost")
? super.isValueType(var)
: this.getValueTypes().contains(var.dataType) || var.isEnum;
? super.isValueType(var)
: this.getValueTypes().contains(var.dataType) || var.isEnum;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ private void adaptToDartInheritance(Map<String, ModelsMap> objs) {
/// to remove extra mappings added as a side effect of setLegacyDiscriminatorBehavior(false)
/// this ensures 1-1 schema mapping instead of 1-many
@Override
protected CodegenDiscriminator createDiscriminator(String schemaName, Schema schema, OpenAPI openAPI) {
CodegenDiscriminator sub = super.createDiscriminator(schemaName, schema, openAPI);
protected CodegenDiscriminator createDiscriminator(String schemaName, Schema schema) {
CodegenDiscriminator sub = super.createDiscriminator(schemaName, schema);
Discriminator originalDiscriminator = schema.getDiscriminator();
if (originalDiscriminator!=null) {
Map<String,String> originalMapping = originalDiscriminator.getMapping();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
}
}

if (hasBodyParameter(openAPI, operation) || hasFormParameter(openAPI, operation)) {
String defaultContentType = hasFormParameter(openAPI, operation) ? "application/x-www-form-urlencoded" : "application/json";
if (hasBodyParameter(operation) || hasFormParameter(operation)) {
String defaultContentType = hasFormParameter(operation) ? "application/x-www-form-urlencoded" : "application/json";
List<String> consumes = new ArrayList<>(getConsumesInfo(openAPI, operation));
String contentTypeValue = consumes.isEmpty() ? defaultContentType : consumes.get(0);
if (contentTypeValue.equals("*/*"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.examples.Example;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.servers.ServerVariable;
import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.GeneratorMetadata;
Expand Down Expand Up @@ -462,6 +463,24 @@ public String escapeUnsafeCharacters(String input) {
return input;
}

/**
* Return the default value of the property
* <p>
* Return null when the default is not defined
*
* @param schema Property schema
* @return string presentation of the default value of the property
*/
@SuppressWarnings("static-method")
@Override
public String toDefaultValue(Schema schema) {
if (schema.getDefault() != null) {
return schema.getDefault().toString();
}

return null;
}

/**
* Escape single and/or double quote to avoid code injection
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o
} else if (ModelUtils.isObjectSchema(schema)) {
fullPrefix += "{";
closeChars = "}";
CodegenDiscriminator disc = createDiscriminator(modelName, schema, openAPI);
CodegenDiscriminator disc = createDiscriminator(modelName, schema);
if (disc != null) {
MappedModel mm = getDiscriminatorMappedModel(disc);
if (mm != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ public static String getParentName(ComposedSchema composedSchema, Map<String, Sc
if (s == null) {
LOGGER.error("Failed to obtain schema from {}", parentName);
return "UNKNOWN_PARENT_NAME";
} else if (hasOrInheritsDiscriminator(s, allSchemas)) {
} else if (hasOrInheritsDiscriminator(s, allSchemas, new ArrayList<Schema>())) {
// discriminator.propertyName is used or x-parent is used
return parentName;
} else {
Expand Down Expand Up @@ -1391,7 +1391,7 @@ public static List<String> getAllParentsName(ComposedSchema composedSchema, Map<
if (s == null) {
LOGGER.error("Failed to obtain schema from {}", parentName);
names.add("UNKNOWN_PARENT_NAME");
} else if (hasOrInheritsDiscriminator(s, allSchemas)) {
} else if (hasOrInheritsDiscriminator(s, allSchemas, new ArrayList<Schema>())) {
// discriminator.propertyName is used or x-parent is used
names.add(parentName);
if (includeAncestors && s instanceof ComposedSchema) {
Expand All @@ -1416,23 +1416,30 @@ public static List<String> getAllParentsName(ComposedSchema composedSchema, Map<
return names;
}

private static boolean hasOrInheritsDiscriminator(Schema schema, Map<String, Schema> allSchemas) {
private static boolean hasOrInheritsDiscriminator(Schema schema, Map<String, Schema> allSchemas, ArrayList<Schema> visitedSchemas) {
for (Schema s : visitedSchemas) {
if (s == schema) {
return false;
}
}
visitedSchemas.add(schema);

if ((schema.getDiscriminator() != null && StringUtils.isNotEmpty(schema.getDiscriminator().getPropertyName()))
|| (isExtensionParent(schema))) { // x-parent is used
return true;
} else if (StringUtils.isNotEmpty(schema.get$ref())) {
String parentName = getSimpleRef(schema.get$ref());
Schema s = allSchemas.get(parentName);
if (s != null) {
return hasOrInheritsDiscriminator(s, allSchemas);
return hasOrInheritsDiscriminator(s, allSchemas, visitedSchemas);
} else {
LOGGER.error("Failed to obtain schema from {}", parentName);
}
} else if (schema instanceof ComposedSchema) {
final ComposedSchema composed = (ComposedSchema) schema;
final List<Schema> interfaces = getInterfaces(composed);
for (Schema i : interfaces) {
if (hasOrInheritsDiscriminator(i, allSchemas)) {
if (hasOrInheritsDiscriminator(i, allSchemas, visitedSchemas)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ namespace {{packageName}}.Client
MaxTimeout = configuration.Timeout,
Proxy = configuration.Proxy,
UserAgent = configuration.UserAgent,
UseDefaultCredentials = configuration.UseDefaultCredentials
UseDefaultCredentials = configuration.UseDefaultCredentials,
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
};
RestClient client = new RestClient(clientOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Net.Http;
using System.Net.Security;
{{#useRestSharp}}
{{#hasOAuthMethods}}using {{packageName}}.Client.Auth;
{{/hasOAuthMethods}}
Expand Down Expand Up @@ -627,6 +628,11 @@ namespace {{packageName}}.Client
set { _HttpSigningConfiguration = value; }
}
{{/hasHttpSignatureMethods}}

/// <summary>
/// Gets and Sets the RemoteCertificateValidationCallback
/// </summary>
public RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; set; }

#endregion Properties

Expand Down Expand Up @@ -714,7 +720,8 @@ namespace {{packageName}}.Client
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
DateTimeFormat = second.DateTimeFormat ?? first.DateTimeFormat,
ClientCertificates = second.ClientCertificates ?? first.ClientCertificates,
UseDefaultCredentials = second.UseDefaultCredentials
UseDefaultCredentials = second.UseDefaultCredentials,
RemoteCertificateValidationCallback = second.RemoteCertificateValidationCallback ?? first.RemoteCertificateValidationCallback,
};
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
{{#useRestSharp}}
{{#hasOAuthMethods}}using {{packageName}}.Client.Auth;
Expand Down Expand Up @@ -161,5 +162,11 @@ namespace {{packageName}}.Client
/// </summary>
HttpSigningConfiguration HttpSigningConfiguration { get; }
{{/hasHttpSignatureMethods}}

/// <summary>
/// Callback function for handling the validation of remote certificates. Useful for certificate pinning and
/// overriding certificate errors in the scope of a request.
/// </summary>
RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;

function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
}
{{#platforms}}
{{#node}}
throw new Error("You need to define an absolute base url for the server.");
{{/node}}
{{^node}}
return window.location.origin + url;
{{/node}}
{{/platforms}}
}

/**
* Represents an HTTP request context
*/
Expand All @@ -83,7 +97,7 @@ export class RequestContext {
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
this.url = new URL(url);
this.url = new URL(ensureAbsoluteUrl(url));
}

/*
Expand All @@ -101,7 +115,7 @@ export class RequestContext {
*
*/
public setUrl(url: string) {
this.url = new URL(url);
this.url = new URL(ensureAbsoluteUrl(url));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ public void testHasBodyParameter() {
openAPI.getComponents().addSchemas("Pet", new ObjectSchema());

final DefaultCodegen codegen = new DefaultCodegen();
codegen.setOpenAPI(openAPI);

Assert.assertFalse(codegen.hasBodyParameter(openAPI, pingOperation));
Assert.assertTrue(codegen.hasBodyParameter(openAPI, createOperation));
Assert.assertFalse(codegen.hasBodyParameter(pingOperation));
Assert.assertTrue(codegen.hasBodyParameter(createOperation));
}

@Test(expectedExceptions = RuntimeException.class)
Expand Down
Loading

0 comments on commit 7877993

Please sign in to comment.