Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typescript Fetch] New optional mode with redux saga & immutablejs (saga & records) #8578

Merged
merged 47 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ac55b6c
first commit: add cli option for saga and records. Added dummy sagas.…
bflamand-work Sep 29, 2020
61a3033
More progress with default values. First prototype for isEntity and i…
bflamand-work Oct 1, 2020
2e3a04e
record generation complete
bflamand-work Oct 5, 2020
9411143
record generation complete
bflamand-work Oct 5, 2020
6e867ee
progress with saga generation
bflamand-work Oct 9, 2020
3da2805
progress with saga generation
bflamand-work Nov 25, 2020
7b42777
Merge pull request #1 from OpenAPITools/master
bflamand Nov 30, 2020
9a3160c
first fully working saga generation
bflamand-work Nov 30, 2020
84c702c
Merge remote-tracking branch 'origin/master' into typescript-saga-imm…
bflamand-work Nov 30, 2020
5554245
merge with latest master
bflamand-work Nov 30, 2020
f8030fb
removed unneeded "items" properties.
bflamand-work Nov 30, 2020
8f33935
moved global CodegenModel modifications into subclass ExtendedCodegen…
bflamand-work Dec 2, 2020
f387d06
moved global CodegenOperation modifications into subclass ExtendedCod…
bflamand-work Dec 2, 2020
c586da2
moved global CodegenProperty modifications into subclass ExtendedCode…
bflamand-work Dec 2, 2020
b273409
moved global CodegenParameter modifications into subclass ExtendedCod…
bflamand-work Dec 2, 2020
9b48cf2
added the missing "allSagas" export.
bflamand-work Dec 3, 2020
1796282
renamed & reworked "meta data response" flags to a more useful genera…
bflamand-work Dec 4, 2020
a82ff31
added vendor flag keepAsJSObject as escape hatch to support circular …
bflamand-work Dec 4, 2020
549797d
added autodetection for passthrough to simplify standardised specs.
bflamand-work Dec 7, 2020
1706006
fix small issue with passthrough void
bflamand-work Dec 7, 2020
32c97a4
fix small issues with passthrough void and missing passthrough import…
bflamand-work Dec 8, 2020
e6c5ef3
fix small issues with passthrough void and missing passthrough import…
bflamand-work Dec 10, 2020
ea5a5eb
Merge pull request #3 from OpenAPITools/master
bflamand Dec 10, 2020
e86c81f
Merge remote-tracking branch 'origin/master' into typescript-saga-imm…
bflamand-work Dec 10, 2020
9160502
Added "reservedRecordField" feature to support remapping fields names…
bflamand-work Dec 10, 2020
a77f17e
added uniqueId inference. Fix small generation when uniqueId property…
bflamand-work Dec 11, 2020
8925de1
removed feature "reservedRecordField" and replaced it with existing b…
bflamand-work Dec 11, 2020
090150b
Changed api recType names to make them less likely to cause name conf…
bflamand-work Dec 16, 2020
76eef30
Moved location of ApiEntities related files and fix issues with exports.
bflamand-work Dec 17, 2020
47e06dd
Merge pull request #4 from OpenAPITools/master
bflamand Jan 27, 2021
8e2b99c
merge master
bflamand-work Jan 27, 2021
0e2b574
- merge latest master
bflamand-work Jan 29, 2021
1c67357
- missing ganarate sampless
bflamand-work Jan 29, 2021
1fb2e4f
Merge pull request #5 from OpenAPITools/master
bflamand Feb 8, 2021
639d687
Merge remote-tracking branch 'origin/master' into typescript-saga-imm…
bflamand-work Feb 8, 2021
6ab1fba
- Modified way to export apiEntitiesSelectpr to reduce typescript ana…
bflamand-work Feb 8, 2021
bff46e0
- added markErrorsAsHandled property to api sagas. Increased typescri…
bflamand-work Mar 11, 2021
e72f84f
- fix bug in saga interfaces. Upgraded to typescript "strict" mode to…
bflamand-work Mar 11, 2021
b13159b
- added optional id for apiEntity selectors. Added toInlined() suppor…
bflamand-work Mar 12, 2021
33cf0d4
- minor tweak for apiEntitySelector to accept null id
bflamand-work Mar 12, 2021
0389c3a
- minor tweak for apiEntitySelector
bflamand-work Apr 19, 2021
b2bfad9
Merge pull request #6 from OpenAPITools/master
bflamand Apr 20, 2021
d87cff8
Merge remote-tracking branch 'origin/master' into typescript-saga-imm…
bflamand-work Apr 20, 2021
ea9b4ae
- runned ensure up to date.
bflamand-work Apr 20, 2021
ace4139
Revert "- runned ensure up to date."
bflamand-work Apr 20, 2021
bf12bb2
- runned ensure up to date.
bflamand-work Apr 20, 2021
ec78ed9
- runned ensure up to date.
bflamand-work Apr 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bin/configs/typescript-fetch-sagas-and-records.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
generatorName: typescript-fetch
outputDir: samples/client/petstore/typescript-fetch/builds/sagas-and-records
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing-saga-and-records.yaml
Copy link
Member

Choose a reason for hiding this comment

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

Can we use OpenAPI 3.0 spec instead as we're doing the same for other samples from openapi 2.0 to 3.0 spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this can wait, I would prefer to take a look at this at a later time. I am not sure of the implications of changing this. It is probably very easy, but I am not sure. Would prefer to proceeed with a first merge and upgrade in a next phase. See my additional comments below regarding the futur plan for this upgrade.

additionalProperties:
npmVersion: 1.0.0
npmName: '@openapitools/typescript-fetch-petstore'
npmRepository: https://skimdb.npmjs.com/registry
useSingleRequestParameter: false
supportsES6: true
typescriptThreePlus: true
sagasAndRecords: true
detectPassthroughModelsWithSuffixAndField: 'Response.data'
inferUniqueIdFromNameSuffix: true
inferEntityFromUniqueIdWithName: id
packageAsSourceOnlyLibrary: false
snapshot: false
1 change: 1 addition & 0 deletions docs/generators/typescript-fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|nullSafeAdditionalProps|Set to make additional properties types declare that their indexer may return undefined| |false|
|prefixParameterInterfaces|Setting this property to true will generate parameter interface declarations prefixed with API class name to avoid name conflicts.| |false|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|sagasAndRecords|Setting this property to true will generate additional files for use with redux-saga and immutablejs.| |false|
|snapshot|When setting this property to true, the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm| |false|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5457,13 +5457,9 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {

// handle default value for enum, e.g. available => StatusEnum.AVAILABLE
if (var.defaultValue != null) {
final String enumDefaultValue = getEnumDefaultValue(var.defaultValue, dataType);

String enumName = null;
final String enumDefaultValue;
if (isDataTypeString(dataType)) {
enumDefaultValue = toEnumValue(var.defaultValue, dataType);
} else {
enumDefaultValue = var.defaultValue;
}
for (Map<String, Object> enumVar : enumVars) {
if (enumDefaultValue.equals(enumVar.get("value"))) {
enumName = (String) enumVar.get("name");
Expand All @@ -5476,6 +5472,16 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
}
}

protected String getEnumDefaultValue(String defaultValue, String dataType) {
final String enumDefaultValue;
if (isDataTypeString(dataType)) {
enumDefaultValue = toEnumValue(defaultValue, dataType);
} else {
enumDefaultValue = defaultValue;
}
return enumDefaultValue;
}

protected List<Map<String, Object>> buildEnumVars(List<Object> values, String dataType) {
List<Map<String, Object>> enumVars = new ArrayList<>();
int truncateIdx = 0;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Map, Record, RecordOf} from 'immutable';

import {
{{#models}}
{{#model}}
{{#isEntity}}
{{classname}}RecordEntity,
{{/isEntity}}
{{/model}}
{{/models}}
} from "./models"

export const ApiEntitiesRecordProps = {
recType: "ApiEntitiesRecord" as "ApiEntitiesRecord",
{{#models}}
{{#model}}
{{#isEntity}}
{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}: ({{classname}}RecordEntity(), Map<string, {{classname}}RecordEntity>()),
{{/isEntity}}
{{/model}}
{{/models}}
};

export type ApiEntitiesRecordPropsType = typeof ApiEntitiesRecordProps;
export const ApiEntitiesRecord = Record(ApiEntitiesRecordProps, ApiEntitiesRecordProps.recType);
export type ApiEntitiesRecord = RecordOf<ApiEntitiesRecordPropsType>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {ApiEntitiesRecord} from "./ApiEntitiesRecord";
import {ReducerBuilder} from "redux-ts-simple";
import {normalizedEntities} from "./runtimeSagasAndRecords";

export const ApiEntitiesReducer = new ReducerBuilder(ApiEntitiesRecord())
.on(normalizedEntities, (state, action): ApiEntitiesRecord => {
const {entities} = action.payload;
return state.withMutations(mutableState => {
for (const entityKey in entities) {
const entityMap = entities[entityKey];
const currentEntityMap = mutableState.get(entityKey as any);
if (currentEntityMap) {
let mergedEntityMap = currentEntityMap.mergeDeep(entityMap);
if (!mergedEntityMap.equals(currentEntityMap)) {
mutableState.set(entityKey as any, mergedEntityMap);
}
}
}
});
})
.build();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export let getApiEntitiesState: (state: any) => any = (state: any) => state.app.apiEntities;

export function setApiEntitiesStateGetter(getter: (state: any) => any) { // Use this to customize the location where you have placed your ApiEntitiesRecord in your project.
getApiEntitiesState = getter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {all, fork} from "redux-saga/effects";

import {
{{#apiInfo}}
{{#apis}}
{{#lambda.camelcase}}{{classFilename}}{{/lambda.camelcase}}AllSagas,
{{/apis}}
{{/apiInfo}}
} from "./";

export function *allApiSagas() {
yield all([
{{#apiInfo}}
{{#apis}}
fork({{#lambda.camelcase}}{{classFilename}}{{/lambda.camelcase}}AllSagas),
{{/apis}}
{{/apiInfo}}
]);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{{#useSagaAndRecords}}
export * from './SagaApiManager'
export * from './allSagas'
{{/useSagaAndRecords}}
{{#apiInfo}}
{{#apis}}
{{#operations}}
export * from './{{ classFilename }}';
{{#useSagaAndRecords}}
export * from './{{{ classFilename }}}Sagas';
{{/useSagaAndRecords}}
{{/operations}}
{{/apis}}
{{/apiInfo}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export * from './runtime';
{{#useSagaAndRecords}}
export * from './runtimeSagasAndRecords';
export * from './ApiEntitiesRecord';
export * from './ApiEntitiesReducer';
export * from './ApiEntitiesSelectors';
{{/useSagaAndRecords}}
{{#apiInfo}}
{{#apis.0}}
export * from './apis';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
{{#model}}
{{^withoutRuntimeChecks}}
export * from './{{{ classFilename }}}';
{{/withoutRuntimeChecks}}{{#withoutRuntimeChecks}}
{{#useSagaAndRecords}}
{{^isEnum}}
export * from './{{{ classFilename }}}Record';
{{/isEnum}}
{{/useSagaAndRecords}}
{{/withoutRuntimeChecks}}
{{#withoutRuntimeChecks}}
{{#isEnum}}
{{>modelEnumInterfaces}}
{{/isEnum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@
"version": "{{npmVersion}}",
"description": "OpenAPI client for {{npmName}}",
"author": "OpenAPI-Generator",
{{#packageAsSourceOnlyLibrary}}
"main": "./index.ts",
{{/packageAsSourceOnlyLibrary}}
{{^packageAsSourceOnlyLibrary}}
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"build": "tsc"{{^sagasAndRecords}},
"prepare": "npm run build"
{{/sagasAndRecords}}
},
{{/packageAsSourceOnlyLibrary}}
"devDependencies": {
"typescript": "^{{#typescriptThreePlus}}3.6{{/typescriptThreePlus}}{{^typescriptThreePlus}}2.4{{/typescriptThreePlus}}"
{{#sagasAndRecords}}
"immutable": "^4.0.0-rc.12",
"normalizr": "^3.6.1",
"redux-saga": "^1.1.3",
"redux-ts-simple": "^3.2.0",
"reselect": "^4.0.0",
{{/sagasAndRecords}}
"typescript": "^{{#typescriptThreePlus}}3.9.5{{/typescriptThreePlus}}{{^typescriptThreePlus}}2.4{{/typescriptThreePlus}}"
}{{#npmRepository}},{{/npmRepository}}
{{#npmRepository}}
"publishConfig": {
Expand Down
Loading