2

I found this excellent question/answer here, but there is no mention of how to go about making the "Pet" class abstract.

The fellow here indicates that this is only possible in the 3.0 specification. While this one here seems to have achieved abstract classes in Swagger 2.0 and is only having trouble with the annotations.

Is this possible in the Swagger 2.0 specification? If so, what tags do I need to utilize in the specification to have Swagger 2.0 generate abstract parent classes?

Helen
  • 87,344
  • 17
  • 243
  • 314
adv
  • 357
  • 5
  • 18

1 Answers1

4

OpenAPI Specification (fka Swagger Specification) is language-agnostic and does not have the concept of abstract classes. It's up to tool implementations to translate schema definitions into the most appropriate language structures.

For example, tools may choose to handle all "base" schemas as abstract classes (as discussed here).

Or tools may use an x- extension, such as x-abstract, to indicate abstract classes:

AbstractClass:
  type: object
  x-abstract: true  # <---
  properties:
    ...

x-abstract is supported by (at least) these two tools:
https://github.com/AphelionApps/SwaggerParser
https://github.com/Automatic/Manual


Bottom line: It depends on how specific tools process OpenAPI definitions.

Helen
  • 87,344
  • 17
  • 243
  • 314
  • I had looked at the extensions also. When extending the OAS implementation, I would be extending the specific implementation that I am using, not the OAS itself, correct? – adv Jul 23 '18 at 11:26
  • Correct. In OAS terms extensions are just user-defined metadata. Each implementation chooses which extensions (if any) it will support. – Helen Jul 23 '18 at 11:31
  • I am going to mark this as the answer, even though I do not have it working yet. It looks like the most promising path. – adv Jul 23 '18 at 13:52