swagger-api / swagger-api/swagger-codegen
[golang][python] Different client behaviour between go-client and python-client
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
go-client isn't enforcing required properties of inner object that aren't set at all while python-client is.
outer-type:
type: object
properties:
inner-type:
type: object
other-object:
...
inner-type:
type: object
required:
- a
- b
properties:
a:
type: string
b:
type: string
If I use an API that required outer-type as a parameter but I don't set inner-type at all in it:
- go-client won't enforce setting
aandbproperties (this is the better option IMO as we don't want anyinner-typein the request) - python-client will enforce it though, which means that on each API call I have to manually set ALL the required fields of all the nested objects (even if I don't want their parent objects at all).
The best UX to me would have been to enforce only the required properties of the objects that were explicitly created in the request.
Swagger-codegen version
Reproduced on 2.4.15 and on 2.4.21
Swagger declaration file content or URL
Command line used for generation
function generate_go_client() {
rm -rf client models
docker run -u $(id -u):$(id -u) -v ${__root}:${__root}:rw,Z -v /etc/passwd:/etc/passwd -w ${__root} \
quay.io/goswagger/swagger:v0.25.0 generate client --template=stratoscale -f swagger.yaml \
--template-dir=/templates/contrib
}
function generate_python_client() {
local dest="${BUILD_FOLDER}"
rm -rf "${dest}"/assisted-service-client/*
docker run --rm -u "$(id -u)" --entrypoint /bin/sh \
-v "${dest}":/local:Z \
-v "${__root}"/swagger.yaml:/swagger.yaml:ro,Z \
-v "${__root}"/tools/generate_python_client.sh:/script.sh:ro,Z \
-e SWAGGER_FILE=/swagger.yaml -e OUTPUT=/local/assisted-service-client/ \
quay.io/ocpmetal/swagger-codegen-cli:2.4.15 /script.sh
cd "${dest}"/assisted-service-client/ && python3 setup.py sdist --dist-dir "${dest}"
cd "${dest}"/assisted-service-client/ && python3 "${__root}"/tools/client_package_initializer.py "${dest}"/assisted-service-client/ https://github.com/openshift/assisted-service --build
}
Steps to reproduce
- clone the repo assited-service - make sure you got that specific branch.
skipper make generate-all
You can installskipperfrom here
Suggest a fix/enhancement
Make python-client act like go-client
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked swagger.yaml and reproduce generation using the shown generate_go_client and generate_python_client commands, including tools/generate_python_client.sh. Compare validation of an omitted inner-type between the generated clients; done means the Python client no longer requires fields from nested objects that were not explicitly created.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100