@kattebak/openapi-generator-ts 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +189 -0
- package/dist/cli/commands/generate.d.ts +23 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +116 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/list.d.ts +2 -0
- package/dist/cli/commands/list.d.ts.map +1 -0
- package/dist/cli/commands/list.js +26 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +6 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +80 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/convert-template.d.ts +31 -0
- package/dist/cli/convert-template.d.ts.map +1 -0
- package/dist/cli/convert-template.js +204 -0
- package/dist/cli/convert-template.js.map +1 -0
- package/dist/cli/convert-template.test.d.ts +2 -0
- package/dist/cli/convert-template.test.d.ts.map +1 -0
- package/dist/cli/convert-template.test.js +74 -0
- package/dist/cli/convert-template.test.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +246 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/config.d.ts +252 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +31 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/generator.d.ts +99 -0
- package/dist/core/generator.d.ts.map +1 -0
- package/dist/core/generator.js +492 -0
- package/dist/core/generator.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/types.d.ts +47 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/generators/generators.test.d.ts +6 -0
- package/dist/generators/generators.test.d.ts.map +1 -0
- package/dist/generators/generators.test.js +247 -0
- package/dist/generators/generators.test.js.map +1 -0
- package/dist/generators/go.d.ts +10 -0
- package/dist/generators/go.d.ts.map +1 -0
- package/dist/generators/go.js +327 -0
- package/dist/generators/go.js.map +1 -0
- package/dist/generators/index.d.ts +29 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +58 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/php.d.ts +14 -0
- package/dist/generators/php.d.ts.map +1 -0
- package/dist/generators/php.js +241 -0
- package/dist/generators/php.js.map +1 -0
- package/dist/generators/python.d.ts +10 -0
- package/dist/generators/python.d.ts.map +1 -0
- package/dist/generators/python.js +273 -0
- package/dist/generators/python.js.map +1 -0
- package/dist/generators/typescript-fetch.d.ts +14 -0
- package/dist/generators/typescript-fetch.d.ts.map +1 -0
- package/dist/generators/typescript-fetch.js +217 -0
- package/dist/generators/typescript-fetch.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/models/codegen-model.d.ts +123 -0
- package/dist/models/codegen-model.d.ts.map +1 -0
- package/dist/models/codegen-model.js +64 -0
- package/dist/models/codegen-model.js.map +1 -0
- package/dist/models/codegen-model.test.d.ts +6 -0
- package/dist/models/codegen-model.test.d.ts.map +1 -0
- package/dist/models/codegen-model.test.js +143 -0
- package/dist/models/codegen-model.test.js.map +1 -0
- package/dist/models/codegen-operation.d.ts +95 -0
- package/dist/models/codegen-operation.d.ts.map +1 -0
- package/dist/models/codegen-operation.js +54 -0
- package/dist/models/codegen-operation.js.map +1 -0
- package/dist/models/codegen-parameter.d.ts +86 -0
- package/dist/models/codegen-parameter.d.ts.map +1 -0
- package/dist/models/codegen-parameter.js +47 -0
- package/dist/models/codegen-parameter.js.map +1 -0
- package/dist/models/codegen-property.d.ts +95 -0
- package/dist/models/codegen-property.d.ts.map +1 -0
- package/dist/models/codegen-property.js +47 -0
- package/dist/models/codegen-property.js.map +1 -0
- package/dist/models/codegen-response.d.ts +64 -0
- package/dist/models/codegen-response.d.ts.map +1 -0
- package/dist/models/codegen-response.js +42 -0
- package/dist/models/codegen-response.js.map +1 -0
- package/dist/models/codegen-security.d.ts +34 -0
- package/dist/models/codegen-security.d.ts.map +1 -0
- package/dist/models/codegen-security.js +18 -0
- package/dist/models/codegen-security.js.map +1 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +7 -0
- package/dist/models/index.js.map +1 -0
- package/dist/parser/index.d.ts +4 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +4 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/openapi-parser.d.ts +71 -0
- package/dist/parser/openapi-parser.d.ts.map +1 -0
- package/dist/parser/openapi-parser.js +195 -0
- package/dist/parser/openapi-parser.js.map +1 -0
- package/dist/parser/openapi-parser.test.d.ts +6 -0
- package/dist/parser/openapi-parser.test.d.ts.map +1 -0
- package/dist/parser/openapi-parser.test.js +238 -0
- package/dist/parser/openapi-parser.test.js.map +1 -0
- package/dist/parser/operation-transformer.d.ts +95 -0
- package/dist/parser/operation-transformer.d.ts.map +1 -0
- package/dist/parser/operation-transformer.js +634 -0
- package/dist/parser/operation-transformer.js.map +1 -0
- package/dist/parser/schema-transformer.d.ts +134 -0
- package/dist/parser/schema-transformer.d.ts.map +1 -0
- package/dist/parser/schema-transformer.js +557 -0
- package/dist/parser/schema-transformer.js.map +1 -0
- package/dist/template/engine-adapter.d.ts +55 -0
- package/dist/template/engine-adapter.d.ts.map +1 -0
- package/dist/template/engine-adapter.js +178 -0
- package/dist/template/engine-adapter.js.map +1 -0
- package/dist/template/engine-adapter.test.d.ts +6 -0
- package/dist/template/engine-adapter.test.d.ts.map +1 -0
- package/dist/template/engine-adapter.test.js +186 -0
- package/dist/template/engine-adapter.test.js.map +1 -0
- package/dist/template/index.d.ts +5 -0
- package/dist/template/index.d.ts.map +1 -0
- package/dist/template/index.js +5 -0
- package/dist/template/index.js.map +1 -0
- package/dist/template/lambdas/indent-lambdas.d.ts +40 -0
- package/dist/template/lambdas/indent-lambdas.d.ts.map +1 -0
- package/dist/template/lambdas/indent-lambdas.js +98 -0
- package/dist/template/lambdas/indent-lambdas.js.map +1 -0
- package/dist/template/lambdas/index.d.ts +44 -0
- package/dist/template/lambdas/index.d.ts.map +1 -0
- package/dist/template/lambdas/index.js +79 -0
- package/dist/template/lambdas/index.js.map +1 -0
- package/dist/template/lambdas/string-lambdas.d.ts +78 -0
- package/dist/template/lambdas/string-lambdas.d.ts.map +1 -0
- package/dist/template/lambdas/string-lambdas.js +148 -0
- package/dist/template/lambdas/string-lambdas.js.map +1 -0
- package/dist/template/lambdas/string-lambdas.test.d.ts +6 -0
- package/dist/template/lambdas/string-lambdas.test.d.ts.map +1 -0
- package/dist/template/lambdas/string-lambdas.test.js +158 -0
- package/dist/template/lambdas/string-lambdas.test.js.map +1 -0
- package/dist/template/template-locator.d.ts +72 -0
- package/dist/template/template-locator.d.ts.map +1 -0
- package/dist/template/template-locator.js +173 -0
- package/dist/template/template-locator.js.map +1 -0
- package/dist/template/template-manager.d.ts +65 -0
- package/dist/template/template-manager.d.ts.map +1 -0
- package/dist/template/template-manager.js +185 -0
- package/dist/template/template-manager.js.map +1 -0
- package/package.json +67 -0
- package/templates/go/.travis.yml +8 -0
- package/templates/go/README.mustache +236 -0
- package/templates/go/api.mustache +452 -0
- package/templates/go/api_doc.mustache +92 -0
- package/templates/go/api_test.mustache +59 -0
- package/templates/go/client.mustache +761 -0
- package/templates/go/configuration.mustache +332 -0
- package/templates/go/git_push.sh.mustache +57 -0
- package/templates/go/gitignore.mustache +24 -0
- package/templates/go/go.mod.mustache +16 -0
- package/templates/go/go.sum.mustache +19 -0
- package/templates/go/model.mustache +21 -0
- package/templates/go/model_anyof.mustache +93 -0
- package/templates/go/model_doc.mustache +97 -0
- package/templates/go/model_enum.mustache +101 -0
- package/templates/go/model_oneof.mustache +160 -0
- package/templates/go/model_simple.mustache +572 -0
- package/templates/go/nullable_model.mustache +35 -0
- package/templates/go/openapi.mustache +1 -0
- package/templates/go/partial_header.mustache +18 -0
- package/templates/go/response.mustache +38 -0
- package/templates/go/signing.mustache +453 -0
- package/templates/go/utils.mustache +352 -0
- package/templates/php/.php-cs-fixer.dist.php +29 -0
- package/templates/php/.travis.yml +8 -0
- package/templates/php/ApiException.mustache +111 -0
- package/templates/php/Configuration.mustache +606 -0
- package/templates/php/FormDataProcessor.mustache +238 -0
- package/templates/php/HeaderSelector.mustache +265 -0
- package/templates/php/ModelInterface.mustache +103 -0
- package/templates/php/ObjectSerializer.mustache +591 -0
- package/templates/php/README.mustache +151 -0
- package/templates/php/api.mustache +891 -0
- package/templates/php/api_doc.mustache +105 -0
- package/templates/php/api_test.mustache +80 -0
- package/templates/php/composer.mustache +44 -0
- package/templates/php/git_push.sh.mustache +57 -0
- package/templates/php/gitignore +15 -0
- package/templates/php/libraries/psr-18/ApiException.mustache +114 -0
- package/templates/php/libraries/psr-18/DebugPlugin.mustache +93 -0
- package/templates/php/libraries/psr-18/README.mustache +161 -0
- package/templates/php/libraries/psr-18/api.mustache +833 -0
- package/templates/php/libraries/psr-18/api_doc.mustache +79 -0
- package/templates/php/libraries/psr-18/composer.mustache +56 -0
- package/templates/php/model.mustache +47 -0
- package/templates/php/model_doc.mustache +10 -0
- package/templates/php/model_enum.mustache +33 -0
- package/templates/php/model_generic.mustache +565 -0
- package/templates/php/model_test.mustache +88 -0
- package/templates/php/partial_header.mustache +18 -0
- package/templates/php/php_doc_auth_partial.mustache +23 -0
- package/templates/php/phpunit.xml.mustache +18 -0
- package/templates/python/README.mustache +60 -0
- package/templates/python/README_onlypackage.mustache +50 -0
- package/templates/python/__init__.mustache +1 -0
- package/templates/python/__init__api.mustache +19 -0
- package/templates/python/__init__model.mustache +22 -0
- package/templates/python/__init__package.mustache +49 -0
- package/templates/python/api.mustache +244 -0
- package/templates/python/api_client.mustache +822 -0
- package/templates/python/api_doc.mustache +81 -0
- package/templates/python/api_doc_example.mustache +38 -0
- package/templates/python/api_response.mustache +21 -0
- package/templates/python/api_test.mustache +48 -0
- package/templates/python/asyncio/rest.mustache +209 -0
- package/templates/python/common_README.mustache +85 -0
- package/templates/python/configuration.mustache +806 -0
- package/templates/python/exceptions.mustache +210 -0
- package/templates/python/exports_api.mustache +3 -0
- package/templates/python/exports_model.mustache +3 -0
- package/templates/python/exports_package.mustache +20 -0
- package/templates/python/git_push.sh.mustache +57 -0
- package/templates/python/github-workflow.mustache +35 -0
- package/templates/python/gitignore.mustache +66 -0
- package/templates/python/gitlab-ci.mustache +31 -0
- package/templates/python/httpx/rest.mustache +190 -0
- package/templates/python/model.mustache +16 -0
- package/templates/python/model_anyof.mustache +182 -0
- package/templates/python/model_doc.mustache +40 -0
- package/templates/python/model_enum.mustache +36 -0
- package/templates/python/model_generic.mustache +403 -0
- package/templates/python/model_oneof.mustache +209 -0
- package/templates/python/model_test.mustache +60 -0
- package/templates/python/partial_api.mustache +52 -0
- package/templates/python/partial_api_args.mustache +18 -0
- package/templates/python/partial_header.mustache +19 -0
- package/templates/python/py.typed.mustache +1 -0
- package/templates/python/pyproject.mustache +172 -0
- package/templates/python/python_doc_auth_partial.mustache +108 -0
- package/templates/python/requirements.mustache +23 -0
- package/templates/python/rest.mustache +254 -0
- package/templates/python/setup.mustache +60 -0
- package/templates/python/setup_cfg.mustache +2 -0
- package/templates/python/signing.mustache +422 -0
- package/templates/python/test-requirements.mustache +6 -0
- package/templates/python/tornado/rest.mustache +148 -0
- package/templates/python/tox.mustache +9 -0
- package/templates/python/travis.mustache +17 -0
- package/templates/typescript-fetch/ApiEntitiesRecord.mustache +26 -0
- package/templates/typescript-fetch/ApiEntitiesReducer.mustache +21 -0
- package/templates/typescript-fetch/ApiEntitiesSelectors.mustache +5 -0
- package/templates/typescript-fetch/README.mustache +127 -0
- package/templates/typescript-fetch/allSagas.mustache +19 -0
- package/templates/typescript-fetch/api_doc.mustache +63 -0
- package/templates/typescript-fetch/api_example.mustache +44 -0
- package/templates/typescript-fetch/apis.index.mustache +16 -0
- package/templates/typescript-fetch/apis.mustache +483 -0
- package/templates/typescript-fetch/apisAssignQueryParam.mustache +12 -0
- package/templates/typescript-fetch/gitignore +4 -0
- package/templates/typescript-fetch/index.mustache +17 -0
- package/templates/typescript-fetch/licenseInfo.mustache +11 -0
- package/templates/typescript-fetch/modelEnum.mustache +28 -0
- package/templates/typescript-fetch/modelEnumInterfaces.mustache +37 -0
- package/templates/typescript-fetch/modelGeneric.mustache +261 -0
- package/templates/typescript-fetch/modelGenericInterfaces.mustache +50 -0
- package/templates/typescript-fetch/modelOneOf.mustache +255 -0
- package/templates/typescript-fetch/modelOneOfInterfaces.mustache +6 -0
- package/templates/typescript-fetch/model_doc.mustache +41 -0
- package/templates/typescript-fetch/models.index.mustache +32 -0
- package/templates/typescript-fetch/models.mustache +24 -0
- package/templates/typescript-fetch/npmignore.mustache +1 -0
- package/templates/typescript-fetch/package.mustache +43 -0
- package/templates/typescript-fetch/recordGeneric.mustache +295 -0
- package/templates/typescript-fetch/records.mustache +17 -0
- package/templates/typescript-fetch/runtime.mustache +424 -0
- package/templates/typescript-fetch/runtimeSagasAndRecords.mustache +120 -0
- package/templates/typescript-fetch/sagaApiManager.mustache +28 -0
- package/templates/typescript-fetch/sagas.mustache +245 -0
- package/templates/typescript-fetch/sourceLibraryIndex.mustache +1 -0
- package/templates/typescript-fetch/tsconfig.esm.mustache +7 -0
- package/templates/typescript-fetch/tsconfig.mustache +25 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// {{{classname}}} {{{description}}}{{#unless description}}the model '{{{classname}}}'{{/unless}}
|
|
2
|
+
type {{{classname}}} {{{format}}}{{^format}}{{dataType}}{{/format}}
|
|
3
|
+
|
|
4
|
+
// List of {{{name}}}
|
|
5
|
+
const (
|
|
6
|
+
{{#allowableValues}}
|
|
7
|
+
{{#enumVars}}
|
|
8
|
+
{{#unless @first}}
|
|
9
|
+
{{/unless}}
|
|
10
|
+
{{#enumClassPrefix}}{{{classname.toUpperCase}}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}}
|
|
11
|
+
{{/enumVars}}
|
|
12
|
+
{{/allowableValues}}
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
// All allowed values of {{{classname}}} enum
|
|
16
|
+
var Allowed{{{classname}}}EnumValues = []{{{classname}}}{
|
|
17
|
+
{{#allowableValues}}
|
|
18
|
+
{{#enumVars}}
|
|
19
|
+
{{{value}}},
|
|
20
|
+
{{/enumVars}}
|
|
21
|
+
{{/allowableValues}}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func (v *{{{classname}}}) UnmarshalJSON(src []byte) error {
|
|
25
|
+
var value {{{format}}}{{^format}}{{dataType}}{{/format}}
|
|
26
|
+
err := json.Unmarshal(src, &value)
|
|
27
|
+
if err != nil {
|
|
28
|
+
return err
|
|
29
|
+
}
|
|
30
|
+
enumTypeValue := {{{classname}}}(value)
|
|
31
|
+
for _, existing := range Allowed{{{classname}}}EnumValues {
|
|
32
|
+
if existing == enumTypeValue {
|
|
33
|
+
*v = enumTypeValue
|
|
34
|
+
return nil
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return fmt.Errorf("%+v is not a valid {{classname}}", value)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// New{{{classname}}}FromValue returns a pointer to a valid {{{classname}}}
|
|
42
|
+
// for the value passed as argument, or an error if the value passed is not allowed by the enum
|
|
43
|
+
func New{{{classname}}}FromValue(v {{{format}}}{{^format}}{{dataType}}{{/format}}) (*{{{classname}}}, error) {
|
|
44
|
+
ev := {{{classname}}}(v)
|
|
45
|
+
if ev.IsValid() {
|
|
46
|
+
return &ev, nil
|
|
47
|
+
} else {
|
|
48
|
+
return nil, fmt.Errorf("invalid value '%v' for {{{classname}}}: valid values are %v", v, Allowed{{{classname}}}EnumValues)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// IsValid return true if the value is valid for the enum, false otherwise
|
|
53
|
+
func (v {{{classname}}}) IsValid() bool {
|
|
54
|
+
for _, existing := range Allowed{{{classname}}}EnumValues {
|
|
55
|
+
if existing == v {
|
|
56
|
+
return true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Ptr returns reference to {{{name}}} value
|
|
63
|
+
func (v {{{classname}}}) Ptr() *{{{classname}}} {
|
|
64
|
+
return &v
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type Nullable{{{classname}}} struct {
|
|
68
|
+
value *{{{classname}}}
|
|
69
|
+
isSet bool
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
func (v Nullable{{classname}}) Get() *{{classname}} {
|
|
73
|
+
return v.value
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
func (v *Nullable{{classname}}) Set(val *{{classname}}) {
|
|
77
|
+
v.value = val
|
|
78
|
+
v.isSet = true
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
func (v Nullable{{classname}}) IsSet() bool {
|
|
82
|
+
return v.isSet
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
func (v *Nullable{{classname}}) Unset() {
|
|
86
|
+
v.value = nil
|
|
87
|
+
v.isSet = false
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
func NewNullable{{classname}}(val *{{classname}}) *Nullable{{classname}} {
|
|
91
|
+
return &Nullable{{classname}}{value: val, isSet: true}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) {
|
|
95
|
+
return json.Marshal(v.value)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error {
|
|
99
|
+
v.isSet = true
|
|
100
|
+
return json.Unmarshal(src, &v.value)
|
|
101
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// {{classname}} - {{{description}}}{{#unless description}}struct for {{{classname}}}{{/unless}}
|
|
2
|
+
type {{classname}} struct {
|
|
3
|
+
{{#oneOf}}
|
|
4
|
+
{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} *{{{.}}}
|
|
5
|
+
{{/oneOf}}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
{{#oneOf}}
|
|
9
|
+
// {{{.}}}As{{classname}} is a convenience function that returns {{{.}}} wrapped in {{classname}}
|
|
10
|
+
func {{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}As{{classname}}(v *{{{.}}}) {{classname}} {
|
|
11
|
+
return {{classname}}{
|
|
12
|
+
{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}: v,
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
{{/oneOf}}
|
|
17
|
+
|
|
18
|
+
// Unmarshal JSON data into one of the pointers in the struct
|
|
19
|
+
func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
|
|
20
|
+
var err error
|
|
21
|
+
{{#isNullable}}
|
|
22
|
+
// this object is nullable so check if the payload is null or empty string
|
|
23
|
+
if string(data) == "" || string(data) == "{}" {
|
|
24
|
+
return nil
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
{{/isNullable}}
|
|
28
|
+
{{#useOneOfDiscriminatorLookup}}
|
|
29
|
+
{{#discriminator}}
|
|
30
|
+
{{#mappedModels}}
|
|
31
|
+
{{#if @first}}
|
|
32
|
+
// use discriminator value to speed up the lookup
|
|
33
|
+
var jsonDict map[string]interface{}
|
|
34
|
+
err = newStrictDecoder(data).Decode(&jsonDict)
|
|
35
|
+
if err != nil {
|
|
36
|
+
return fmt.Errorf("failed to unmarshal JSON into map for the discriminator lookup")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
{{/if}}
|
|
40
|
+
// check if the discriminator value is '{{{mappingName}}}'
|
|
41
|
+
if jsonDict["{{{propertyBaseName}}}"] == "{{{mappingName}}}" {
|
|
42
|
+
// try to unmarshal JSON data into {{{modelName}}}
|
|
43
|
+
err = json.Unmarshal(data, &dst.{{{modelName}}})
|
|
44
|
+
if err == nil {
|
|
45
|
+
return nil // data stored in dst.{{{modelName}}}, return on the first match
|
|
46
|
+
} else {
|
|
47
|
+
dst.{{{modelName}}} = nil
|
|
48
|
+
return fmt.Errorf("failed to unmarshal {{classname}} as {{{modelName}}}: %s", err.Error())
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
{{/mappedModels}}
|
|
53
|
+
return nil
|
|
54
|
+
{{/discriminator}}
|
|
55
|
+
{{^discriminator}}
|
|
56
|
+
match := 0
|
|
57
|
+
{{#oneOf}}
|
|
58
|
+
// try to unmarshal data into {{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}
|
|
59
|
+
err = json.Unmarshal(data, &dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
|
|
60
|
+
if err == nil {
|
|
61
|
+
json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}, _ := json.Marshal(dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
|
|
62
|
+
if string(json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) == "{}" { // empty struct
|
|
63
|
+
dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil
|
|
64
|
+
} else {
|
|
65
|
+
match++
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
{{/oneOf}}
|
|
72
|
+
if match > 1 { // more than 1 match
|
|
73
|
+
// reset to nil
|
|
74
|
+
{{#oneOf}}
|
|
75
|
+
dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil
|
|
76
|
+
{{/oneOf}}
|
|
77
|
+
|
|
78
|
+
return fmt.Errorf("data matches more than one schema in oneOf({{classname}})")
|
|
79
|
+
} else if match == 1 {
|
|
80
|
+
return nil // exactly one match
|
|
81
|
+
} else { // no match
|
|
82
|
+
return fmt.Errorf("data failed to match schemas in oneOf({{classname}})")
|
|
83
|
+
}
|
|
84
|
+
{{/discriminator}}
|
|
85
|
+
{{/useOneOfDiscriminatorLookup}}
|
|
86
|
+
{{^useOneOfDiscriminatorLookup}}
|
|
87
|
+
match := 0
|
|
88
|
+
{{#oneOf}}
|
|
89
|
+
// try to unmarshal data into {{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}
|
|
90
|
+
err = newStrictDecoder(data).Decode(&dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
|
|
91
|
+
if err == nil {
|
|
92
|
+
json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}, _ := json.Marshal(dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
|
|
93
|
+
if string(json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) == "{}" { // empty struct
|
|
94
|
+
dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil
|
|
95
|
+
} else {
|
|
96
|
+
if err = validator.Validate(dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}); err != nil {
|
|
97
|
+
dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil
|
|
98
|
+
} else {
|
|
99
|
+
match++
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
{{/oneOf}}
|
|
107
|
+
if match > 1 { // more than 1 match
|
|
108
|
+
// reset to nil
|
|
109
|
+
{{#oneOf}}
|
|
110
|
+
dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil
|
|
111
|
+
{{/oneOf}}
|
|
112
|
+
|
|
113
|
+
return fmt.Errorf("data matches more than one schema in oneOf({{classname}})")
|
|
114
|
+
} else if match == 1 {
|
|
115
|
+
return nil // exactly one match
|
|
116
|
+
} else { // no match
|
|
117
|
+
return fmt.Errorf("data failed to match schemas in oneOf({{classname}})")
|
|
118
|
+
}
|
|
119
|
+
{{/useOneOfDiscriminatorLookup}}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Marshal data from the first non-nil pointers in the struct to JSON
|
|
123
|
+
func (src {{classname}}) MarshalJSON() ([]byte, error) {
|
|
124
|
+
{{#oneOf}}
|
|
125
|
+
if src.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} != nil {
|
|
126
|
+
return json.Marshal(&src.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
{{/oneOf}}
|
|
130
|
+
return nil, nil // no data in oneOf schemas
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Get the actual instance
|
|
134
|
+
func (obj *{{classname}}) GetActualInstance() (interface{}) {
|
|
135
|
+
if obj == nil {
|
|
136
|
+
return nil
|
|
137
|
+
}
|
|
138
|
+
{{#oneOf}}
|
|
139
|
+
if obj.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} != nil {
|
|
140
|
+
return obj.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
{{/oneOf}}
|
|
144
|
+
// all schemas are nil
|
|
145
|
+
return nil
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Get the actual instance value
|
|
149
|
+
func (obj {{classname}}) GetActualInstanceValue() (interface{}) {
|
|
150
|
+
{{#oneOf}}
|
|
151
|
+
if obj.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} != nil {
|
|
152
|
+
return *obj.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
{{/oneOf}}
|
|
156
|
+
// all schemas are nil
|
|
157
|
+
return nil
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
{{>nullable_model}}
|