Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nhomble committed May 12, 2020
2 parents b98d925 + c1d47a5 commit 8660e38
Show file tree
Hide file tree
Showing 830 changed files with 32,859 additions and 8,586 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyTitleAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
19e887ae0fddb9fd03c4341951ee9077703a652f
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyTitleAttribute("Org.OpenAPITools.Test")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
19e887ae0fddb9fd03c4341951ee9077703a652f
Binary file not shown.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
- [Vouchery.io](https://vouchery.io)
- [Xero](https://www.xero.com/)
- [Yahoo Japan](https://www.yahoo.co.jp/)
- [Vonage](https://vonage.com)
- [YITU Technology](https://www.yitutech.com/)
- [Yelp](https://www.yelp.com/)
- [Zalando](https://www.zalando.com)
Expand Down
2 changes: 1 addition & 1 deletion bin/aspnetcore-petstore-server-3.0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -g aspnetcore -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -t modules/openapi-generator/src/main/resources/aspnetcore/2.1/ -o samples/server/petstore/aspnetcore-3.0 --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5} --additional-properties aspnetCoreVersion=3.0 $@"
ags="generate -g aspnetcore -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -t modules/openapi-generator/src/main/resources/aspnetcore/3.0/ -o samples/server/petstore/aspnetcore-3.0 --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5} --additional-properties aspnetCoreVersion=3.0 $@"

java $JAVA_OPTS -jar $executable $ags
2 changes: 1 addition & 1 deletion bin/aspnetcore-petstore-server-3.1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -g aspnetcore -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -t modules/openapi-generator/src/main/resources/aspnetcore/2.1/ -o samples/server/petstore/aspnetcore-3.1 --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5} --additional-properties aspnetCoreVersion=3.1 $@"
ags="generate -g aspnetcore -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -t modules/openapi-generator/src/main/resources/aspnetcore/3.0/ -o samples/server/petstore/aspnetcore-3.1 --additional-properties packageGuid={3C799344-F285-4669-8FD5-7ED9B795D5C5} --additional-properties aspnetCoreVersion=3.1 $@"

java $JAVA_OPTS -jar $executable $ags
1 change: 1 addition & 0 deletions docs/generators/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sidebar_label: rust
|library|library template (sub-template) to use.|<dl><dt>**hyper**</dt><dd>HTTP client: Hyper.</dd><dt>**reqwest**</dt><dd>HTTP client: Reqwest.</dd></dl>|hyper|
|packageName|Rust package name (convention: lowercase).| |openapi|
|packageVersion|Rust package version.| |1.0.0|
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |false|

## IMPORT MAPPING

Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ OPTIONS
--http-user-agent <http user agent>
HTTP user agent, e.g. codegen_csharp_api_client, default to
'OpenAPI-Generator/{packageVersion}}/{language}'
'OpenAPI-Generator/{packageVersion}/{language}'
-i <spec file>, --input-spec <spec file>
location of the OpenAPI spec, as URL or file (required)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public String getReleaseNote() {
/**
* Gets the http user agent to be used by client generators which support setting this value.
* <p>
* e.g. codegen_csharp_api_client, defaults to 'OpenAPI-Generator/{packageVersion}}/{language}'
* e.g. codegen_csharp_api_client, defaults to 'OpenAPI-Generator/{packageVersion}/{language}'
*
* @return the http user agent
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-gradle-plugin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ apply plugin: 'org.openapi.generator'
|httpUserAgent
|String
|None
|HTTP user agent, e.g. codegen_csharp_api_client. Generator default is 'OpenAPI-Generator/{packageVersion}}/{language}', but may be generator-specific.
|HTTP user agent, e.g. codegen_csharp_api_client. Generator default is 'OpenAPI-Generator/{packageVersion}/{language}', but may be generator-specific.

|reservedWordsMappings
|Map(String,String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
val releaseNote = project.objects.property<String?>()

/**
* HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}}/{language}'
* HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}/{language}'
*/
val httpUserAgent = project.objects.property<String?>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ open class GenerateTask : DefaultTask() {
val releaseNote = project.objects.property<String?>()

/**
* HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}}/{language}'
* HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}/{language}'
*/
@get:Internal
val httpUserAgent = project.objects.property<String?>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
public static final String RELEASE_NOTE_DESC = "Release note, default to 'Minor update'.";

public static final String HTTP_USER_AGENT = "httpUserAgent";
public static final String HTTP_USER_AGENT_DESC = "HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}}/{language}'";
public static final String HTTP_USER_AGENT_DESC = "HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}/{language}'";

public static final String SUPPORTS_ES6 = "supportsES6";
public static final String SUPPORTS_ES6_DESC = "Generate code that conforms to ES6.";
Expand Down Expand Up @@ -356,4 +356,7 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
public static final String LEGACY_DISCRIMINATOR_BEHAVIOR_DESC = "This flag is used by OpenAPITools codegen to influence the processing of the discriminator attribute in OpenAPI documents. This flag has no impact if the OAS document does not use the discriminator attribute. The default value of this flag is set in each language-specific code generator (e.g. Python, Java, go...)using the method toModelName. " +
"Note to developers supporting a language generator in OpenAPITools; to fully support the discriminator attribute as defined in the OAS specification 3.x, language generators should set this flag to true by default; however this requires updating the mustache templates to generate a language-specific discriminator lookup function that iterates over {{#mappedModels}} and does not iterate over {{children}}, {{#anyOf}}, or {{#oneOf}}.";

public static final String USE_SINGLE_REQUEST_PARAMETER = "useSingleRequestParameter";
public static final String USE_SINGLE_REQUEST_PARAMETER_DESC = "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.";

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import java.util.*;

/**
* CodegenModel represents a schema object in a OpenAPI document.
*/
@JsonIgnoreProperties({"parentModel", "interfaceModels"})
public class CodegenModel implements IJsonSchemaValidationProperties {
// The parent model name from the schemas. The parent is determined by inspecting the allOf, anyOf and
Expand Down Expand Up @@ -220,6 +223,45 @@ public void setDescription(String description) {
this.description = description;
}

/**
* Returns the discriminator for this schema object, or null if no discriminator has been specified.
*
* The list of all possible schema discriminator mapping values is obtained
* from explicit discriminator mapping values in the OpenAPI document, and from
* inherited discriminators through oneOf, allOf, anyOf.
* For example, a discriminator may be defined in a 'Pet' schema as shown below.
* The Dog and Cat schemas inherit the discriminator through the allOf reference.
* In the 'Pet' schema, the supported discriminator mapping values for the
* 'objectType' properties are 'Dog' and 'Cat'.
* The allowed discriminator mapping value for the Dog schema is 'Dog'.
* The allowed discriminator mapping value for the Cat schema is 'Dog'.
*
* Pet:
* type: object
* discriminator:
* propertyName: objectType
* required:
* - objectType
* properties:
* objectType:
* type: string
* Dog:
* allOf:
* - $ref: '#/components/schemas/Pet'
* - type: object
* properties:
* p1:
* type: string
* Cat:
* allOf:
* - $ref: '#/components/schemas/Pet'
* - type: object
* properties:
* p2:
* type: string
*
* @return the discriminator.
*/
public CodegenDiscriminator getDiscriminator() {
return discriminator;
}
Expand All @@ -228,6 +270,14 @@ public void setDiscriminator(CodegenDiscriminator discriminator) {
this.discriminator = discriminator;
}

/**
* Returns the name of the discriminator property for this schema in the OpenAPI document.
* In the OpenAPI document, the discriminator may be specified in the local schema or
* it may be inherited, such as through a 'allOf' schema which references another schema
* that has a discriminator, recursively.
*
* @return the name of the discriminator property.
*/
public String getDiscriminatorName() {
return discriminator == null ? null : discriminator.getPropertyName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2553,36 +2553,60 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
if (composedSchema.getOneOf() != null && composedSchema.getOneOf().size() != 0) {
// All oneOf definitions must contain the discriminator
Integer hasDiscriminatorCnt = 0;
Integer hasNullTypeCnt = 0;
Set<String> discriminatorsPropNames = new HashSet<>();
for (Schema oneOf : composedSchema.getOneOf()) {
for (Schema oneOf: composedSchema.getOneOf()) {
if (ModelUtils.isNullType(oneOf)) {
// The null type does not have a discriminator. Skip.
hasNullTypeCnt++;
continue;
}
foundDisc = recursiveGetDiscriminator(oneOf, openAPI);
if (foundDisc != null) {
discriminatorsPropNames.add(foundDisc.getPropertyName());
hasDiscriminatorCnt++;
}
}
if (hasDiscriminatorCnt == composedSchema.getOneOf().size() && discriminatorsPropNames.size() == 1) {
if (discriminatorsPropNames.size() > 1) {
throw new RuntimeException("The oneOf schemas have conflicting discriminator property names. " +
"oneOf schemas must have the same property name, but found " + String.join(", ", discriminatorsPropNames));
}
if ((hasDiscriminatorCnt + hasNullTypeCnt) == composedSchema.getOneOf().size() && discriminatorsPropNames.size() == 1) {
disc.setPropertyName(foundDisc.getPropertyName());
disc.setMapping(foundDisc.getMapping());
return disc;
}
// If the scenario when oneOf has two children and one of them is the 'null' type,
// there is no need for a discriminator.
}
if (composedSchema.getAnyOf() != null && composedSchema.getAnyOf().size() != 0) {
// All anyOf definitions must contain the discriminator because a min of one must be selected
Integer hasDiscriminatorCnt = 0;
Integer hasNullTypeCnt = 0;
Set<String> discriminatorsPropNames = new HashSet<>();
for (Schema anyOf : composedSchema.getAnyOf()) {
for (Schema anyOf: composedSchema.getAnyOf()) {
if (ModelUtils.isNullType(anyOf)) {
// The null type does not have a discriminator. Skip.
hasNullTypeCnt++;
continue;
}
foundDisc = recursiveGetDiscriminator(anyOf, openAPI);
if (foundDisc != null) {
discriminatorsPropNames.add(foundDisc.getPropertyName());
hasDiscriminatorCnt++;
}
}
if (hasDiscriminatorCnt == composedSchema.getAnyOf().size() && discriminatorsPropNames.size() == 1) {
if (discriminatorsPropNames.size() > 1) {
throw new RuntimeException("The anyOf schemas have conflicting discriminator property names. " +
"anyOf schemas must have the same property name, but found " + String.join(", ", discriminatorsPropNames));
}
if ((hasDiscriminatorCnt + hasNullTypeCnt) == composedSchema.getAnyOf().size() && discriminatorsPropNames.size() == 1) {
disc.setPropertyName(foundDisc.getPropertyName());
disc.setMapping(foundDisc.getMapping());
return disc;
}
// If the scenario when anyOf has two children and one of them is the 'null' type,
// there is no need for a discriminator.
}
}
return null;
Expand Down Expand Up @@ -2611,7 +2635,10 @@ protected List<MappedModel> getOneOfAnyOfDescendants(String composedSchemaName,
if (schemaList == null) {
continue;
}
for (Schema sc : schemaList) {
for (Schema sc: schemaList) {
if (ModelUtils.isNullType(sc)) {
continue;
}
String ref = sc.get$ref();
if (ref == null) {
// for schemas with no ref, it is not possible to build the discriminator map
Expand Down Expand Up @@ -3110,9 +3137,15 @@ public CodegenProperty fromProperty(String name, Schema p) {
} else if (ModelUtils.isFreeFormObject(p)) {
property.isFreeFormObject = true;
property.baseType = getSchemaType(p);
if (languageSpecificPrimitives.contains(property.dataType)) {
property.isPrimitiveType = true;
}
} else if (ModelUtils.isAnyTypeSchema(p)) {
property.isAnyType = true;
property.baseType = getSchemaType(p);
if (languageSpecificPrimitives.contains(property.dataType)) {
property.isPrimitiveType = true;
}
} else { // model
setNonArrayMapProperty(property, type);
Schema refOrCurrent = ModelUtils.getReferencedSchema(this.openAPI, p);
Expand Down
Loading

0 comments on commit 8660e38

Please sign in to comment.