Skip to content

Commit

Permalink
fixes undue propagation of x-go-name to tags in AllOf serializer
Browse files Browse the repository at this point in the history
* fixes go-swagger#2071
* added unit test on generated model

Signed-off-by: Frederic BIDON <[email protected]>
  • Loading branch information
fredbi committed Oct 2, 2019
1 parent 5499abf commit 4475a34
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 44 deletions.
3 changes: 3 additions & 0 deletions fixtures/bugs/2071/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gen-*
!gen-fixtures.sh
*.log
42 changes: 42 additions & 0 deletions fixtures/bugs/2071/fixture-2071.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
swagger: "2.0"
info:
title: "gen operation with body param, --skip-flatten mode"
version: "0.0.1"
description: "repro issue 1537"
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
paths:
/getPet:
get:
responses:
200:
description: "OK"
schema:
$ref: '#/definitions/Pet'
/getCat:
get:
responses:
200:
description: "OK"
schema:
$ref: '#/definitions/Cat'

definitions:
Pet:
type: object
properties:
name:
type: string
x-go-name: Name
x-nullable: true
Cat:
allOf:
- $ref: "#/definitions/Pet"
- type: "object"
properties:
ability:
type: string
x-go-name: SomeAbility
x-nullable: true
73 changes: 73 additions & 0 deletions fixtures/bugs/2071/gen-fixtures.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#! /bin/bash
if [[ ${1} == "--clean" ]] ; then
clean=1
fi
continueOnError=
# A small utility to build fixture servers
testcases="${testcases} fixture-2071.yaml"
for opts in "" "--with-expand" ; do
for testcase in ${testcases} ; do
grep -q discriminator ${testcase}
discriminated=$?
if [[ ${discriminated} -eq 0 && ${opts} == "--with-expand" ]] ; then
echo "Skipped ${testcase} with ${opts}: discriminator not supported with ${opts}"
continue
fi
if [[ ${testcase} == "../1479/fixture-1479-part.yaml" && ${opts} == "--with-expand" ]] ; then
echo "Skipped ${testcase} with ${opts}: known issue with enum in anonymous allOf not validated. See you next PR"
continue
fi

spec=${testcase}
testcase=`basename ${testcase}`
if [[ -z ${opts} ]]; then
target=./gen-${testcase%.*}-flatten
else
target=./gen-${testcase%.*}-expand
fi
serverName="codegensrv"
rm -rf ${target}
mkdir ${target}
echo "Model generation for ${spec} with opts=${opts}"
serverName="nrcodegen"
swagger generate server --skip-validation ${opts} --spec ${spec} --target ${target} --name=${serverName} 1>${testcase%.*}.log 2>&1
# 1>x.log 2>&1
#
if [[ $? != 0 ]] ; then
echo "Generation failed for ${spec}"
if [[ ! -z ${continueOnError} ]] ; then
failures="${failures} codegen:${spec}"
continue
else
exit 1
fi
fi
echo "${spec}: Generation OK"
if [[ ! -d ${target}/models ]] ; then
echo "No model in this spec! Continue building server"
fi
if [[ -d ${target}/cmd/${serverName}"-server" ]] ; then
(cd ${target}/cmd/${serverName}"-server"; go build)
#(cd ${target}/models; go build)
if [[ $? != 0 ]] ; then
echo "Build failed for ${spec}"
if [[ ! -z ${continueOnError} ]] ; then
failures="${failures} build:${spec}"
continue
else
exit 1
fi
fi
echo "${spec}: Build OK"
if [[ -n ${clean} ]] ; then
rm -rf ${target}
fi
fi
done
done
if [[ ! -z ${failures} ]] ; then
echo ${failures}|tr ' ' '\n'
else
echo "No failures"
fi
exit
Loading

0 comments on commit 4475a34

Please sign in to comment.