YAML is a superset of JSON. This means you can use JSON syntax for objects and arrays within a YAML document.

In your first example, you can just remove the | after the value: to keep the example value as an object.

The following are equivalent:

examples:
  singlePet:
    summary: Single pet
    description: A request containing a single pet
    value:
      {
        "pets" : [
          {
            "petType" : "DOG",
            "name" : "Ben"
          }
        ]
      }
examples:
  singlePet:
    summary: Single pet
    description: A request containing a single pet
    value:
      pets:
      - petType: DOG
        name: Ben

Alternatively, you can use externalValue to point to an external file containing sample JSON.

examples:
  singlePet:
    summary: Single pet
    description: A request containing a single pet
    externalValue: 'https://api.example.com/docs/examples/pet.json'
Answer from Helen on Stack Overflow
🌐
GitHub
gist.github.com › kinlane › 43934f44fd591a6ee59a45267d9e3066
Sample OpenAPI 3.0 YAML · GitHub
Sample OpenAPI 3.0 YAML · Raw · sample-openapi-30.yaml · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below.
🌐
Swagger
swagger.io › docs › specification › v3_0 › basic-structure
Basic Structure | Swagger Docs
A sample OpenAPI 3.0 definition written in YAML looks like: ... description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML. ... All keyword names are case-sensitive. Every API definition must include the version of the OpenAPI Specification ...
🌐
Stoplight
stoplight.io › openapi
OpenAPI | OpenAPI Definition & Online Tools | Open API Standards List | Stoplight
The complete YAML of the GET request plus the POST request could look like this: openapi: 3.0.0 info: title: customer version: '1.0' servers: - url: 'https://api.example.com' paths: '/customers/{customer_id}': parameters: - schema: type: integer ...
🌐
SmartBear
support.smartbear.com › swaggerhub › docs › en › get-started › openapi-3-0-tutorial.html
OpenAPI 3.0 Tutorial | SwaggerHub Documentation
openapi: 3.0.0 info: version: 1.0.0 title: Sample API description: A sample API to illustrate OpenAPI concepts paths: /list: get: description: Returns a list of stuff responses: '200': description: Successful response · The syntax above will make sense once we finish this walkthrough.
🌐
LornaJane
lornajane.net › posts › 2020 › creating-a-simple-openapi-spec
Creating a Simple OpenAPI Spec | LornaJane
August 6, 2020 - For the impatient: if you just want to look at an example without any additional context, there’s a spec here https://github.com/lornajane/flask-planets-and-webhooks/blob/master/openapi.yaml · I’ve been using a very trivial API example project in a few of my recent talks on API-adjacent topics, with just a couple of endpoints. There’s a blog post about the Planets API but in short you can get a list of either one planet or many, with requests like: GET http://localhost:5000/planets GET http://localhost:5000/planets/3
🌐
Swagger
swagger.io › specification
OpenAPI Specification - Version 3.1.0 | Swagger
The OpenAPI Specification defines a standard interface to RESTful APIs which allows both humans and computers to understand service capabilities without access to source code, documentation, or network traffic inspection.
🌐
DZone
dzone.com › software design and architecture › integration › a sample openapi 3.0 file to get started
A Sample OpenAPI 3.0 File to Get Started
September 18, 2017 - Familiarize yourself with the new OpenAPI specification version 3.0 by looking over this example file, with an analysis and thoughts from the API Evangelist.
Find elsewhere
🌐
GitHub
github.com › Redocly › openapi-template › blob › gh-pages › openapi.yaml
openapi-template/openapi.yaml at gh-pages · Redocly/openapi-template
For more full example check out: https://github.com/APIs-guru/petstore_extended · · openapi: 3.0.2 · info: version: '1.0.0' # Your API version · # It can be any string but it is better to use semantic versioning: http://semver.org/ # Warning: OpenAPI requires the version to be a string, but without quotation marks YAML can recognize it as a number.
Author   Redocly
🌐
IBM
ibm.com › docs › en › zos-connect › zos-connect › 3.0
Creating a simple OpenAPI 3 document
A step by step "how-to" tutorial to create a simple OpenAPI 3.0 document for API integration.
🌐
Redocly
redocly.com › learn › openapi › learning-openapi
Introduction to OpenAPI
You can use `markdown` here. ... application/json: schema: $ref: ../components/schemas/User.yaml example: username: user1 email: user@example.com '403': description: Forbidden '404': description: User not found put: tags: ...
🌐
OpenAPI
spec.openapis.org › oas › v3.2.0.html
OpenAPI Specification v3.2.0
When example or examples are provided, the example SHOULD match the specified schema and be in the correct format as specified by the media type and its encoding. The example and examples fields are mutually exclusive. See Working With Examples for further guidance regarding the different ways of specifying examples, including non-JSON/YAML values.
Top answer
1 of 2
29

We have used lately springdoc-openapi java library. It helps automating the generation of API documentation using spring boot projects.

It automatically deploys swagger-ui to a spring-boot application Documentation will be available in HTML format, using the official [swagger-ui jars]:

The Swagger UI page should then be available at http://server:port/context-path/swagger-ui.html and the OpenAPI description will be available at the following url for json format: http://server:port/context-path/v3/api-docs

  • server: The server name or IP
  • port: The server port
  • context-path: The context path of the application

Documentation can be available in yaml format as well, on the following path: /v3/api-docs.yaml. (to convert into yaml) Add the library to the list of your project dependencies (No additional configuration is needed)

 <dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-ui</artifactId>
      <version>1.2.3</version>
  </dependency>
2 of 2
5

I was missing some library for this for longer time. Finally, decided to implement my own generator https://github.com/jrcodeza/spring-openapi maybe you can check it out too. It's based on reflection and supports javax and spring annotations. It also generates inheritance model (with discriminators) based on Jackson annotations. Besides you can define your own interceptors if you want to alter generation process (e.g. when you have your own annotations and need to adjust generated sections of schema). You can use it in runtime mode or as a maven plugin. There is also OpenAPI3 to java client generator, which generates the model. Again it generates also Javax annotations and Jackson annotations for correct inheritance.

🌐
OpenAPI
spec.openapis.org › oas › v3.0.3.html
OpenAPI Specification v3.0.3
An OpenAPI document compatible with OAS 3.*.* contains a required openapi field which designates the semantic version of the OAS that it uses. (OAS 2.0 documents contain a top-level version field named swagger and value "2.0".) An OpenAPI document that conforms to the OpenAPI Specification is itself a JSON object, which may be represented either in JSON or YAML format. For example, if a field has an array value, the JSON array representation will be used:
🌐
OpenAPI
learn.openapis.org › examples › v3.0 › api-with-examples.html
api-with-examples - OpenAPI Documentation
{ "openapi": "3.0.0", "info": { "title": "Simple API overview", "version": "2.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response", "content": { "application/json": { "examples": { "foo": { "value": { "versions": [ { "status": "CURRENT", "updated": "2011-01-21T11:33:21Z", "id": "v2.0", "links": [ { "href": "http://127.0.0.1:8774/v2/", "rel": "self" } ] }, { "status": "EXPERIMENTAL", "updated": "2013-07-23T11:33:21Z", "id": "v3.0", "links": [ { "href": "http://127.0.0.1:8774/v3/", "rel": "self"
🌐
I'd Rather Be Writing
idratherbewriting.com › learnapidoc › pubapis_openapi_tutorial_overview.html
OpenAPI tutorial using Swagger Editor and Swagger UI: Overview | I'd Rather Be Writing Blog and API doc course
4 days ago - You can also write in JSON, if you prefer that. There are more curly braces to deal with, but it isn’t a space-sensitive format. The OpenAPI specification documentation on GitHub shows code samples in both YAML and JSON in nearly every example.
🌐
Medium
issac88.medium.com › everything-we-need-to-know-about-openapi-3-0-69fa9985bf7c
Everything we need to know about OpenAPI 3.0 | by Issac | Medium
February 26, 2021 - In OpenAPI 3.0, you use the servers ... has an url and an optional Markdown-formatted description. https://api.example.com/v1/users?role=admin&status=active \________________________/\____/ \______________________/ server URL ...
🌐
OpenAPI
spec.openapis.org › oas › v3.0.0.html
OpenAPI Specification v3.0.0
July 26, 2017 - An OpenAPI document compatible with OAS 3.*.* contains a required openapi field which designates the semantic version of the OAS that it uses. (OAS 2.0 documents contain a top-level version field named swagger and value "2.0".) An OpenAPI document that conforms to the OpenAPI Specification is itself a JSON object, which may be represented either in JSON or YAML format. For example, if a field has an array value, the JSON array representation will be used:
🌐
IBM
ibm.com › docs › en › zos-connect › 3.0.0
Creating a simple OpenAPI 3.0 document
Learn how to create an EmployeesAPI OpenAPI 3.0 document from scratch in Swagger Editor by defining info objects, servers, paths, responses, and schemas to support enterprise-grade Db2 API integration.
🌐
GitHub
github.com › Redocly › openapi-starter › blob › main › openapi › openapi.yaml
openapi-starter/openapi/openapi.yaml at main · Redocly/openapi-starter
This is an **example** API to demonstrate features of the OpenAPI · specification. · # Introduction · · This API definition is intended to to be a good starting point for · describing your API in [OpenAPI/Swagger · format](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md).
Author   Redocly