Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- lifts nested validations with allOf, additionalProperties, additionalItems, maps and slices of such constructs - ensures that empty Validate() func remain empty when there is no validation (e.g. just return nil) - fixes incorrect codegen with empty objects and additionalProperties (conflict on nullable) - fixes missing validations with additionalProperties (aliased types, nested maps ending with a $ref) - removes NeedsValidation, NeedsRequired - adds codegen UT, to run and assert both the default flatten and the --skip-flatten option (expand) - fixes unmarshaller for anonymous nested allOf - expand UT coverage on model.go and types.go Fixes: - fixes #1487 (nested validations with additionalItems) - fixes #1479 (nested validations with allOf) - fixes #1453 (maps of slices, empty objects) For the following issues, it is difficult to tell if they were already fixed or not. Anyhow, this commit asserts the codegen for those, with spec flatten (default) and expand option. Acknowledges past fixes (with possible slight codegen modifications) and adds non-reg UT: - fixes #1198 - additionalProperties - fixes #979 - allOf - fixes #1042 - allOf The following (polymorphic cases) are acknowledged only with the default spec flatten option: - fixes #606 - polymorphic types (and non-reg on duplicate #1336) - fixes #842 - polymorphic types - fixes #607 - polymorphic types Contributes to : - #1232 - allOf - #1233 - polymorphic types
- Loading branch information
Showing
50 changed files
with
16,318 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
swagger: "2.0" | ||
info: | ||
title: allOf marshalling | ||
description: | | ||
when the specification incorrectly defines the allOf, | ||
generated unmarshalling is wrong. | ||
This fixture asserts that with correct spec, the generated models are correct. | ||
version: "0.0" | ||
|
||
basePath: "/test" | ||
|
||
paths: | ||
"/allof": | ||
get: | ||
responses: | ||
'200': | ||
description: test | ||
schema: | ||
"$ref": "#/definitions/ExtendedErrorModel" | ||
|
||
definitions: | ||
ErrorModel: | ||
type: object | ||
required: | ||
- message | ||
- code | ||
properties: | ||
message: | ||
type: string | ||
code: | ||
type: integer | ||
minimum: 100 | ||
maximum: 600 | ||
ExtendedErrorModel: | ||
allOf: | ||
- $ref: '#/definitions/ErrorModel' | ||
- type: object | ||
required: | ||
- rootCause | ||
properties: | ||
rootCause: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"title": "allOf marshalling", | ||
"description": "when the specification incorrectly defines the allOf,\ngenerated unmarshalling is wrong.\nThis fixture asserts that with correct spec, the generated models are correct.\n", | ||
"version": "0.0" | ||
}, | ||
"basePath": "/test", | ||
"paths": { | ||
"/allof": { | ||
"get": { | ||
"responses": { | ||
"200": { | ||
"description": "test", | ||
"schema": { | ||
"$ref": "#/definitions/B" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"A": { | ||
"description": "a first definition A", | ||
"type": "object", | ||
"properties": { | ||
"f1": { | ||
"type": "string" | ||
}, | ||
"f2": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"B": { | ||
"description": "a second definition B, which extends A", | ||
"type": "object", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/A" | ||
}, | ||
null | ||
], | ||
"required": [ | ||
"f3", | ||
"f4" | ||
], | ||
"properties": { | ||
"f3": { | ||
"type": "string" | ||
}, | ||
"f4": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
swagger: "2.0" | ||
info: | ||
title: allOf marshalling | ||
description: | | ||
when the specification incorrectly defines the allOf, | ||
generated unmarshalling is wrong. | ||
This fixture asserts that with correct spec, the generated models are correct. | ||
version: "0.0" | ||
|
||
basePath: "/test" | ||
|
||
paths: | ||
"/allof": | ||
get: | ||
responses: | ||
'200': | ||
description: test | ||
schema: | ||
"$ref": "#/definitions/B" | ||
|
||
definitions: | ||
A: | ||
description: a first definition A | ||
type: object | ||
properties: | ||
f1: | ||
type: string | ||
f2: | ||
type: string | ||
|
||
B: | ||
description: a second definition B, which extends A | ||
type: object | ||
allOf: | ||
- "$ref": "#/definitions/A" | ||
- | ||
required: | ||
- f3 | ||
- f4 | ||
properties: | ||
f3: | ||
type: string | ||
f4: | ||
type: array | ||
items: | ||
type: string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"title": "allOf marshalling", | ||
"description": "when the specification incorrectly defines the allOf,\ngenerated unmarshalling is wrong.\nThis fixture asserts that with correct spec, the generated models are correct.\n", | ||
"version": "0.0" | ||
}, | ||
"basePath": "/test", | ||
"paths": { | ||
"/allof": { | ||
"get": { | ||
"responses": { | ||
"200": { | ||
"description": "test", | ||
"schema": { | ||
"$ref": "#/definitions/B" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"A": { | ||
"description": "a first definition A", | ||
"type": "object", | ||
"properties": { | ||
"f1": { | ||
"type": "string" | ||
}, | ||
"f2": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"B": { | ||
"description": "a second definition B, which extends A", | ||
"type": "object", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/A" | ||
}, | ||
{ | ||
"required": [ | ||
"f3", | ||
"f4" | ||
], | ||
"properties": { | ||
"f3": { | ||
"type": "string" | ||
}, | ||
"f4": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
swagger: "2.0" | ||
info: | ||
title: allOf marshalling | ||
description: | | ||
when the specification incorrectly defines the allOf, | ||
generated unmarshalling is wrong. | ||
This fixture asserts that with correct spec, the generated models are correct. | ||
version: "0.0" | ||
|
||
basePath: "/test" | ||
|
||
paths: | ||
"/allof": | ||
get: | ||
responses: | ||
'200': | ||
description: test | ||
schema: | ||
"$ref": "#/definitions/B" | ||
|
||
definitions: | ||
A: | ||
description: a first definition A | ||
type: object | ||
properties: | ||
f1: | ||
type: string | ||
f2: | ||
type: string | ||
|
||
B: | ||
description: a second definition B, which extends A | ||
type: object | ||
allOf: | ||
- "$ref": "#/definitions/A" | ||
- | ||
required: | ||
- f3 | ||
- f4 | ||
properties: | ||
f3: | ||
type: string | ||
f4: | ||
type: array | ||
items: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#! /bin/bash | ||
if [[ ${1} == "--clean" ]] ; then | ||
clean=1 | ||
fi | ||
# Acknowledgements | ||
testcases="${testcases} fixture-1042.yaml" | ||
testcases="${testcases} fixture-1042-2.yaml" | ||
for testcase in ${testcases} ; do | ||
spec=${testcase} | ||
testcase=`basename ${testcase}` | ||
target=./gen-${testcase%.*} | ||
serverName="codegensrv" | ||
rm -rf ${target} | ||
mkdir ${target} | ||
echo "Model generation for ${spec}" | ||
swagger generate model --skip-validation --spec ${spec} --target ${target} --output=${testcase%.*}.log | ||
# 1>x.log 2>&1 | ||
# | ||
if [[ $? != 0 ]] ; then | ||
echo "Generation failed for ${spec}" | ||
exit 1 | ||
fi | ||
echo "${spec}: Generation OK" | ||
if [[ ! -d ${target}/models ]] ; then | ||
echo "No model in this spec! Skipped" | ||
else | ||
(cd ${target}/models; go build) | ||
if [[ $? != 0 ]] ; then | ||
echo "Build failed for ${spec}" | ||
exit 1 | ||
fi | ||
echo "${spec}: Build OK" | ||
if [[ -n ${clean} ]] ; then | ||
rm -rf ${target} | ||
fi | ||
fi | ||
done | ||
exit | ||
testcases=`cd ../../codegen;ls -1|grep -vE 'azure|bitbucket|existing-model|issue72|todolist.simple.yml'` | ||
#testcases=${testcases}" fixture-1062.json fixture-984.yaml" | ||
#testcases=`cd ../../codegen;ls -1|grep 'todolist.enums.yml'` | ||
for testcase in ${testcases} ; do | ||
target=./gen-${testcase%.*} | ||
if [[ -f ../../codegen/${testcase} ]] ; then | ||
spec=../../codegen/${testcase} | ||
else | ||
spec=${testcase} | ||
fi | ||
serverName="nrcodegen" | ||
rm -rf ${target} | ||
mkdir ${target} | ||
echo "Server generation for ${spec}" | ||
swagger generate server --skip-validation --spec ${spec} --target ${target} --name=${serverName} 1>${testcase%.*}.log 2>&1 | ||
#--output=${testcase%.*}.log | ||
if [[ $? != 0 ]] ; then | ||
echo "Generation failed for ${spec}" | ||
exit 1 | ||
fi | ||
echo "${spec}: Generation OK" | ||
(cd ${target}/cmd/${serverName}"-server"; go build) | ||
if [[ $? != 0 ]] ; then | ||
echo "Build failed for ${spec}" | ||
exit 1 | ||
fi | ||
echo "${spec}: Build OK" | ||
if [[ -n ${clean} ]] ; then | ||
rm -rf ${target} | ||
fi | ||
done | ||
# TODO(fredbi): enable non reg again | ||
testcases= | ||
for testcase in ${testcases} ; do | ||
target=./gen-${testcase%.*} | ||
spec=./${testcase} | ||
serverName="bugfix" | ||
rm -rf ${target} | ||
mkdir ${target} | ||
echo "Generation for ${spec}" | ||
swagger generate server --spec ${spec} --target ${target} --quiet --name=${serverName} | ||
if [[ $? != 0 ]] ; then | ||
echo "Generation failed for ${spec}" | ||
exit 1 | ||
fi | ||
echo "${spec}: Generation OK" | ||
(cd ${target}/cmd/${serverName}"-server"; go build) | ||
if [[ $? != 0 ]] ; then | ||
echo "Build failed for ${spec}" | ||
exit 1 | ||
fi | ||
echo "${spec}: Build OK" | ||
if [[ -n ${clean} ]] ; then | ||
rm -rf ${target} | ||
fi | ||
done |
Oops, something went wrong.