Possible bug in JSON generation when using reusable examples from components/examples
Per documentation at https://swagger.io/docs/specification/adding-examples/ I should be able to define examples of schema objects and use them in request/response bodies. When defining a request body content like so: ... content: application/json: schema: $ref: "#/components/schemas/BidLineSummary" examples: objectExample: $ref: "#/components/examples/BidLineSummaryCapExample" ... The generated API shows no values from the referenced example, but does show the object model and it's field defaults. Changing up the above to be: ... content: application/json: schema: $ref: "#/components/schemas/BidLineSummary" example: BidLineSummaryCapExample: $ref: "#/components/examples/BidLineSummaryCapExample" ... (note example with 's' removed) gives generated JSON like: { "BidLineSummaryCapExample": { "value": { "id": "bb89c07f-0f1b-47a9-bcac-ff9ac4f44ee0", "bidMonth": 11, "bidYear": 2018, "baseName": "mem11", "seatPosition": "CAP", "userEnteredPilotCount": 365, "systemPilotCount": null, "userEnteredPayOnlyPilotCount": 52, "systemPayOnlyPilotCount": null, "userEnteredRegularLineCount": 208, "systemRegularLineCount": null, "suggestedRegularLineCount": null, "userEnteredReserveLineCount": 34, "systemReserveLineCount": null, "suggestedReserveLineCount": null, "userEnteredSecondaryLineCount": 71, "systemSecondaryLineCount": null, "suggestedSecondaryLineCount": null }, "$$ref": "#/components/examples/BidLineSummaryCapExample" } } Why is it returning the $ref definition after the object body? The JSON is entirely wrong as the correct output should be: { "id": "bb89c07f-0f1b-47a9-bcac-ff9ac4f44ee0", "bidMonth": 11, "bidYear": 2018, "baseName": "mem11", "seatPosition": "CAP", "userEnteredPilotCount": 365, "systemPilotCount": null, "userEnteredPayOnlyPilotCount": 52, "systemPayOnlyPilotCount": null, "userEnteredRegularLineCount": 208, "systemRegularLineCount": null, "suggestedRegularLineCount": null, "userEnteredReserveLineCount": 34, "systemReserveLineCount": null, "suggestedReserveLineCount": null, "userEnteredSecondaryLineCount": 71, "systemSecondaryLineCount": null, "suggestedSecondaryLineCount": null } Which is the same output generated when defining the exact same example directly within the request body like so: requestBody: content: application/json: schema: $ref: '#/components/schemas/BidLineSummary' example: id: bb89c07f-0f1b-47a9-bcac-ff9ac4f44ee0 bidMonth: 11 bidYear: 2018 baseName: mem11 seatPosition: CAP userEnteredPilotCount: 365 systemPilotCount: null userEnteredPayOnlyPilotCount: 52 systemPayOnlyPilotCount: null userEnteredRegularLineCount: 208 systemRegularLineCount: null suggestedRegularLineCount: null userEnteredReserveLineCount: 34 systemReserveLineCount: null suggestedReserveLineCount: null userEnteredSecondaryLineCount: 71 systemSecondaryLineCount: null suggestedSecondaryLineCount: null It appears this is a bug with the JSON generation when using $ref to components/examples. Any help would be appreciated as we can workaround currently by defining all examples in the request/response bodies but it would be much more useful to be able to have reusable examples. Thanks, Nate BrandeburgSolved2.1KViews0likes2Comments