Conversation
…mustache test file.
…utablejs # Conflicts: # modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java # modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java # modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java # modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java # modules/openapi-generator/src/main/resources/typescript-fetch/models.index.mustache # modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptFetchClientOptionsProvider.java # modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientOptionsTest.java
JFCote
left a comment
There was a problem hiding this comment.
Lot of things to remove and/or move
| * Alternative version of the language-specific data type when generator needs a different output in some templates. | ||
| * For example this is used by typescript fetch generator to output either Array (javascript) or List (immutablejs) | ||
| */ | ||
| public String dataTypeAlternate; |
There was a problem hiding this comment.
You should not do this. This is a common thing to do in most of the existing template. You need to deal with this in the TypescriptFetchCodegen.java. You can you typeMapping or even postProcessing. But don't create yet another property
There was a problem hiding this comment.
From what I understand, the only way to have another property accessible in the mustache file for models is to add it here? If there was another way, this would be great, we would not have to "polute" global codegen here...
Btw, this would not be needed if we made a new generator specifically for outputing sagas&records. But here we need to continue to output the normal typescript fetch in addition to the new stuff so we need a second and different dataType here for the new stuff. This would also not be needed if mustache fully supported if/else but it does not. So we need to do the if/else in code and prepare this variable so it can be used in records and saga mustache files.
| /** | ||
| * The property represents a unique id (x-isUniqueId: true); field populated only by typescript fetch for now. | ||
| */ | ||
| public boolean isUniqueId; |
There was a problem hiding this comment.
is there a common way to name properties that are on the vendor side so people are not tempted to use them in their template by error?
There was a problem hiding this comment.
I looked and did not find a pattern for this. Naming seams to be different depending on who added a variable. But we could at least use one for our code and remain consistant.
| // the undeclared properties. | ||
| public CodegenProperty items; | ||
|
|
||
| public String itemsDataType; // if isContainer == true, this is the dataType of the items else it is null. Used by typescript fetch only for now. |
There was a problem hiding this comment.
Don't use these 3 tags since they have duplicated information.
itemsDataType: This is already in the item, you don't need this.
itemsAreModels: You can do "if" in your template based on the isUniqueId
itemsAreEntities: You can do "if" in your template based on the item type. This is very common in most template.
There was a problem hiding this comment.
again, this was added because I did not find any way to get this information once in the mustache file. I needed to expose it here.
| } else { | ||
| enumDefaultValue = var.defaultValue; | ||
| } | ||
| final String enumDefaultValue = var.defaultValue; |
| } | ||
| } | ||
|
|
||
| @Override |
There was a problem hiding this comment.
same question here, why did you remove this?
| recType: "{{classname}}Record" as "{{classname}}Record", | ||
| {{#vars}} | ||
| {{#isArray}} | ||
| {{#itemsAreModels}} |
There was a problem hiding this comment.
This is directly related to what I have said above, you don't need these 3 new properties.
The logic is:
- All items are models unless they are native type
- You can know that a model is an "entity" if isUnique is true.
There was a problem hiding this comment.
Will check if {{^nativeType}} is the same as itemsAreModels ...
| public normalize(apiObject: {{classname}}, asEntity?: boolean): {{classname}} { | ||
| (apiObject as any).recType = {{#isEntity}}asEntity ? "{{classname}}RecordEntity" : {{/isEntity}}"{{classname}}Record"; | ||
| {{#vars}} | ||
| {{#isUniqueId}} |
There was a problem hiding this comment.
you are already doing it the right way here
| {{#isMetaDataResponse}} | ||
| {{#vars.1}} | ||
|
|
||
| public fromApi_data(apiObject: {{classname}}): {{{dataTypeAlternate}}} { |
There was a problem hiding this comment.
like I said above, all this thing with the dataTypeAlternate must be handled in the codegen code
| export const knownIndexedSetByKey = []; | ||
|
|
||
| export function appFromJS(any: any): any { | ||
| return originalFromJS(any, (key, value) => { |
There was a problem hiding this comment.
please review all your file and make sure you use a "4 space tabs" instead of "real tabs". this is the standard in this project
| isRestful, isDeprecated, isCallbackRequest, uniqueItems; | ||
| public String path, operationId, returnType, returnFormat, httpMethod, returnBaseType, | ||
| returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse; | ||
| isRestful, isDeprecated, isCallbackRequest, uniqueItems, returnTypeIsMetaDataResponse, returnTypeIsMetaOnlyResponse, returnTypeSupportsEntities, returnTypeIsModel, returnTypeIsArray; |
There was a problem hiding this comment.
it kind of weird to have a concept of entity in a very generic object called CodegenOperation. I think this should be handled in the specific codegen in the java code. I don't think any of these variable should be here.
There was a problem hiding this comment.
Maybe follow the pattern here?
class ExtendedCodegenOperation extends CodegenOperation {
…Model used exclusively by TypescriptFetchClient. Adding missing samples files.
…egenOperation used exclusively by TypescriptFetchClient.
…genProperty used exclusively by TypescriptFetchClient.
…egenParameter used exclusively by TypescriptFetchClient.
…l concept of "operation return passthrough"
…dependencies in models and other special cases. Also fixed issues with default values for some records properties.
…s in some cases. Fix issues with enum default values.
…s in some cases. Fix issues with enum default values.
… that cannot be used in Records. Added missing export to record: toApi().
…uilt-in "reserved words" feature. Fix minor issues with typings in generated files.
…licts. Added generated ApiEntities (record, reducer & selector) files.
- renamed fake test apis to better fit the "pet theme" - added mode for "SourceOnlyLibrary" (same as used in codegen typescript jquery)
…lysis time for consuming project. Removed tab characters in mustache files. Reformat code for TypeScriptFetchClientCodegen to try to remove false positive for tabs vs spaces.
…pt version to address some typing errors on library build.
… ensure proper typechecking info is generated.
…t to convert an entity to an inlined model recursively.
…3&4 (OpenAPITools#6916) * Added supporting kotlin.serialization for jvm * Added Serializable annotations for java types(date,time,url,uri etc.) * Added SafeEnumSerializer * Added StringBuilderAdapter for kotlin.serialization Fix adapter naming Fix Retrofit ApiClient.kt for kotlin.serialization * Added StringBuilderAdapter for kotlin.serialization * Switch sample to retrofit2-kotlin-serialization * Add sample for retrofit2-kotlin.serialization * update sample * update sample * update sample #3 * Fix enum quotes for kotlin.serialization * update samples * update pom.xml * add pom.xml to child module * fix kotlin-multiplatform freeCompilerArgs * refactoring, add useSafeEnum option, remove safeEnum for kotlin.multiplatform * update kotlin samples * fix import kotlinx.serialization.Required * Update kotlinx.serialization 1.0.0-rc-2, kotlin 1.4.10, retrofit-kotlinx-converter 0.7.0 * Update gradle wrapper 6.7-rc-3 * fix SafeEnum import * fix Json initialization, fix SafeEnumSerializer * update samples * update kotlinx.serialization to 1.0.0 * Update gradle to 6.7 in kotlin samples * fixed adding @contextual for collections with non-primitive type elements * remove unused SafeEnum imports, refactored * update kotlin readme * update kotlin project template Readme.md * update samples for kotlin * simplify template for class properties * remove @contextual from kotlin-multiplatform * update kotlin multiplatform dependencies * refactoring templates * revert all changes for multiplatform * fix tests * revert multiplatform #2 * update samples after merge, fix missed isListContainer->isArray * fixed redundant space before @contextual * Fixed enum template, Class were missed in generated samples * fix enum template toString value->serialName * fixed isEnum case for collections * update samples * removed useSafeEnum option, kotlinx serialization has out of box approach with coerceInputValues option for same behavior * generate samples * update kotlinx.serialization 1.0.1 * update samples * Added pom.mustache template for kotlin-client samples with fixed execution of gradle wrapper instead standalone installed gradle on CI * update samples with new pom.xml * reverted enum value property name * fixed kotlin-multiplatform pom.xml * update kotlin-threetenbp sample * update kotlin-string sample * update kotlin-string sample * fix adding kotlinx.serialization classpath to build.gradle * generate samples * add supporting kotlinx_serialization kotlinx.serialization.Serializable with java.io.Serializable at the same time * update retrofit2-kotlinx-serialization-converter:0.8.0 * update kotlinx_serialization sample with retrofit2-kotlinx-serialization-converter:0.8.0 * apply suggest from @blendthink * added proguard-rules.pro file for kotlinx.serialization on Android projects * fix pom.mustache * update gradle wrapper to 6.8.3 * update kotlin samples * fix kotlin readme template, update kotlin samples * update kotlin samples * update kotlin sample delete petstore/kotlin unit tests * revert deletion kotlin client tests remove adding pom.xml to kotlin client samples * add support kotlinx serialization for okhttp3/4 * update kotlin client samples
…utablejs # Conflicts: # modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java
This reverts commit ea9b4ae
…OpenAPITools#11315) * Fixing empty Content-Type in HTTP requests * Updating samples
…ppy warnings (OpenAPITools#12479) * feat(rust): support various Rust integer types (#2) * fix: Use ROOT locale * fix: unsigned int bounds were incorrect * fix: deal with potential null value
PR checklist
./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.master