Open BenceSzalai opened 4 years ago
Meanwhile I've figured out that everything works fine, if the $ref
points to a schema object, not a property of it. So apparently the resolution works at least in part, because this is fine:
paths:
/offer/:
get:
parameters:
- name: country
schema:
$ref: '#/components/schemas/Country'
components:
schemas:
Offer:
type: object
properties:
country:
$ref: '#/components/schemas/Country'
Country:
type: string
According to the OpenAPI specs the references should work as defined by JSON Reference, so generally there's no restriction for parameter schema references to only allow pointing to direct children of #/components/schemas
, but not to the descendant of it.
Hit the same issue. Would be nice to have this solved.
Bug Report Checklist
Description
According to OpenAPI Specification v3.0.3
$ref
is allowed to define the schema of a Parameter object, however when doing so code generation generates warnings such asWARN o.o.codegen.utils.ModelUtils - #/components/schemas/... is not defined
, while the$ref
pointer is definitely correct, for example it can be resolved fine by a variety of other tools.openapi-generator version
This behaviour is the same for both
v5.0.0-beta2
andv4.3.1
. I've also checked against the latest snapshot.OpenAPI declaration file content or url
Full example: https://gist.github.com/BenceSzalai/908243fbe9a3107a11bf9093c77e31bc
Relevant excerpt:
Steps to reproduce
/bin/java -jar openapi-generator.jar generate -g php -i "sample.yaml" -o "generated"
Actually the chosen generator doesn't matter,-g php
is only an example.*[main] WARN o.o.codegen.utils.ModelUtils - #/components/schemas/Offer/properties/country is not defined
emitted during generation.*: In fact it exposes the issue more, since the
$country
parameter onDefaultApi::getOffer()
ingenerated/lib/Api/DefaultApi.php
gets type hinted with a non existent class:\OpenAPI\Client\Model\Country
instead ofstring
which should have been resolved from the$ref
. But probably it has further consequences in other generators as well.