diff --git a/generator/konfig-dash/.changeset/famous-kiwis-fly.md b/generator/konfig-dash/.changeset/famous-kiwis-fly.md new file mode 100644 index 000000000..084ef966c --- /dev/null +++ b/generator/konfig-dash/.changeset/famous-kiwis-fly.md @@ -0,0 +1,5 @@ +--- +'konfig-lib': minor +--- + +strip format: uuid for C# SDK diff --git a/generator/konfig-dash/packages/konfig-lib/src/transformSpec.ts b/generator/konfig-dash/packages/konfig-lib/src/transformSpec.ts index b010fee0c..a5930331e 100644 --- a/generator/konfig-dash/packages/konfig-lib/src/transformSpec.ts +++ b/generator/konfig-dash/packages/konfig-lib/src/transformSpec.ts @@ -542,6 +542,32 @@ export const transformSpec = async ({ } } + if (generator === 'csharp') { + // remove uuid format from any "string" type schemas + // Why? Well SnapTrade has the following schema: + /* + - in: query + required: false + name: brokerage_authorizations + description: + Optional. Comma seperated list of authorization IDs (only use if + filtering is needed on one or more authorizations). + schema: + type: string + format: uuid + example: 917c8734-8470-4a3e-a18f-57c3f2ee6631 + */ + // But then I realized the whole use of the "Guid" class in C# is actually a bit annoying when all other languages + // will accept a string type for a UUID. So I decided to remove the format from all string types in C#. + recurseObject(spec.spec, ({ value: schema }) => { + if (schema === null) return + if (typeof schema !== 'object') return + if (schema['type'] !== 'string') return + if (schema['format'] !== 'uuid') return + delete schema['format'] + }) + } + if (generator === 'java') { const successfulVendorExtension = 'x-konfig-is-used-in-successful-response' const nonSuccessfulVendorExtension = diff --git a/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/CodegenProperty.java b/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/CodegenProperty.java index 23b8c8467..87b2f3235 100644 --- a/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/CodegenProperty.java +++ b/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/CodegenProperty.java @@ -155,6 +155,7 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti public boolean isArray; public boolean isMap; public boolean isEnum; + public boolean isEnumRef; public boolean isInnerEnum; // Enums declared inline will be located inside the generic model, changing how the enum is referenced in some cases. public boolean isReadOnly; public boolean isWriteOnly; diff --git a/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 5a6c5e7ca..800a95faf 100644 --- a/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -4012,8 +4012,12 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, if (allowableValues.size() > 0) { property.allowableValues = allowableValues; } + if (p != referencedSchema) + property.isEnumRef = true; } + + if (referencedSchema.getNullable() != null) { property.isNullable = referencedSchema.getNullable(); } @@ -4085,7 +4089,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, } else if (ModelUtils.isAnyType(p)) { updatePropertyForAnyType(property, p); } else if (ModelUtils.isTypeObjectSchema(pDeref)) { - updatePropertyForObject(property, pDeref); + updatePropertyForObject(property, p); } else if (!ModelUtils.isNullType(p)) { // referenced model ; @@ -4110,7 +4114,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, String type = getSchemaType(p); setNonArrayMapProperty(property, type); property.isModel = (ModelUtils.isComposedSchema(referencedSchema) - || ModelUtils.isObjectSchema(referencedSchema)) && ModelUtils.isModel(referencedSchema); + || ModelUtils.isModel(referencedSchema)); } if (property.complexType != null) { diff --git a/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java b/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java index 27ebb6fa7..c0e56d753 100644 --- a/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java +++ b/generator/konfig-generator-api/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java @@ -126,6 +126,8 @@ public AbstractCSharpCodegen() { // NOTE: C# uses camel cased reserved words, while models are title cased. We don't want lowercase comparisons. reservedWords.addAll( Arrays.asList( + // "System." namespace + "Action", // set "client" as a reserved word to avoid conflicts with Org.OpenAPITools.Client // this is a workaround and can be removed if c# api client is updated to use // fully qualified name diff --git a/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_auth_partial.mustache b/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_auth_partial.mustache index 877a22dfc..db1a86864 100644 --- a/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_auth_partial.mustache +++ b/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_auth_partial.mustache @@ -36,4 +36,4 @@ client.SetAccessToken("YOUR_ACCESS_TOKEN"); {{/isOAuth}} {{/authMethods}} {{/hasAuthMethods}} -{{/apiDocumentationAuthenticationPartial}} +{{/apiDocumentationAuthenticationPartial}} \ No newline at end of file diff --git a/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_example_enum_param.mustache b/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_example_enum_param.mustache new file mode 100644 index 000000000..7c026bda2 --- /dev/null +++ b/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_example_enum_param.mustache @@ -0,0 +1 @@ +{{#allowableValues}}{{#enumVars}}{{#-first}}{{name}}{{/-first}}{{/enumVars}}{{^enumVars}}{{#values}}{{#-first}}{{.}}{{/-first}}{{/values}}{{/enumVars}}{{/allowableValues}} \ No newline at end of file diff --git a/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_example_execute.mustache b/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_example_execute.mustache index 8f58b8ef0..c8fa7e283 100644 --- a/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_example_execute.mustache +++ b/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_example_execute.mustache @@ -1,6 +1,6 @@ {{#allParams}} {{#isPrimitiveType}} -var {{paramName}} = {{{example}}}; // {{{description}}}{{^required}} (optional) {{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} +var {{paramName}} = {{{example}}};{{#description}} // {{{description}}}{{^required}} (optional) {{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/description}} {{/isPrimitiveType}} {{^isPrimitiveType}} {{#isBodyParam}} diff --git a/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_example_execute_setup_body_param.mustache b/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_example_execute_setup_body_param.mustache index 2c01b5ce1..8fa954a4f 100644 --- a/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_example_execute_setup_body_param.mustache +++ b/generator/konfig-generator-api/src/main/resources/csharp-netcore/api_doc_example_execute_setup_body_param.mustache @@ -1,4 +1,8 @@ {{#vars}} +{{#isEnumRef}} +var {{nameInCamelCaseLowerFirst}} = {{{datatypeWithEnum}}}.{{> api_doc_example_enum_param}};{{#description}} // {{{.}}}{{/description}} +{{/isEnumRef}} +{{^isEnumRef}} {{#isPrimitiveType}} {{#example}} {{#isEnum}} @@ -9,9 +13,26 @@ var {{nameInCamelCaseLowerFirst}} = {{{example}}};{{#description}} // {{{.}}}{{/ {{/isEnum}} {{/example}} {{^example}} +{{#isNumber}} +var {{nameInCamelCaseLowerFirst}} = default({{{dataType}}});{{#description}} // {{{.}}}{{/description}} +{{/isNumber}} {{#isString}} +{{^isEnum}} var {{nameInCamelCaseLowerFirst}} = "{{{nameInCamelCaseLowerFirst}}}_example";{{#description}} // {{{.}}}{{/description}} +{{/isEnum}} +{{#isEnum}} +var {{nameInCamelCaseLowerFirst}} = {{{../dataType}}}.{{{enumName}}}.{{> api_doc_example_enum_param}};{{#description}} // {{{.}}}{{/description}} +{{/isEnum}} {{/isString}} +{{#isAnyType}} +var {{nameInCamelCaseLowerFirst}} = "{{{nameInCamelCaseLowerFirst}}}_example";{{#description}} // {{{.}}}{{/description}} +{{/isAnyType}} {{/example}} {{/isPrimitiveType}} +{{^isPrimitiveType}} +{{#isArray}} +var {{nameInCamelCaseLowerFirst}} = new {{{dataType}}}();{{#description}} // {{{.}}}{{/description}} +{{/isArray}} +{{/isPrimitiveType}} +{{/isEnumRef}} {{/vars}} \ No newline at end of file diff --git a/generator/konfig-generator-api/src/main/resources/typescript-axios/README.mustache b/generator/konfig-generator-api/src/main/resources/typescript-axios/README.mustache index 83c6ea7fd..8ee1cad4a 100644 --- a/generator/konfig-generator-api/src/main/resources/typescript-axios/README.mustache +++ b/generator/konfig-generator-api/src/main/resources/typescript-axios/README.mustache @@ -1,10 +1,14 @@ {{#readmeHeader}}