Skip to content

Typescript saga immutablejs#2

Closed
bflamand wants to merge 42 commits intomasterfrom
typescript-saga-immutablejs
Closed

Typescript saga immutablejs#2
bflamand wants to merge 42 commits intomasterfrom
typescript-saga-immutablejs

Conversation

@bflamand
Copy link
Copy Markdown
Owner

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./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.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

…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
@bflamand bflamand self-assigned this Nov 30, 2020
Copy link
Copy Markdown
Collaborator

@JFCote JFCote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Owner Author

@bflamand bflamand Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a bug!

}
}

@Override
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here, why did you remove this?

recType: "{{classname}}Record" as "{{classname}}Record",
{{#vars}}
{{#isArray}}
{{#itemsAreModels}}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are already doing it the right way here

{{#isMetaDataResponse}}
{{#vars.1}}

public fromApi_data(apiObject: {{classname}}): {{{dataTypeAlternate}}} {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh...

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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
…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.
bflamand pushed a commit that referenced this pull request Apr 20, 2021
…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
@bflamand bflamand closed this Sep 17, 2021
bflamand pushed a commit that referenced this pull request Jan 31, 2022
…OpenAPITools#11315)

* Fixing empty Content-Type in HTTP requests

* Updating samples
bflamand pushed a commit that referenced this pull request Oct 12, 2022
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants