Skip to content

Commit

Permalink
[ENG-1257] Regenerate SnapTrade SDKs (#260)
Browse files Browse the repository at this point in the history
* fix generated C# tests + TS SDK README

* docs(changeset): strip format: uuid for C# SDK
  • Loading branch information
dphuang2 authored Oct 7, 2023
1 parent 158a8c0 commit 93d5dcf
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 9 deletions.
5 changes: 5 additions & 0 deletions generator/konfig-dash/.changeset/famous-kiwis-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'konfig-lib': minor
---

strip format: uuid for C# SDK
26 changes: 26 additions & 0 deletions generator/konfig-dash/packages/konfig-lib/src/transformSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ client.SetAccessToken("YOUR_ACCESS_TOKEN");
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
{{/apiDocumentationAuthenticationPartial}}
{{/apiDocumentationAuthenticationPartial}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#allowableValues}}{{#enumVars}}{{#-first}}{{name}}{{/-first}}{{/enumVars}}{{^enumVars}}{{#values}}{{#-first}}{{.}}{{/-first}}{{/values}}{{/enumVars}}{{/allowableValues}}
Original file line number Diff line number Diff line change
@@ -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}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{{#vars}}
{{#isEnumRef}}
var {{nameInCamelCaseLowerFirst}} = {{{datatypeWithEnum}}}.{{> api_doc_example_enum_param}};{{#description}} // {{{.}}}{{/description}}
{{/isEnumRef}}
{{^isEnumRef}}
{{#isPrimitiveType}}
{{#example}}
{{#isEnum}}
Expand All @@ -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}}
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
{{#readmeHeader}}
<div align="center">

# {{{title}}}

[![Visit {{{title}}}](./header.png)]({{{url}}})

# [{{{title}}}]({{{url}}})
{{^omitInfoDescription}}

{{{appDescription}}}
{{/omitInfoDescription}}

{{> readme_badges}}

</div>
{{/readmeHeader}}
{{^readmeHeader}}
# {{npmName}}

{{> readme_badges}}
{{/readmeHeader}}

{{^omitInfoDescription}}{{{appDescription}}}
{{/omitInfoDescription}}

{{> readme_badges}}
{{/readmeHeader}}

## Table of Contents

<!-- toc -->
Expand Down

0 comments on commit 93d5dcf

Please sign in to comment.