How do you define an array of different examples in a Swagger spec?

Joseph Downing

I'm trying to document an API with a static swagger file that can return some JSON that contains an array that looks something like this:

[
  {
    "type": "type A",
    "field A": "this field is specific to type A"
  },
  {
    "type": "type B",
    "field B": "this field is specific to type B"
  }
]

I've tried a few different ways of defining my spec using either polymorphism or explicitly defining multiple examples. The examples have always either ended up looking like:

[
  {
    "type": "type A",
    "field A": "this field is specific to type A",
    "field B": "this field is specific to type B"
  }
]

or just:

[
  {
    "type": "type A",
    "field A": "this field is specific to type A"
  }
]

Is there a way to define an example in my swagger spec so that the example payload shown by swagger-ui will contain an array containing an example of Type A and an example of Type B like the first JSON I wrote?

Nelson G.

You can't.

You can only define one example per mime-type per response :

{
  "description": "A response",
  "schema": {
    "type": "string"
    }
  },
  "examples": {
    "application/json": {
      "name": "Dog"
    },
    "application/xml": {
      "name": "Cat"
    }
  }
}

If you want add complete scenario, I suggest you to write (or generate) a full scenario example in an HTML page and link it with an externalDocs. You can define externalDocs in root, operations, tags and schemas.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do you define a char array as a constant?

From Dev

In Swagger, how do I define a parameter as a multidimensional array?

From Dev

How do I refactor this Swagger API Spec

From Dev

How to define empty array in swagger

From Dev

Different examples for same model in swagger

From Java

How is spec/rails_helper.rb different from spec/spec_helper.rb? Do I need it?

From Dev

How do you align output of different lengths coming from an array?

From Dev

How do you create RPM from .spec file?

From Dev

How do you define trait using Fabrication

From Dev

How do you define an ordered pair in Coq?

From Dev

How do you define constants in Elixir modules?

From Dev

how do you define a language that is not compiled

From Dev

How do you exactly define domain service

From Dev

How do you define a deconstructor in c++?

From Dev

How do you define trait using Fabrication

From Dev

How to define a map in swagger?

From Dev

How do you define a static matrix with #define in C?

From Dev

How do I define possible return values with Swagger.io

From Dev

If you define an object in an anonymous function -- how do you use it?

From Java

Can you monkey-patch built in classes and if not, how do I overload an operator to define addition for two different classes?

From Dev

How to express "arbitrary JSON" in swagger-spec?

From Dev

How to receive a dynamic response in a Swagger spec

From Dev

How do you use an array?

From Dev

How do you annotate a nested Java class for Swagger?

From Dev

How do I define an associative array?

From Dev

How do you fill an array with objects from a different class? deteils below

From Dev

How do you append an array to an array in numpy?

From Dev

How do you define DBContext properly in a Class Library Project?

From Dev

How and where do you define your database structure in Meteor?

Related Related

  1. 1

    How do you define a char array as a constant?

  2. 2

    In Swagger, how do I define a parameter as a multidimensional array?

  3. 3

    How do I refactor this Swagger API Spec

  4. 4

    How to define empty array in swagger

  5. 5

    Different examples for same model in swagger

  6. 6

    How is spec/rails_helper.rb different from spec/spec_helper.rb? Do I need it?

  7. 7

    How do you align output of different lengths coming from an array?

  8. 8

    How do you create RPM from .spec file?

  9. 9

    How do you define trait using Fabrication

  10. 10

    How do you define an ordered pair in Coq?

  11. 11

    How do you define constants in Elixir modules?

  12. 12

    how do you define a language that is not compiled

  13. 13

    How do you exactly define domain service

  14. 14

    How do you define a deconstructor in c++?

  15. 15

    How do you define trait using Fabrication

  16. 16

    How to define a map in swagger?

  17. 17

    How do you define a static matrix with #define in C?

  18. 18

    How do I define possible return values with Swagger.io

  19. 19

    If you define an object in an anonymous function -- how do you use it?

  20. 20

    Can you monkey-patch built in classes and if not, how do I overload an operator to define addition for two different classes?

  21. 21

    How to express "arbitrary JSON" in swagger-spec?

  22. 22

    How to receive a dynamic response in a Swagger spec

  23. 23

    How do you use an array?

  24. 24

    How do you annotate a nested Java class for Swagger?

  25. 25

    How do I define an associative array?

  26. 26

    How do you fill an array with objects from a different class? deteils below

  27. 27

    How do you append an array to an array in numpy?

  28. 28

    How do you define DBContext properly in a Class Library Project?

  29. 29

    How and where do you define your database structure in Meteor?

HotTag

Archive