-
Notifications
You must be signed in to change notification settings - Fork 739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allOf as schema reference is not allowed #2652
Comments
That's not valid the way you have it. do you want the properties:
audit:
description: Audit data with information regarding document creation and modification.
$ref: '#/definitions/StoreAudit' |
I'm pretty sure that this is not allowed according to the JSON $ref spec... |
See https://swagger.io/docs/specification/using-ref/
|
Ah, yeah, that's technically not allowed -- the The trouble with that is if I have properties Autorest is a smidgen lenient on that one, since there isn't a way to describe the use of a type opposed to it's declaration description. if you want to be 100% conformant, you can't do what you're looking for. |
Ok, I see, AutoRest is in the good position to be only a consumer of specs... But why is
not allowed/better: It does not violate the rules (as $ref would) and is semantically the same (allOf with one ref == $ref)? |
Hmm. It does work. I tried it with petstore, and it works just fine. "Pet": {
"required": [
"name",
"photoUrls"
],
"properties": {
"id": {
"type": "integer",
"format": "int64",
"title": "The id of the pet.",
"description": "A more detailed description of the id of the pet."
},
"category": {
"description": "mooooo ramble ramble ramble ramble ramble ramble ramble ramble ramble",
"allOf" : [
{ "$ref": "#/definitions/Category" }
]
},
"name": {
"type": "string",
"example": "doggie"
},
"photoUrls": {
"type": "array",
"xml": {
"name": "photoUrl",
"wrapped": true
},
"items": {
"type": "string"
}
},
"tags": {
"type": "array",
"xml": {
"name": "tag",
"wrapped": true
},
"items": {
"$ref": "#/definitions/Tag"
}
},
"status": {
"type": "string",
"description": "pet status in the store",
"enum": [
"available",
"pending",
"sold"
]
}
},
"title": "A pet",
"description": "A group of properties representing a pet.",
"xml": {
"name": "Pet"
}
}, AutoRest does make a subclass |
Strange, with the Java generator I had exceptions. However I still think you should handle this like a $ref. |
I just tried the same thing with the java generator and it worked fine. Is your reference correct? |
My spec is much more complex with discriminators etc. I'll try to create a reproduction sample tomorrow... |
Using |
I hope i can look into this tomorrow... |
Currently I have to transform the Swagger spec the following way: The original spec: https://github.com/Picturepark/Picturepark.SDK.DotNet/blob/master/swagger/PictureparkSwagger.json The transformed spec: Generation works with the transformed specs, but I have to manually fix the following Java code: https://github.com/Picturepark/Picturepark.SDK.Playground#java |
@RSuter looking into it. 🙂 You wrote:
Just to clarify, since I'm no expert about our Java generator: Are those fixes side-effects of the Swagger transformations you did? It does not look like it (why would imports be missing or Now back to the actual |
No the fixes are additional problems... and should probably looked at by Java guys (I'm a .NET guy so maybe I also did something wrong, but the missing imports are surely a bug). |
I split that issue out to #2665 so it doesn't get messy in here... |
Okay, upon further investigation, I unfortunately have to say that some of the issues AutoRest has with the (untransformed) Swagger are kind of by design: This seems to cause even bigger troubles in other places:
So essentially we "solved" the above design conflicts by not generating code in any such case. 😞 I partied on your original Swagger and only ended up with pretty much identical transformations as you did. Sorry that there's no better answer at this point, but looking at your nice transformer, I guess you're at least not blocked by this - please let me know if you encounter anything that you feel like it is something we should implement/fix (like the Java stuff! 😃) to at least get a little closer to Nirvana (where every valid Swagger can be stuck inside AutoRest). |
For this project I'm not blocked, correct. But I develop the Swagger toolchain NSwag and I'd like to support as many other tools as possible. This is why these transformations are not really feasible for a greater audience... In my code generators I treat $ref and allOf (with a single entry) the same. So this means that it is not a problem whether the spec has $refs or allOf refs. Isn't this an option for you too?
|
Fair points regarding the fixes, will look into/discuss it 🙂 Regarding 2, I think that is one of the odd decisions that were once made (I think not having |
I discovered a problem with my Swagger spec which is generated with NSwag.
The problem applies to parameters and schema properties. It happens if the parameter or property has a "description" (which belongs only to the parameter/property) and needs a reference to another type from the "definitions". The problem is that $ref is only allowed as only property (we also have a "description"). This is why NSwag generates the "description" and the $ref in an "allOf".
See sample:
My questions are:
Btw: I'm the developer of NSwag.
The text was updated successfully, but these errors were encountered: